[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MoveTool.java,1.6,1.7
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-09-02 13:30:33
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14633 Modified Files: MoveTool.java Log Message: Now the move works with the select tool Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MoveTool.java 31 Aug 2005 14:56:33 -0000 1.6 --- MoveTool.java 2 Sep 2005 13:30:23 -0000 1.7 *************** *** 9,13 **** --- 9,16 ---- import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.View; + import net.sourceforge.bprocessor.gl.view.Transformation; + import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; *************** *** 47,50 **** --- 50,56 ---- private int lastY = 0; + /** The plane to drag according to */ + private Plane dragPlane; + /** * The Constructor *************** *** 63,66 **** --- 69,104 ---- lastX = e.getX(); lastY = e.getY(); + + if (target instanceof Vertex) { + dragPlane = new Plane(0, 0, 1, 0); + } else if (target instanceof Edge) { + dragPlane = new Plane(0, 0, 1, 0); + } else if (target instanceof Surface) { + Surface sel = (Surface)target; + dragPlane = sel.plane(); + log.info("" + dragPlane); + } + // make a orthogonal plane to the current one + if (moveMode == XZ) { + log.info("orthogonal"); + Transformation trans = glv.getView().transformation(); + int x = lastX; + int y = lastY; + Vertex near = new Vertex("near", x, y, 0.0); + Vertex far = new Vertex("far", x, y, 1.0); + Edge ray = new Edge("ray", near, far); + ray = trans.unProject(ray); + dragPlane = dragPlane.orthogonalPlane(ray); + } + } + + /** + * Invoked when a mouse button has been released on a component. + * @param e The MouseEvent + */ + protected void released(MouseEvent e) { + super.released(e); + + dragPlane = null; } *************** *** 69,74 **** * @param e The MouseEvent object */ ! protected void dragged(MouseEvent e) { ! int x = e.getX(); int y = e.getY(); if (viewType == View.VIEW_3D) { --- 107,131 ---- * @param e The MouseEvent object */ ! protected void dragged(MouseEvent e) { ! if (dragPlane != null) { ! int x = e.getX(); ! int y = e.getY(); ! ! View view = glv.getView(); ! double[] from = view.toPlaneCoords(new double[] {lastX, lastY}, dragPlane); ! log.info("from " + from[0] + ", " + from[1] + ", " + from[2]); ! double[] to = view.toPlaneCoords(new double[] {x, y}, dragPlane); ! log.info("to " + to[0] + ", " + to[1] + ", " + to[2]); ! double[] delta = new double[] {to[0] - from[0], to[1] - from[1], to[2] - from[2]}; ! log.info("delta " + delta[0] + ", " + delta[1] + ", " + delta[2]); ! move(selection, delta); ! } else { ! log.warn("There were no plane to drag according to"); ! } ! ! lastX = e.getX(); ! lastY = e.getY(); ! } ! /* int x = e.getX(); int y = e.getY(); if (viewType == View.VIEW_3D) { *************** *** 180,186 **** lastX = x; lastY = y; ! } ! /** * Invoked when a key has been pressed. Lets user control the speed * and mode of movement. --- 237,320 ---- lastX = x; lastY = y; ! }*/ ! /** ! * Move the entire selection ! * @param sel The selection list ! * @param delta The movement ! */ ! private void move(List sel, double[] delta) { ! Iterator it = sel.iterator(); ! while (it.hasNext()) { ! Object elm = it.next(); ! if (elm instanceof Vertex) { ! move((Vertex)elm, delta); ! } else if (elm instanceof Edge) { ! move((Edge)elm, delta); ! } else if (elm instanceof Surface) { ! move((Surface)elm, delta); ! } ! } ! } ! ! /** ! * Move the give surface and its inner surfaces ! * @param surface The surface to move ! * @param delta The movement ! */ ! private void move(Surface surface, double[] delta) { ! log.info("moved surface"); ! List l = Util.traverse(surface); ! double[] coords; ! for (int i = 0; i < l.size(); i++) { ! Vertex v = (Vertex)l.get(i); ! coords = new double[] {v.getX() + delta[0], ! v.getY() + delta[1], ! v.getZ() + delta[2]}; ! updateVertex(v, coords); ! } ! ! Set innerSurfaces = surface.getInnerSurfaces(); ! if (innerSurfaces != null) { ! Iterator innerIt = innerSurfaces.iterator(); ! while (innerIt.hasNext()) { ! move((Surface)innerIt.next(), delta); ! } ! } ! } ! ! /** ! * Move the give edge ! * @param edge The surface to move ! * @param delta The movement ! */ ! private void move(Edge edge, double[] delta) { ! Vertex to = edge.getTo(); ! Vertex from = edge.getFrom(); ! ! double[] coords = new double[] {to.getX() + delta[0], ! to.getY() + delta[1], ! to.getZ() + delta[2]}; ! updateVertex(to, coords); ! coords = new double[] {from.getX() + delta[0], ! from.getY() + delta[1], ! from.getZ() + delta[2]}; ! updateVertex(from, coords); ! } ! ! /** ! * Move the give vertex ! * @param vertex The surface to move ! * @param delta The movement ! */ ! private void move(Vertex vertex, double[] delta) { ! double[] coords = new double[] {vertex.getX() + delta[0], ! vertex.getY() + delta[1], ! vertex.getZ() + delta[2]}; ! coords = snapToGrid(coords); ! updateVertex(vertex, coords); ! } ! ! /** * Invoked when a key has been pressed. Lets user control the speed * and mode of movement. |