Author: paperwing
Date: 2012-03-02 13:13:35 -0800 (Fri, 02 Mar 2012)
New Revision: 28420

Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/SimpleCamera.java
Log:
Added camera reset key C, added default camera movement and rotation speeds, 
completed method to produce Tait?\226?\128?\147Bryan angles (yaw, pitch, roll) 
using Z-X-Y convention.

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-02 20:54:02 UTC (rev 28419)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-02 21:13:35 UTC (rev 28420)
@@ -23,6 +23,7 @@
 import org.cytoscape.paperwing.internal.rendering.RenderSelectionBoxProcedure;
 import org.cytoscape.paperwing.internal.rendering.ResetSceneProcedure;
 import org.cytoscape.paperwing.internal.rendering.text.StringRenderer;
+import org.cytoscape.paperwing.internal.tools.GeometryToolkit;
 import org.cytoscape.view.model.CyNetworkView;
 
 /**
@@ -82,7 +83,6 @@
                for (ReadOnlyGraphicsProcedure renderProcedure : 
renderProcedures) {
                        renderProcedure.execute(graphicsData);
                }
-               
        }
 
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
 2012-03-02 20:54:02 UTC (rev 28419)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
 2012-03-02 21:13:35 UTC (rev 28420)
@@ -6,6 +6,7 @@
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.data.GraphicsSelectionData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
+import org.cytoscape.paperwing.internal.tools.GeometryToolkit;
 import org.cytoscape.paperwing.internal.tools.NetworkToolkit;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
 import org.cytoscape.view.model.CyNetworkView;
@@ -17,6 +18,7 @@
                        GraphicsData graphicsData) {
                
                Set<Integer> held = keys.getHeld();
+               Set<Integer> pressed = keys.getPressed();
                SimpleCamera camera = graphicsData.getCamera();
                
                processCameraTranslation(held, camera);
@@ -25,6 +27,10 @@
                
                processCameraFirstPersonLook(keys, mouse, camera);
                processCameraZoom(mouse, graphicsData);
+               
+               processResetCamera(held, graphicsData);
+               
+               processDebugAngles(pressed, camera);
        }
        
        private void processCameraZoom(MouseMonitor mouse, GraphicsData 
graphicsData) {
@@ -140,4 +146,30 @@
                        camera.rollCounterClockwise();
                }
        }
+       
+       private void processResetCamera(Set<Integer> held, GraphicsData 
graphicsData) {
+               
+               // Reset camera
+               if (held.contains(KeyEvent.VK_C)) {
+                       graphicsData.setCamera(new SimpleCamera());
+               }
+       }
+       
+       private void processDebugAngles(Set<Integer> pressed, SimpleCamera 
camera) {
+               
+               if (pressed.contains(KeyEvent.VK_V)) {
+                       System.out.println("Camera direction and up vectors: " 
+ camera.getDirection()
+                                       + ", " + camera.getUp());
+                       
+                       Vector3 angles = 
GeometryToolkit.findYawPitchRoll(camera.getDirection(), camera.getUp());
+                       System.out.println("Camera yaw, pitch, roll: " + 
angles);
+                       
+                       /*
+                       Vector3 direction = 
GeometryToolkit.findDirectionVector(angles.x(), angles.y());
+                       Vector3 up = GeometryToolkit.findUpVector(angles.x(), 
angles.y(), angles.z());
+                       
+                       System.out.println("Camera direction and up calculated 
from Euler angles: " + direction + ", " + up);
+                       */
+               }
+       }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
    2012-03-02 20:54:02 UTC (rev 28419)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
    2012-03-02 21:13:35 UTC (rev 28420)
@@ -218,13 +218,31 @@
         * Assuming the initial direction is towards the negative z direction, 
calculate what
         * the direction would be given yaw and pitch angles. The rotations are 
done by the right-hand rule.
         * 
+        * This method assumes the Z-X-Y convention, that is, the first 
rotation is done with respect
+        * to the Z-axis and the last rotation is done with respect to the 
Y-axis.
+        * 
         * @param yaw The yaw angle
         * @param pitch The pitch angle
+        * @param roll The roll angle
         * @return The unit direction vector corresponding to the given yaw and 
pitch angles.
         */
