00001
00002
00003
00004
00005 package org.hfbk.vis.visnode;
00006
00007 import java.awt.event.MouseEvent;
00008
00009 import org.dronus.gl.GLUtil;
00010 import org.dronus.graph.Node;
00011 import org.lwjgl.util.vector.Vector3f;
00012
00019 abstract public class VisNodeDraggable extends VisNodeMousable {
00020
00021 protected VisNodeDraggable(Node node, Vector3f position) {
00022 super(node, position);
00023 }
00024
00025 Vector3f handle;
00026 Vector3f vpLast;
00027
00040 boolean hit(Ray mouseray, Vector3f hit) {
00041
00042
00043 boolean gotHit=super.hit(mouseray, hit);
00044
00045 if (handle==null) return gotHit;
00046
00047
00048
00049
00050
00051 Vector3f projector=(Vector3f)new Vector3f(mouseray.dir).scale(hitDepth);
00052 Vector3f.add(mouseray.start, projector, hit);
00053
00054 return gotHit;
00055 }
00056
00057
00058
00062 float hitDepth;
00063 void handleEvent(VisMouseEvent evt) {
00064 if (evt.getID()==MouseEvent.MOUSE_DRAGGED){
00065 if (handle==null){
00066
00067 handle=evt.hit;
00068 hitDepth=GLUtil.getPosition().length();
00069 }else{
00070
00071
00072
00073 Vector3f drag=evt.hit;
00074 Vector3f.sub(drag,handle,drag);
00075 position=traverse(parent, drag);
00076
00077 Vector3f viewdrag=new Vector3f();
00078 Vector3f.sub(getRoot().client.mouseViewpoint, vpLast, viewdrag);
00079 Vector3f.add(position, viewdrag, position);
00080 }
00081 vpLast=new Vector3f(getRoot().client.mouseViewpoint);
00082 }else if (evt.getID()==MouseEvent.MOUSE_MOVED){
00083
00084 handle=null;
00085 vpLast=null;
00086 }
00087 }
00088 }