VisClient/org/hfbk/vis/visnode/VisNodeDraggable.java

Go to the documentation of this file.
00001 /*
00002  * Created on 28.04.2008
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                 // calculate a flat plane intersection in object space to determine if hit.
00043                 boolean gotHit=super.hit(mouseray, hit);
00044                 
00045                 if  (handle==null) return gotHit; 
00046                         
00047                 // tie distance to camera to first hit 
00048                 // fix to prevent sliding due to inexact
00049                 // sphere approx. by the tangential plane.
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                                         //first click, just remember position ("handle")
00067                                         handle=evt.hit;
00068                                         hitDepth=GLUtil.getPosition().length();
00069                                 }else{
00070                                         //moves the object so the handle position matches 
00071                                         //the current hit position
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                                 // no drag, remove handle.
00084                                 handle=null;
00085                                 vpLast=null;
00086                         }
00087         }       
00088 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1