summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2007-04-10 00:23:45 +0000
committerKenneth Russel <[email protected]>2007-04-10 00:23:45 +0000
commit5da3c985902fb90edd32ce2af2e82518ff8cefbe (patch)
tree70248546e070b1ad63fa72827a2c698e9628f61c
parent3e839104e21ff5010f3b4751db9408f5c3386c5d (diff)
Fixed bug in computation of orthographic projection matrix where it
was not taking into account the Z offset of the near/far planes. Fixed bug in Camera's unprojection routine where it needed to specify the negation of the near distance for the initial Z coordinate. Added getWidth() and getHeight() to Texture2 node. Added convenience method getPickedPoint() to RayPickAction. Added check to Camera to avoid recomputing the projection matrix if the aspect ratio was set to the same value as the last time. Made Group node Iterable. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/joglutils/trunk@65 83d24430-9974-4f80-8418-2cc3294053b9
-rw-r--r--src/net/java/joglutils/msg/actions/RayPickAction.java11
-rw-r--r--src/net/java/joglutils/msg/nodes/Camera.java9
-rw-r--r--src/net/java/joglutils/msg/nodes/Group.java7
-rw-r--r--src/net/java/joglutils/msg/nodes/OrthographicCamera.java3
-rw-r--r--src/net/java/joglutils/msg/nodes/Texture2.java38
5 files changed, 63 insertions, 5 deletions
diff --git a/src/net/java/joglutils/msg/actions/RayPickAction.java b/src/net/java/joglutils/msg/actions/RayPickAction.java
index 633d7c4..ee2528a 100644
--- a/src/net/java/joglutils/msg/actions/RayPickAction.java
+++ b/src/net/java/joglutils/msg/actions/RayPickAction.java
@@ -154,12 +154,21 @@ public class RayPickAction extends Action {
/** Returns the list of points this action selected during the last
traversal, sorted in increasing order of distance from the
- origin. Typically applications will only need to deal with the
+ camera. Typically applications will only need to deal with the
first point in the returned list. */
public List<PickedPoint> getPickedPoints() {
return pickedPoints;
}
+ /** Returns the closest point to the camera this action selected
+ during the last traversal, or null if no points were picked. */
+ public PickedPoint getPickedPoint() {
+ List<PickedPoint> pickedPoints = getPickedPoints();
+ if (pickedPoints == null || pickedPoints.isEmpty())
+ return null;
+ return pickedPoints.get(0);
+ }
+
/** Returns the computed 3D ray in world coordinates that this
RayPickAction is using for its picking. If the action is
configured with on-screen coordinates instead of with a 3D ray,
diff --git a/src/net/java/joglutils/msg/nodes/Camera.java b/src/net/java/joglutils/msg/nodes/Camera.java
index 8dc63d4..ecd7179 100644
--- a/src/net/java/joglutils/msg/nodes/Camera.java
+++ b/src/net/java/joglutils/msg/nodes/Camera.java
@@ -111,6 +111,8 @@ public abstract class Camera extends Node {
/** Sets the aspect ratio of the camera -- the width of the viewport
divided by the height of the viewport. */
public void setAspectRatio(float aspectRatio) {
+ if (aspectRatio == this.aspectRatio)
+ return;
this.aspectRatio = aspectRatio;
projDirty = true;
}
@@ -195,10 +197,13 @@ public abstract class Camera extends Node {
public void unproject(Vec2f point, Line line) throws SingularMatrixException {
// First, we are going to compute the 3D point which corresponds
// to the given point on the near plane. Map the screen
- // coordinates to the (-1, 1) range.
+ // coordinates to the (-1, 1) range. Note that because the camera
+ // points down the -Z axis, we use as the initial Z coordinate of
+ // the 3D point we need to unproject the negation of the near
+ // distance.
Vec4f pt3d = new Vec4f(2 * point.x() - 1,
2 * point.y() - 1,
- getNearDistance(),
+ -getNearDistance(),
1);
// Compute the cumulative view and projection matrices
Mat4f mat = new Mat4f();
diff --git a/src/net/java/joglutils/msg/nodes/Group.java b/src/net/java/joglutils/msg/nodes/Group.java
index ccf06f0..05486ab 100644
--- a/src/net/java/joglutils/msg/nodes/Group.java
+++ b/src/net/java/joglutils/msg/nodes/Group.java
@@ -43,7 +43,7 @@ import net.java.joglutils.msg.actions.*;
/** A node which manages other Node instances. */
-public class Group extends Node {
+public class Group extends Node implements Iterable<Node> {
private List<Node> children = new ArrayList<Node>();
/** Append a child node to the list of children nodes this group node is managing. */
@@ -124,6 +124,11 @@ public class Group extends Node {
replaceChild(idx, newChild);
}
+ /** Returns an Iterator over the nodes this Group contains. */
+ public Iterator<Node> iterator() {
+ return children.iterator();
+ }
+
public void doAction(Action action) {
for (int i = 0; i < getNumChildren(); i++) {
action.apply(getChild(i));
diff --git a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java
index 0678acd..28c657a 100644
--- a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java
+++ b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java
@@ -61,11 +61,12 @@ public class OrthographicCamera extends Camera {
if ((height == 0) || (width == 0) || (deltaZ == 0))
return projMatrix;
- // This is a simplified version of the orthographic camera
+ // This is a simplified version of the orthographic projection
// matrix where it's symmetric about the origin
projMatrix.set(0, 0, 2.0f / width);
projMatrix.set(1, 1, 2.0f / height);
projMatrix.set(2, 2, -2.0f / deltaZ);
+ projMatrix.set(2, 3, -(zFar + zNear) / deltaZ);
}
return projMatrix;
diff --git a/src/net/java/joglutils/msg/nodes/Texture2.java b/src/net/java/joglutils/msg/nodes/Texture2.java
index 02763fc..d405f0a 100644
--- a/src/net/java/joglutils/msg/nodes/Texture2.java
+++ b/src/net/java/joglutils/msg/nodes/Texture2.java
@@ -140,6 +140,44 @@ public class Texture2 extends Node {
dirty = true;
}
+ /** Returns the width of the texture or TextureRenderer this
+ Texture2 node is referencing, or 0 if it has not been set up
+ yet. */
+ public int getWidth() {
+ if (data != null) {
+ return data.getWidth();
+ }
+
+ if (texture != null) {
+ return texture.getWidth();
+ }
+
+ if (textureRenderer != null) {
+ return textureRenderer.getWidth();
+ }
+
+ return 0;
+ }
+
+ /** Returns the height of the texture or TextureRenderer this
+ Texture2 node is referencing, or 0 if it has not been set up
+ yet. */
+ public int getHeight() {
+ if (data != null) {
+ return data.getHeight();
+ }
+
+ if (texture != null) {
+ return texture.getHeight();
+ }
+
+ if (textureRenderer != null) {
+ return textureRenderer.getHeight();
+ }
+
+ return 0;
+ }
+
/**
* Updates a subregion of the content area of this texture using the
* specified sub-region of the given data. Only updates the