-       public static Vector3 findDirectionVector(double yaw, double pitch) {
+       public static Vector3 findDirectionVector(double yaw, double pitch, 
double roll) {
                Vector3 direction = new Vector3(0, 0, -1);
                
+               direction = direction.rotate(new Vector3(0, 0, 1), roll);
+               
+               Vector3 newAxisX = (new Vector3(1, 0, 0)).rotate(new Vector3(0, 
1, 0), yaw);
+               
+               // Rotate about its new x-axis for pitch
+               direction = direction.rotate(newAxisX, pitch);
+               
+               return direction.normalize();
+       }
+       
+       // Older method; rotates about axes in order Y-X-Z
+       public static Vector3 findDirectionVectorOld(double yaw, double pitch) {
+               Vector3 direction = new Vector3(0, 0, -1);
+               
                // Rotate about y-axis for yaw
                direction = direction.rotate(new Vector3(0, 1, 0), yaw);
                
@@ -241,6 +259,9 @@
         * up vector would be given the yaw, pitch, and roll angles. The 
rotations are done by
         * the right-hand rule.
         * 
+        * This method assumes the Z-X-Y convention, that is, the first 
rotation is done with respect
+        * to the Z-axis and the last rotation is done with respect to the 
Y-axis.
+        * 
         * @param yaw The yaw angle
         * @param pitch The pitch angle
         * @param roll The roll angle
@@ -258,36 +279,52 @@
                return up.normalize();
        }
        
+       // Older method; rotates about axes in order Y-X-Z
+       public static Vector3 findUpVectorOld(double yaw, double pitch, double 
roll) {
+
+               // Determine the rotated axes
+               Vector3 newAxisX = (new Vector3(1, 0, 0)).rotate(new Vector3(0, 
1, 0), yaw);
+               Vector3 newAxisY = (new Vector3(0, 1, 0)).rotate(newAxisX, 
pitch);
+               Vector3 newAxisZ = newAxisX.cross(newAxisY);
+               
+               Vector3 up = newAxisY.rotate(newAxisZ, roll);
+               
+               return up.normalize();
+       }
+       
        /**
-        * Given the direction and up vectors, calculate the pitch, yaw, and 
roll angles assuming
+        * Given the direction and up vectors, calculate the yaw, pitch, and 
roll angles assuming
         * the initial direction is towards the negative z direction and the 
initial up vector
         * is towards the positive y direction.
         * 
+        * This method assumes the Z-X-Y convention, that is, the first 
rotation is done with respect
+        * to the Z-axis and the last rotation is done with respect to the 
Y-axis.
+        * 
         * @param direction The direction vector
         * @param up The up vector
-        * @return A 3-vector in the form of (pitch, yaw, roll)
+        * @return A 3-vector in the form of (yaw, pitch, roll) in degrees
         */
-       public static Vector3 findPitchYawRoll(Vector3 direction, Vector3 up) {
+       public static Vector3 findYawPitchRoll(Vector3 direction, Vector3 up) {
                
-               double pitch, yaw, roll;
+               // Obtain the rotated axes
+               Vector3 newAxisZ = direction.multiply(-1);
+               Vector3 newAxisY = up.copy();
+               Vector3 newAxisX = newAxisY.cross(newAxisZ);
                
-               Vector3 pitchProjection = direction.projectNormal(new 
Vector3(0, 1, 0));
+               // Calculate the vector representing the line of nodes for the 
Tait-Bryan convention
+               Vector3 lineOfNodes = (newAxisY).cross(new Vector3(0, 0, 1));
                
-               if (pitchProjection.magnitudeSquared() < Double.MIN_NORMAL) {
-                       pitch = 90;
-               } else {
-                       pitch = direction.angleAcute(pitchProjection);
-               }
+               // This vector is perpendicular to the line of nodes and the 
fixed z axis
+               Vector3 intermediateY = lineOfNodes.rotate(new Vector3(0, 0, 
1), Math.PI / 2);
                
-               Vector3 yawProjection = direction.projectNormal(new Vector3(1, 
0, 0));
-               yaw = direction.angleAcute(yawProjection);
+               double yaw, pitch, roll;
                
-               Vector3 rollProjection = up.projectNormal(new Vector3(0, 0, 1));
-               roll = up.angleAcute(rollProjection);
+               yaw = newAxisX.angle(lineOfNodes);
+               pitch = newAxisY.angle(intermediateY);
+               roll = (new Vector3(0, 1, 0)).angle(intermediateY);
                
-               // TODO: At certain orientations, the values for pitch and yaw 
may be indeterminate. If pitch is 90 degrees,
-               // then it doesn't matter what yaw is.
-               
-               return new Vector3(pitch, yaw, roll);
+               Vector3 result = new Vector3(yaw, pitch, roll);
+               result.multiplyLocal(180.0 / Math.PI);
+               return result;
        }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/SimpleCamera.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/SimpleCamera.java
       2012-03-02 20:54:02 UTC (rev 28419)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/SimpleCamera.java
       2012-03-02 21:13:35 UTC (rev 28420)
@@ -18,6 +18,21 @@
        // a variable distance away from the camera. This target point is very
        // useful for certain rotations and transformations.
        
+       /** The default camera translational movement speed */
+       public static final double DEFAULT_MOVE_SPEED = 0.04;
+       
+       /**  The default angular speed for camera turning */
+       public static final double DEFAULT_TURN_SPEED = 0.0033;
+       
+       /** The default camera orbit angular speed */
+       public static final double DEFAULT_ORBIT_SPEED = 0.01;
+       
+       /** The default camera rolling angular speed */
+       public static final double DEFAULT_ROLL_SPEED = 0.01;
+       
+       /** The default zooming translational speed */
+       public static final double DEFAULT_ZOOM_SPEED = 0.4;
+       
        /** The minimum allowed distance between the camera's position vector 
and
         * the target position vector
         */
@@ -78,7 +93,7 @@
         * vectors
         */
        public SimpleCamera() {
-               this(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new 
Vector3(0, 1, 0));
+               this(new Vector3(0, 0, 3), new Vector3(0, 0, 0), new Vector3(0, 
1, 0));
        }
        
        /** Construct a new SimpleCamera object with specified position,
@@ -91,7 +106,8 @@
        public SimpleCamera(Vector3 position, Vector3 target, Vector3 up) {
                // TODO: provide constants for default values
                
-               this(position, target, up, 0.01, 0.002, 0.002, 0.1, 0.4);
+               this(position, target, up, DEFAULT_MOVE_SPEED, 
DEFAULT_TURN_SPEED, 
+                               DEFAULT_ORBIT_SPEED, DEFAULT_ROLL_SPEED, 
DEFAULT_ZOOM_SPEED);
        }
 
        /** Creates a new SimpleCamera object with specified positions,

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to