Author: paperwing
Date: 2012-03-05 16:05:51 -0800 (Mon, 05 Mar 2012)
New Revision: 28430

Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
   
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/WindVisualLexicon.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.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/lighting/Light.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
Log:
In process of incorporating management of lights to GraphicsHandler from 
Graphics; light position now represented with homogenous coordinates following 
OpenGL's glLightf(), visual property set for a single light added to 
WindVisualLexicon

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-06 00:05:51 UTC (rev 28430)
@@ -131,8 +131,13 @@
                
                // Re-calculate the viewing volume
                SimpleCamera camera = graphicsData.getCamera();
-               
graphicsData.getViewingVolume().calculateViewingVolume(camera.getPosition(), 
camera.getDirection(), camera.getUp(), 
-                               graphicsData.getNearZ(), 
graphicsData.getFarZ(), graphicsData.getVerticalFov(), 
+               graphicsData.getViewingVolume().calculateViewingVolume(
+                               camera.getPosition(), 
+                               camera.getDirection(), 
+                               camera.getUp(), 
+                               graphicsData.getNearZ(), 
+                               graphicsData.getFarZ(), 
+                               graphicsData.getVerticalFov(), 
                                
GeometryToolkit.findHorizontalFieldOfView(graphicsData.getDistanceScale(), 
                                                graphicsData.getScreenWidth(), 
graphicsData.getScreenHeight()));
                
@@ -235,7 +240,7 @@
                float[] specularReflection = { 0.46f, 0.46f, 0.46f, 1.0f };
                gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR,
                                FloatBuffer.wrap(specularReflection));
-               gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 21); // Default 
shininess 31
+               gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 16); // Default 
shininess 31
                
                gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0);
        }

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-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-06 00:05:51 UTC (rev 28430)
@@ -1,18 +1,24 @@
 package org.cytoscape.paperwing.internal;
 
+import java.nio.FloatBuffer;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import javax.media.opengl.GL2;
+
 import org.cytoscape.paperwing.internal.coordinator.CoordinatorProcessor;
 import org.cytoscape.paperwing.internal.coordinator.MainCoordinatorProcessor;
 import org.cytoscape.paperwing.internal.coordinator.ViewingCoordinator;
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.CytoscapeDataProcessor;
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.MainCytoscapeDataProcessor;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
+import org.cytoscape.paperwing.internal.data.LightingData;
+import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.input.InputProcessor;
 import org.cytoscape.paperwing.internal.input.MainInputProcessor;
+import org.cytoscape.paperwing.internal.lighting.Light;
 import org.cytoscape.paperwing.internal.picking.DefaultShapePickingProcessor;
 import org.cytoscape.paperwing.internal.picking.ShapePickingProcessor;
 import org.cytoscape.paperwing.internal.rendering.PositionCameraProcedure;
@@ -66,13 +72,6 @@
        @Override
        public void drawScene(GraphicsData graphicsData) {
                
-               // TODO: Seems we had to move this to the draw method to 
prevent a crash involving a native library
-               // and the VizMapper preview. The cause was likely due to the 
TextRenderer class being initialized
-               // too early.
-               if (graphicsData.getFramesElapsed() == 1) {
-                       
-               }
-               
                // Control light positioning
                float[] lightPosition = { -4.0f, 4.0f, 6.0f, 1.0f };
                
@@ -87,8 +86,29 @@
 
        @Override
        public void setupLighting(GraphicsData graphicsData) {
-               // TODO Auto-generated method stub
                
+               GL2 gl = graphicsData.getGlContext();
+               LightingData lightingData = graphicsData.getLightingData();
+       
+               Light light0 = lightingData.getLight(0);
+               light0.setAmbient(0.4f, 0.4f, 0.4f, 1.0f);
+               light0.setDiffuse(0.57f, 0.57f, 0.57f, 1.0f);
+               light0.setSpecular(0.79f, 0.79f, 0.79f, 1.0f);
+               light0.setPosition(-4.0f, 4.0f, 6.0f, 1.0f);
+               light0.setTurnedOn(true);
+               
+               for (int i = 0; i < LightingData.NUM_LIGHTS; i++) {
+                       Light light = lightingData.getLight(i);
+               
+                       if (light.isTurnedOn()) {
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, 
FloatBuffer.wrap(light.getAmbient()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, 
FloatBuffer.wrap(light.getDiffuse()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, 
FloatBuffer.wrap(light.getSpecular()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, 
FloatBuffer.wrap(light.getPosition()));
+       
+                               gl.glEnable(GL2.GL_LIGHT0 + i);
+                       }
+               }
        }
 
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
        2012-03-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
        2012-03-06 00:05:51 UTC (rev 28430)
@@ -1,5 +1,8 @@
 package org.cytoscape.paperwing.internal;
 
+import java.awt.Color;
+import java.awt.Paint;
+
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.view.model.NullDataType;
@@ -8,6 +11,7 @@
 import org.cytoscape.view.presentation.property.DoubleVisualProperty;
 import org.cytoscape.view.presentation.property.NullVisualProperty;
 import org.cytoscape.view.presentation.property.BasicVisualLexicon;
+import org.cytoscape.view.presentation.property.PaintVisualProperty;
 
 /** The visual lexicon for the Wind rendering engines */
 public class WindVisualLexicon extends BasicVisualLexicon {
@@ -53,6 +57,9 @@
        public static final VisualProperty<Boolean> SHOW_EDGE_LABELS = new 
BooleanVisualProperty(
                        true, "SHOW_EDGE_LABELS", "Show Edge Labels", 
CyNetwork.class);
        
+       // Light visual properties
+       // =======================
+       
        public static final VisualProperty<Double> LIGHT_X_LOCATION = new 
DoubleVisualProperty(
                        0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_X_LOCATION", "Light 
X Location", CyNetwork.class);
        
@@ -63,8 +70,27 @@
                        0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_Z_LOCATION", "Light 
Z Location", CyNetwork.class);
        
        public static final VisualProperty<Boolean> LIGHT_ENABLED = new 
BooleanVisualProperty(
-                       true, "LIGHT_ENABLED", "Light Enablede", 
CyNetwork.class);
+                       true, "LIGHT_ENABLED", "Light Enabled", 
CyNetwork.class);
        
+       public static final VisualProperty<Paint> LIGHT_AMBIENT_COLOR = new 
PaintVisualProperty(
+                       new Color(255, 255, 255), PAINT_RANGE, 
"LIGHT_AMBIENT_COLOR", "Light Ambient Color", CyNetwork.class);
+
+       public static final VisualProperty<Double> LIGHT_AMBIENT_ALPHA = new 
DoubleVisualProperty(
+                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_AMBIENT_ALPHA", 
"Light Ambient Alpha", CyNetwork.class);
+       
+       public static final VisualProperty<Paint> LIGHT_DIFFUSE_COLOR = new 
PaintVisualProperty(
+                       new Color(255, 255, 255), PAINT_RANGE, 
"LIGHT_DIFFUSE_COLOR", "Light Diffuse Color", CyNetwork.class);
+
+       public static final VisualProperty<Double> LIGHT_DIFFUSE_ALPHA = new 
DoubleVisualProperty(
+                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_DIFFUSE_ALPHA", 
"Light Diffuse Alpha", CyNetwork.class);
+       
+       public static final VisualProperty<Paint> LIGHT_SPECULAR_COLOR = new 
PaintVisualProperty(
+                       new Color(255, 255, 255), PAINT_RANGE, 
"LIGHT_SPECULAR_COLOR", "Light Specular Color", CyNetwork.class);
+
+       public static final VisualProperty<Double> LIGHT_SPECULAR_ALPHA = new 
DoubleVisualProperty(
+                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_SPECULAR_ALPHA", 
"Light Specular Alpha", CyNetwork.class);
+       
+       
        /** Create a new WindVisualLexicon object */
        public WindVisualLexicon() {
                super(WIND_ROOT);

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-06 00:05:51 UTC (rev 28430)
@@ -253,4 +253,12 @@
        public void setViewingVolume(ViewingVolume viewingVolume) {
                this.viewingVolume = viewingVolume;
        }
+
+       public LightingData getLightingData() {
+               return lightingData;
+       }
+
+       public void setLightingData(LightingData lightingData) {
+               this.lightingData = lightingData;
+       }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
        2012-03-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
        2012-03-06 00:05:51 UTC (rev 28430)
@@ -8,12 +8,16 @@
 public class LightingData {
        
        /** The total number of lights. OpenGL specifies 8 as the minimum 
number of lights supported by hardware. */
-       private static int NUM_LIGHTS = 8;
+       public static final int NUM_LIGHTS = 8;
        
        /** The array of lights present in the scene */
        private Light[] lights;
        
-       /** Obtain the light with the given index */
+       /** 
+        * Obtain the light with the given index 
+        * 
+        * @param index The index of the desired light, ranging from 0 to 
LightingData.NUM_LIGHTS (default 8)
+        */
        public Light getLight(int index) {
                return lights[index];
        }

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-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
 2012-03-06 00:05:51 UTC (rev 28430)
@@ -30,7 +30,7 @@
                
                processResetCamera(held, graphicsData);
                
-               processDebugAngles(pressed, camera);
+               processDebugAngles(held, camera);
        }
        
        private void processCameraZoom(MouseMonitor mouse, GraphicsData 
graphicsData) {
@@ -155,21 +155,21 @@
                }
        }
        
-       private void processDebugAngles(Set<Integer> pressed, SimpleCamera 
camera) {
+       private void processDebugAngles(Set<Integer> held, SimpleCamera camera) 
{
                
-               if (pressed.contains(KeyEvent.VK_V)) {
+               if (held.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 direction = 
GeometryToolkit.findDirectionVector(angles.x(), angles.y(), angles.z());
                        Vector3 up = GeometryToolkit.findUpVector(angles.x(), 
angles.y(), angles.z());
                        
-                       System.out.println("Camera direction and up calculated 
from Euler angles: " + direction + ", " + up);
-                       */
+                       System.out.println("Camera direction and up calculated 
from angles: " + direction + ", " + up);
+                       
+                       System.out.println("Differences: " + 
(direction.subtract(camera.getDirection()).magnitudeSquared() + 
up.subtract(camera.getUp()).magnitudeSquared()));
                }
        }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
   2012-03-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
   2012-03-06 00:05:51 UTC (rev 28430)
@@ -22,8 +22,8 @@
        /** An array containing the color of the specular component of the 
light in RGBA format */
        private float[] specular;
        
-       /** The position of the light in 3D space */
-       private Vector3 position;
+       /** An array containing the position of the lights in homogenous 
coordinates, format (x, y, z, w) */
+       private float[] position;
        
        /** A boolean indicating whether the light is turned on. */
        private boolean turnedOn;
@@ -32,22 +32,24 @@
         * Creates a light with its position at the origin and white values for 
all colors
         */
        public Light() {
-               position = new Vector3();
                turnedOn = false;
                
                ambient = new float[4]; 
                diffuse = new float[4];
                specular = new float[4];
+               position = new float[4];
                
                for (int i = 0; i < 3; i++) {
                        ambient[i] = DEFAULT_COLOR_VALUE;
                    diffuse[i] = DEFAULT_COLOR_VALUE;
                        specular[i] = DEFAULT_COLOR_VALUE;
+                       position[i] = 0;
                }
                
                ambient[3] = DEFAULT_ALPHA_VALUE;
            diffuse[3] = DEFAULT_ALPHA_VALUE;
                specular[3] = DEFAULT_ALPHA_VALUE;
+               position[3] = 1;
        }
        
        /**
@@ -56,9 +58,9 @@
         * @param ambient An array containing the color and alpha of the 
ambient light component, in the form (r, g, b, a)
         * @param diffuse An array containing the color and alpha of the 
diffuse light component, in the form (r, g, b, a)
         * @param specular An array containing the color and alpha of the 
specular light component, in the form (r, g, b, a)
-        * @param position The position of the light
+        * @param position An array containing the position of the light in 
homogenous coordinates, in the form (x, y, z, w)
         */
-       public Light(float[] ambient, float[] diffuse, float[] specular, 
Vector3 position) {
+       public Light(float[] ambient, float[] diffuse, float[] specular, 
float[] position) {
                // Require 4 parameters for ambient, diffuse, and specular 
lighting
                if (ambient.length < 4) {
                        throw new IllegalArgumentException("Array for light 
ambient property has less than 4 elements.");
@@ -72,18 +74,23 @@
                        throw new IllegalArgumentException("Array for light 
specular property has less than 4 elements.");
                }
                
-               this.position = new Vector3(position);
+               if (position.length < 4) {
+                       throw new IllegalArgumentException("Array containing 
light position in homogenous coordinates has less than 4 elements.");
+               }
+
                turnedOn = false;
                
                this.ambient = new float[4]; 
                this.diffuse = new float[4];
                this.specular = new float[4];
+               this.position = new float[4];
                
                // Copy light properties
                for (int i = 0; i < 4; i++) {
                        this.ambient[i] = ambient[i];
                        this.diffuse[i] = diffuse[i];
                        this.specular[i] = specular[i];
+                       this.position[i] = position[i];
                }
        }
        
@@ -119,7 +126,7 @@
         * 
         * @return A {@link Vector3} containing the 3D coordinates of the light.
         */
-       public Vector3 getPosition() {
+       public float[] getPosition() {
                return position;
        }
        
@@ -173,8 +180,11 @@
         * 
         * @param position The new position represented by a {@link Vector3} 
object.
         */
-       public void setPosition(Vector3 position) {
-               this.position.set(position);
+       public void setPosition(float x, float y, float z, float w) {
+               position[0] = x;
+               position[1] = y;
+               position[2] = z;
+               position[3] = w;
        }
        
        /**

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-05 23:08:38 UTC (rev 28429)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
    2012-03-06 00:05:51 UTC (rev 28430)
@@ -221,22 +221,22 @@
         * 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
+        * @param yaw The yaw angle, in degrees
+        * @param pitch The pitch angle, in degrees
+        * @param roll The roll angle, in degrees
         * @return The unit direction vector corresponding to the given yaw and 
pitch angles.
         */
        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, 
0, 1), Math.toRadians(roll)));
+               Vector3 newAxisY = (new Vector3(0, 1, 0).rotate(new Vector3(0, 
0, 1), Math.toRadians(roll)));
                
-               Vector3 newAxisX = (new Vector3(1, 0, 0)).rotate(new Vector3(0, 
1, 0), yaw);
+               newAxisY = newAxisY.rotate(newAxisX, Math.toRadians(pitch));
+               newAxisX = newAxisX.rotate(newAxisY, Math.toRadians(yaw));
                
-               // Rotate about its new x-axis for pitch
-               direction = direction.rotate(newAxisX, pitch);
+               Vector3 newAxisZ = newAxisX.cross(newAxisY);
                
-               return direction.normalize();
+               return newAxisZ.invert().normalize();
        }
        
        // Older method; rotates about axes in order Y-X-Z
@@ -259,8 +259,8 @@
         * 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.
+        * This method assumes the Z-Y-X convention, that is, the first 
rotation is done with respect
+        * to the Z-axis and the last rotation is done with respect to the 
X-axis.
         * 
         * @param yaw The yaw angle
         * @param pitch The pitch angle
@@ -270,13 +270,23 @@
        public static Vector3 findUpVector(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 newAxisY = (new Vector3(0, 1, 0)).rotate(new 
Vector3(0, 0, 1), roll);
+               // Vector3 newAxisX = (new Vector3(0, 1, 0)).rotate(new 
Vector3(0, 0, 1), roll);
+               
+               // rotate by z, change x and y
+               // rotate by new x, y is in final position
+               // rotate by new y, x is in final position
+               // obtain z in final position (cross product)
+               
+               Vector3 newAxisX = (new Vector3(1, 0, 0).rotate(new Vector3(0, 
0, 1), Math.toRadians(roll)));
+               Vector3 newAxisY = (new Vector3(0, 1, 0).rotate(new Vector3(0, 
0, 1), Math.toRadians(roll)));
+               
+               newAxisY = newAxisY.rotate(newAxisX, Math.toRadians(pitch));
+               newAxisX = newAxisX.rotate(newAxisY, Math.toRadians(yaw));
+               
                Vector3 newAxisZ = newAxisX.cross(newAxisY);
                
-               Vector3 up = newAxisY.rotate(newAxisZ, roll);
-               
-               return up.normalize();
+               return newAxisY.normalize();
        }
        
        // Older method; rotates about axes in order Y-X-Z
@@ -297,8 +307,8 @@
         * 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.
+        * This method assumes the Z-Y-X convention, that is, the first 
rotation is done with respect
+        * to the Z-axis and the last rotation is done with respect to the 
X-axis.
         * 
         * @param direction The direction vector
         * @param up The up vector
@@ -312,16 +322,16 @@
                Vector3 newAxisX = newAxisY.cross(newAxisZ);
                
                // Calculate the vector representing the line of nodes for the 
Tait-Bryan convention
-               Vector3 lineOfNodes = (newAxisY).cross(new Vector3(0, 0, 1));
+               Vector3 lineOfNodes = (new Vector3(0, 0, 1)).cross(newAxisX);
                
-               // 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);
+               // This vector is perpendicular to the line of nodes
+               Vector3 lineOfNodesPerpendicular = lineOfNodes.rotate(new 
Vector3(0, 0, 1), -Math.PI / 2);
                
                double yaw, pitch, roll;
                
-               yaw = newAxisX.angle(lineOfNodes);
-               pitch = newAxisY.angle(intermediateY);
-               roll = (new Vector3(0, 1, 0)).angle(intermediateY);
+               yaw = newAxisX.angle(lineOfNodesPerpendicular);
+               pitch = newAxisY.angle(lineOfNodes);            
+               roll = (new Vector3(0, 1, 0)).angle(lineOfNodes);
                
                Vector3 result = new Vector3(yaw, pitch, roll);
                result.multiplyLocal(180.0 / Math.PI);

-- 
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