?? translategizmo.java
字號:
interactionTechnique = 1; // Vector break; case Z_AXIS_GROUP: v = new Vector3D(0, 0, 1); interactionTechnique = 1; // Vector break; case XY_PLANE_GROUP: v = new Vector3D(0, 0, 1); interactionTechnique = 2; // Plane break; case YZ_PLANE_GROUP: v = new Vector3D(1, 0, 0); interactionTechnique = 2; // Plane break; case XZ_PLANE_GROUP: v = new Vector3D(0, 1, 0); interactionTechnique = 2; // Plane break; } if ( v == null ) { oldmousex = e.getX(); oldmousey = e.getY(); return false; } //- Implement interaction technique for selected element ---------- Vector3D o = getPosition(); Vector3D p = new Vector3D(0, 0, 0); Ray r = null; InfinitePlane plane; int mousex = e.getX(); int mousey = e.getY(); Vector3D deltapos = new Vector3D(); camera.updateVectors(); if ( interactionTechnique == 2 ) { r = camera.generateRay(mousex, mousey); if ( r.direction.dotProduct(v) > 0 ) { v = v.multiply(-1); } plane = new InfinitePlane(v, o); if ( !plane.doIntersection(r) ) { oldmousex = e.getX(); oldmousey = e.getY(); p = o; } else { p = r.direction.multiply(r.t).add(r.origin); } } else if ( interactionTechnique == 1 ) { boolean accountForU = false; boolean accountForV = false; Vector3D left, up; left = camera.getLeft(); up = camera.getUp(); v.normalize(); left.normalize(); up.normalize(); if ( Math.abs(v.dotProduct(left)) > Math.cos(Math.toRadians(80.0)) ) { accountForU = true; } if ( Math.abs(v.dotProduct(up)) > Math.cos(Math.toRadians(80.0)) ) { accountForV = true; } if ( accountForU && !accountForV ) { plane = camera.calculateUPlaneAtPixel(mousex, mousey); } else if ( accountForV && !accountForU ) { plane = camera.calculateVPlaneAtPixel(mousex, mousey); } else if ( accountForU && accountForV ) { if ( (mousex-oldmousex) > (mousey-oldmousey) ) { plane = camera.calculateUPlaneAtPixel(mousex, mousey); } else { plane = camera.calculateVPlaneAtPixel(mousex, mousey); } } else { oldmousex = e.getX(); oldmousey = e.getY(); return false; } r = new Ray(o, v); Ray r2 = new Ray(o, v); if ( !plane.doIntersectionWithNegative(r) ) { oldmousex = e.getX(); oldmousey = e.getY(); return false; } p = r.origin.add(r.direction.multiply(r.t)); } oldmousex = e.getX(); oldmousey = e.getY(); //* HOW TO REFACTOR TO HERE *************************************** lastDeltaPosition = p.substract(getPosition()); return false; } public boolean processMouseReleasedEventAwt(MouseEvent e) { selectedResizing = true; calculateGeometryState(getPosition(), T, selectedResizing, aparentSizeInPixels, camera); return true; } public boolean processMouseClickedEventAwt(MouseEvent e) { selectedResizing = true; calculateGeometryState(getPosition(), T, selectedResizing, aparentSizeInPixels, camera); int previousSelection = volatileSelection; if ( volatileSelection == NULL_GROUP ) { previousSelection = persistentSelection; } persistentSelection = calculateSelection(e.getX(), e.getY()); if ( persistentSelection == NULL_GROUP ) { persistentSelection = previousSelection; } if ( persistentSelection != previousSelection ) { return true; } return false; } /** Given a pixel coordinate, this method traces a ray from current camera to gizmo's geometry and determines the constituent element selected. */ private int calculateSelection(int x, int y) { camera.updateVectors(); Ray r = camera.generateRay(x, y); double nearestDistance = Double.MAX_VALUE; int nearestElement = -1; int index = 1, i; /* Note that box elements are only for display, they do not affect gravity selections */ for ( i = 0; index <= 9 && i < elementInstances.size(); index++, i++ ) { r.t = Double.MAX_VALUE; SimpleBody gi = elementInstances.get(i); if ( gi.getGeometry() != null && gi.doIntersection(r) && r.t < nearestDistance ) { nearestDistance = r.t; nearestElement = index; } } int selection = NULL_GROUP; switch ( nearestElement ) { case X_AXIS_ELEMENT: selection = X_AXIS_GROUP; break; case Y_AXIS_ELEMENT: selection = Y_AXIS_GROUP; break; case Z_AXIS_ELEMENT: selection = Z_AXIS_GROUP; break; case XYY_SEGMENT_ELEMENT: selection = XY_PLANE_GROUP; break; case XYX_SEGMENT_ELEMENT: selection = XY_PLANE_GROUP; break; case YZZ_SEGMENT_ELEMENT: selection = YZ_PLANE_GROUP; break; case YZY_SEGMENT_ELEMENT: selection = YZ_PLANE_GROUP; break; case XZZ_SEGMENT_ELEMENT: selection = XZ_PLANE_GROUP; break; case XZX_SEGMENT_ELEMENT: selection = XZ_PLANE_GROUP; break; } active = false; if ( selection != NULL_GROUP ) { active = true; } return selection; } public boolean isActive() { return active; } public boolean processMouseMovedEventAwt(MouseEvent e) { oldmousex = e.getX(); oldmousey = e.getY(); selectedResizing = true; calculateGeometryState(getPosition(), T, selectedResizing, aparentSizeInPixels, camera); int previousSelection = volatileSelection; if ( volatileSelection == NULL_GROUP ) { previousSelection = persistentSelection; } volatileSelection = calculateSelection(e.getX(), e.getY()); if ( volatileSelection != previousSelection ) { return true; } return false; } /* TO REFACTOR CODE! */ private Vector3D calculateInteractionPosition(MouseEvent e) { return null; } public boolean processMouseDraggedEventAwt(MouseEvent e) { //- If it is called as an automatic reposition, do nothing --------/* if ( skipRobot ) { skipRobot = false; oldmousex = e.getX(); oldmousey = e.getY(); return false; }*/ //Vector3D p = calculateInteractionPosition(e); // Not working! //* HOW TO REFACTOR FROM HERE ************************************* //- Configure sub-interaction technique from active element ------- int currentSelection; if ( volatileSelection == NULL_GROUP ) { currentSelection = persistentSelection; } else { currentSelection = volatileSelection; } Vector3D v = null; int interactionTechnique = 0; switch ( currentSelection ) { case X_AXIS_GROUP: v = new Vector3D(1, 0, 0); interactionTechnique = 1; // Vector break; case Y_AXIS_GROUP: v = new Vector3D(0, 1, 0); interactionTechnique = 1; // Vector break; case Z_AXIS_GROUP: v = new Vector3D(0, 0, 1); interactionTechnique = 1; // Vector break; case XY_PLANE_GROUP: v = new Vector3D(0, 0, 1); interactionTechnique = 2; // Plane break; case YZ_PLANE_GROUP: v = new Vector3D(1, 0, 0); interactionTechnique = 2; // Plane break; case XZ_PLANE_GROUP: v = new Vector3D(0, 1, 0); interactionTechnique = 2; // Plane break; } if ( v == null ) { oldmousex = e.getX(); oldmousey = e.getY(); return false; } //- Implement interaction technique for selected element ---------- Vector3D o = getPosition(); Vector3D p = new Vector3D(0, 0, 0); Ray r = null; InfinitePlane plane; int mousex = e.getX(); int mousey = e.getY(); Vector3D deltapos = new Vector3D(); camera.updateVectors(); if ( interactionTechnique == 2 ) { r = camera.generateRay(mousex, mousey); if ( r.direction.dotProduct(v) > 0 ) { v = v.multiply(-1); } plane = new InfinitePlane(v, o); if ( !plane.doIntersection(r) ) { oldmousex = e.getX(); oldmousey = e.getY(); p = o; } else { p = r.direction.multiply(r.t).add(r.origin); } } else if ( interactionTechnique == 1 ) { boolean accountForU = false; boolean accountForV = false; Vector3D left, up; left = camera.getLeft(); up = camera.getUp(); v.normalize(); left.normalize(); up.normalize(); if ( Math.abs(v.dotProduct(left)) > Math.cos(Math.toRadians(80.0)) ) { accountForU = true; } if ( Math.abs(v.dotProduct(up)) > Math.cos(Math.toRadians(80.0)) ) { accountForV = true; } if ( accountForU && !accountForV ) { plane = camera.calculateUPlaneAtPixel(mousex, mousey); } else if ( accountForV && !accountForU ) { plane = camera.calculateVPlaneAtPixel(mousex, mousey); } else if ( accountForU && accountForV ) { if ( (mousex-oldmousex) > (mousey-oldmousey) ) { plane = camera.calculateUPlaneAtPixel(mousex, mousey); } else { plane = camera.calculateVPlaneAtPixel(mousex, mousey); } } else { oldmousex = e.getX(); oldmousey = e.getY(); return false; } r = new Ray(o, v); Ray r2 = new Ray(o, v); if ( !plane.doIntersectionWithNegative(r) ) { oldmousex = e.getX(); oldmousey = e.getY(); return false; } p = r.origin.add(r.direction.multiply(r.t)); } oldmousex = e.getX(); oldmousey = e.getY(); //* HOW TO REFACTOR TO HERE *************************************** setPosition(p.substract(lastDeltaPosition)); selectedResizing = false; //- Automatic cursor repositioning constrain ---------------------- // THIS IS NOT WORKING NICELY!/* try { if ( awtRobot == null ) { awtRobot = new Robot(); } Vector3D pp = new Vector3D(); Vector3D base = p.add(deltapos); camera.projectPoint(base, pp); Point global = e.getComponent().getLocationOnScreen(); //awtRobot.mouseMove((int)pp.x+global.x, (int)pp.y+global.y); skipRobot = true; } catch ( Exception ex ) { System.err.println(ex); }*/ return true; } public boolean processMouseWheelEventAwt(MouseWheelEvent e) { return false; }}//===========================================================================//= EOF =//===========================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -