Author: paperwing
Date: 2012-01-18 16:13:37 -0800 (Wed, 18 Jan 2012)
New Revision: 28044
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/geometric/Vector3.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/rendering/RenderNodesProcedure.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/ScalableShapeDrawer.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
Log:
Cube shape drawing completed, changed drawing method to accommodate normals for
lighting. Currently the cube size is such that it can be inscribed in the
sphere shape. In process of implementing tetrahedral shape, but the rotation
method in Vector3 needs to be revised for accuracy
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/geometric/Vector3.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/geometric/Vector3.java
2012-01-18 23:37:05 UTC (rev 28043)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/geometric/Vector3.java
2012-01-19 00:13:37 UTC (rev 28044)
@@ -314,7 +314,7 @@
/** Treating this vector as a position vector, rotate it about the
* given normal that passes through the origin by the specified
- * angle clockwise, in radins
+ * angle in the right-hand rule direction, in radians
*
* @param normal The normal vector used for the rotation
* @param angle The angle in radians to rotate this vector
@@ -332,7 +332,6 @@
// -c is the centre of the circle.
//TODO: obtain a more efficient sin function
-
Vector3 rotated;
rotated = normal.normalize();
@@ -343,6 +342,39 @@
return rotated;
}
+ public Vector3 rotateDebug(Vector3 normal, double angle) {
+ // Parametric equation for circle in 3D space:
+ // P = Rcos(t)u + Rsin(t)nxu + c
+ //
+ // Where:
+ // -u is a unit vector from the centre of the circle to any point
+ // on the circumference
+ // -R is the radius
+ // -n is a unit vector perpendicular to the plane
+ // -c is the centre of the circle.
+
+ //TODO: obtain a more efficient sin function
+ Vector3 rotated;
+
+ rotated = normal.normalize();
+
+
+ System.out.println("current vector:" + this);
+ System.out.println("normal after normalization:" + rotated);
+
+ rotated.crossLocal(this);
+ System.out.println("normal after cross product:" + rotated);
+
+ rotated.multiplyLocal(Math.sin(angle));
+ System.out.println("normal after multiplication with sin(angle):" +
rotated);
+
+ System.out.println("current vector multiplied by cos(angle): " +
this.multiply(Math.cos(angle)));
+
+ rotated.addLocal(this.multiply(Math.cos(angle)));
+
+ return rotated;
+ }
+
public Vector3 towards(Vector3 other, double fraction) {
Vector3 result = other.subtract(this);
result.multiplyLocal(fraction);
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-01-18 23:37:05 UTC (rev 28043)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
2012-01-19 00:13:37 UTC (rev 28044)
@@ -130,12 +130,12 @@
private void processCameraRoll(Set<Integer> held, SimpleCamera camera) {
// Roll camera clockwise
- if (held.contains(KeyEvent.VK_Z)) {
+ if (held.contains(KeyEvent.VK_X)) {
camera.rollClockwise();
}
// Roll camera counter-clockwise
- if (held.contains(KeyEvent.VK_X)) {
+ if (held.contains(KeyEvent.VK_Z)) {
camera.rollCounterClockwise();
}
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
2012-01-18 23:37:05 UTC (rev 28043)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
2012-01-19 00:13:37 UTC (rev 28044)
@@ -126,7 +126,8 @@
//gl.glCallList(nodeListIndex);
gl.glScalef(SMALL_SPHERE_RADIUS,
SMALL_SPHERE_RADIUS, SMALL_SPHERE_RADIUS);
- shapeDrawer.drawShape(gl,
ShapeType.SHAPE_CUBIC);
+ // shapeDrawer.drawShape(gl,
ShapeType.SHAPE_CUBIC);
+ shapeDrawer.drawShape(gl,
ShapeType.SHAPE_TETRAHEDRAL);
gl.glPopMatrix();
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/ScalableShapeDrawer.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/ScalableShapeDrawer.java
2012-01-18 23:37:05 UTC (rev 28043)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/ScalableShapeDrawer.java
2012-01-19 00:13:37 UTC (rev 28044)
@@ -7,6 +7,9 @@
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
+import org.cytoscape.paperwing.internal.geometric.Vector3;
+import org.cytoscape.paperwing.internal.tools.RenderToolkit;
+
public class ScalableShapeDrawer {
private static final int SPHERE_SLICES_DETAIL = 12;
@@ -30,6 +33,7 @@
public void initialize(GL2 gl) {
initializeSphere(gl);
initializeCube(gl);
+ initializeTetrahedron(gl);
}
// Diameter 1 sphere
@@ -57,58 +61,127 @@
float halfLength = (float) (1.0 / Math.sqrt(2) / 2);
gl.glNewList(shapeListIndex, GL2.GL_COMPILE);
- gl.glBegin(GL2.GL_TRIANGLE_STRIP);
+ // gl.glBegin(GL2.GL_TRIANGLE_STRIP);
+ gl.glPushMatrix();
+ gl.glScalef(halfLength, halfLength, halfLength);
+
+ gl.glBegin(GL2.GL_QUADS);
+
// +y face
- gl.glNormal3f(0, 1, 0);
- gl.glVertex3f(-halfLength, halfLength, -halfLength); // -x, -z
- gl.glVertex3f(halfLength, halfLength, -halfLength); // +x, -z
- gl.glVertex3f(-halfLength, halfLength, halfLength); // -x, +z
- gl.glVertex3f(halfLength, halfLength, halfLength); // +x, +z
+ gl.glNormal3i(0, 1, 0);
+ gl.glVertex3i(-1, 1, -1); // -x, -z
+ gl.glVertex3i(1, 1, -1); // +x, -z
+ gl.glVertex3i(1, 1, 1); // +x, +z
+ gl.glVertex3i(-1, 1, 1); // -x, +z
// +z face
- gl.glNormal3f(0, 0, 1);
- gl.glVertex3f(halfLength, -halfLength, halfLength);
+ gl.glNormal3i(0, 0, 1);
+ gl.glVertex3i(-1, 1, 1);
+ gl.glVertex3i(1, 1, 1);
+ gl.glVertex3i(1, -1, 1);
+ gl.glVertex3i(-1, -1, 1);
// +x face
- gl.glNormal3f(1, 0, 0);
- gl.glVertex3f(halfLength, halfLength, -halfLength);
- gl.glVertex3f(halfLength, -halfLength, -halfLength);
+ gl.glNormal3i(1, 0, 0);
+ gl.glVertex3i(1, 1, 1);
+ gl.glVertex3i(1, 1, -1);
+ gl.glVertex3i(1, -1, -1);
+ gl.glVertex3i(1, -1, 1);
+ // -y face
+ gl.glNormal3i(0, -1, 0);
+ gl.glVertex3i(-1, -1, -1);
+ gl.glVertex3i(1, -1, -1);
+ gl.glVertex3i(1, -1, 1);
+ gl.glVertex3i(-1, -1, 1);
+
// -z face
- gl.glNormal3f(0, 0, -1);
- gl.glVertex3f(-halfLength, halfLength, -halfLength);
- gl.glVertex3f(-halfLength, -halfLength, -halfLength);
+ gl.glNormal3i(0, 0, -1);
+ gl.glVertex3i(-1, 1, -1);
+ gl.glVertex3i(1, 1, -1);
+ gl.glVertex3i(1, -1, -1);
+ gl.glVertex3i(-1, -1, -1);
// -x face
- gl.glNormal3f(-1, 0, 0);
- gl.glVertex3f(-halfLength, halfLength, halfLength);
- gl.glVertex3f(-halfLength, -halfLength, halfLength);
+ gl.glNormal3i(-1, 0, 0);
+ gl.glVertex3i(-1, 1, 1);
+ gl.glVertex3i(-1, 1, -1);
+ gl.glVertex3i(-1, -1, -1);
+ gl.glVertex3i(-1, -1, 1);
- // +z face
- gl.glNormal3f(0, 0, 1);
- gl.glVertex3f(halfLength, -halfLength, halfLength);
+ gl.glEnd();
+ gl.glPopMatrix();
- // -y face
- gl.glNormal3f(0, -1, 0);
- gl.glVertex3f(-halfLength, -halfLength, -halfLength);
- gl.glVertex3f(halfLength, -halfLength, -halfLength);
+ gl.glEndList();
-// // -y face
-// gl.glNormal3f(0, -1, 0);
-// gl.glVertex3f(halfLength, -halfLength, -halfLength);
-// gl.glVertex3f(-halfLength, -halfLength, -halfLength);
+ shapeLists.put(ShapeType.SHAPE_CUBIC, shapeListIndex);
+ }
+
+ // Tetrahedron inscribed in circle with radius 0.5
+ private void initializeTetrahedron(GL2 gl) {
+ int shapeListIndex = gl.glGenLists(1);
+
+ double radius = 0.5;
+ Vector3 yAxisDirection = new Vector3(0, 1, 0);
+ Vector3 zAxisDirection = new Vector3(0, 0, 1);
+ // Points' positions are relative to the center of the shape
+ Vector3 topPoint = new Vector3(0, radius * 4, 0);
+ Vector3 nearLeftPoint = topPoint.rotate(zAxisDirection,
Math.toRadians(120));
+ System.out.println("nearLeft after first rotation: " +
nearLeftPoint);
+ System.out.println("nearLeft distance: " +
nearLeftPoint.magnitude());
+ nearLeftPoint = nearLeftPoint.rotateDebug(yAxisDirection,
Math.toRadians(30));
- // gl.glVertex3f(-cornerCoordinate, -cornerCoordinate,
cornerCoordinate);
- // gl.glNorm
+ Vector3 farPoint = nearLeftPoint.rotate(yAxisDirection,
Math.toRadians(240));
+ Vector3 nearRightPoint = nearLeftPoint.rotate(yAxisDirection,
Math.toRadians(120));
+ Vector3 frontNormal =
topPoint.plus(nearLeftPoint).plus(nearRightPoint);
+ frontNormal.normalizeLocal();
+
+ Vector3 leftBackNormal = frontNormal.rotate(yAxisDirection,
Math.toRadians(240));
+ Vector3 rightBackNormal = frontNormal.rotate(yAxisDirection,
Math.toRadians(120));
+ Vector3 bottomNormal = new Vector3(0, -1, 0);
+
+ System.out.println("Tetrahedron coordinates: ");
+ System.out.println("top: " + topPoint);
+ System.out.println("nearLeft: " + nearLeftPoint);
+ System.out.println("nearLeft distance: " +
nearLeftPoint.magnitude());
+ System.out.println("nearRight: " + nearRightPoint);
+ System.out.println("nearRight distance: " +
nearRightPoint.magnitude());
+ System.out.println("far: " + farPoint);
+ System.out.println("far distance: " + farPoint.magnitude());
+
+ gl.glNewList(shapeListIndex, GL2.GL_COMPILE);
+
+ gl.glBegin(GL2.GL_TRIANGLES);
+
+ RenderToolkit.setNormal(gl, frontNormal);
+ RenderToolkit.drawPoint(gl, topPoint);
+ RenderToolkit.drawPoint(gl, nearRightPoint);
+ RenderToolkit.drawPoint(gl, nearLeftPoint);
+
+ RenderToolkit.setNormal(gl, leftBackNormal);
+ RenderToolkit.drawPoint(gl, topPoint);
+ RenderToolkit.drawPoint(gl, farPoint);
+ RenderToolkit.drawPoint(gl, nearRightPoint);
+
+ RenderToolkit.setNormal(gl, rightBackNormal);
+ RenderToolkit.drawPoint(gl, topPoint);
+ RenderToolkit.drawPoint(gl, nearRightPoint);
+ RenderToolkit.drawPoint(gl, farPoint);
+
+ RenderToolkit.setNormal(gl, bottomNormal);
+ RenderToolkit.drawPoint(gl, nearRightPoint);
+ RenderToolkit.drawPoint(gl, farPoint);
+ RenderToolkit.drawPoint(gl, nearLeftPoint);
+
gl.glEnd();
gl.glEndList();
- shapeLists.put(ShapeType.SHAPE_CUBIC, shapeListIndex);
+ shapeLists.put(ShapeType.SHAPE_TETRAHEDRAL, shapeListIndex);
}
public void drawShape(GL2 gl, ShapeType shapeType) {
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
2012-01-18 23:37:05 UTC (rev 28043)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
2012-01-19 00:13:37 UTC (rev 28044)
@@ -27,5 +27,18 @@
(float) rotateAxis.y(),
(float) rotateAxis.z());
}
+
+ public static void drawPoint(GL2 gl, Vector3 point) {
+ gl.glVertex3f((float) point.x(),
+ (float) point.y(),
+ (float) point.z());
+ }
+ public static void setNormal(GL2 gl, Vector3 normal) {
+ Vector3 normalized = normal.normalize();
+
+ gl.glNormal3f((float) normalized.x(),
+ (float) normalized.y(),
+ (float) normalized.z());
+ }
}
--
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.