Permalink
Browse files

Added method to query camera for current x/y/z "rotations" required t…

…o face camera
  • Loading branch information...
1 parent 2af81f4 commit f02232d1fde1e9581d50124b833720ab555a5b38 @jdf committed Mar 9, 2009
Showing with 75 additions and 2 deletions.
  1. +1 −1 resources/build.xml
  2. +28 −0 src/peasy/InterpolationManager.java
  3. +43 −0 src/peasy/PeasyCam.java
  4. +3 −1 web/index.html
View
@@ -18,7 +18,7 @@
<property name="author" value="Jonathan Feinberg" />
<property name="copyright" value="(c) 2008" />
<property name="libraryName" value="PeasyCam" />
- <property name="versionNumber" value="0.4.3" />
+ <property name="versionNumber" value="0.5.0" />
<property name="yourLink" value="http://mrfeinberg.com" />
<property name="keywords" value="3D,camera,rotation" />
<property name="tested:platform" value="Windows" />
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package peasy;
+
+import peasy.PeasyCam.AbstractInterp;
+
+class InterpolationManager
+{
+ private AbstractInterp currentInterpolator = null;
+
+ protected synchronized void startInterpolation(final AbstractInterp interpolation)
+ {
+ cancelInterpolation();
+ currentInterpolator = interpolation;
+ currentInterpolator.start();
+ }
+
+ protected synchronized void cancelInterpolation()
+ {
+ if (currentInterpolator != null)
+ {
+ currentInterpolator.cancel();
+ currentInterpolator = null;
+ }
+ }
+
+}
View
@@ -21,7 +21,9 @@
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
+import peasy.org.apache.commons.math.geometry.CardanEulerSingularityException;
import peasy.org.apache.commons.math.geometry.Rotation;
+import peasy.org.apache.commons.math.geometry.RotationOrder;
import peasy.org.apache.commons.math.geometry.Vector3D;
import processing.core.PApplet;
import processing.core.PConstants;
@@ -374,6 +376,47 @@ public void setState(final CameraState state, final long animationTimeMillis)
feed();
}
+ /**
+ * Express the current camera rotation as an equivalent series
+ * of world rotations, in X, Y, Z order. This is useful when,
+ * for example, you wish to orient text towards the camera
+ * at all times, as in
+ *
+ * <pre>float[] rotations = cam.getRotations(rotations);
+ *rotateX(rotations[0]);
+ *rotateY(rotations[1]);
+ *rotateZ(rotations[2]);
+ *text("Here I am!", 0, 0, 0);</pre>
+ */
+ public float[] getRotations()
+ {
+ try
+ {
+ final double[] angles = rotation.getAngles(RotationOrder.XYZ);
+ return new float[] { (float) angles[0], (float) angles[1], (float) angles[2] };
+ }
+ catch (CardanEulerSingularityException e)
+ {
+ }
+ try
+ {
+ final double[] angles = rotation.getAngles(RotationOrder.YXZ);
+ return new float[] { (float) angles[1], (float) angles[0], (float) angles[2] };
+ }
+ catch (CardanEulerSingularityException e)
+ {
+ }
+ try
+ {
+ final double[] angles = rotation.getAngles(RotationOrder.ZXY);
+ return new float[] { (float) angles[2], (float) angles[0], (float) angles[1] };
+ }
+ catch (CardanEulerSingularityException e)
+ {
+ }
+ return new float[] { 0, 0, 0 };
+ }
+
abstract public class AbstractInterp
{
double startTime;
View
@@ -213,7 +213,9 @@
CameraState state = camera.getState(); // get a serializable settings object for current state
camera.setState(CameraState state);
-camera.setState(CameraState state, long animationTimeInMillis); // set the camera to the given saved state</pre>
+camera.setState(CameraState state, long animationTimeInMillis); // set the camera to the given saved state
+
+float[] rotations = camera.getRotations(); // x, y, and z rotations required to face camera in model space</pre>
</div>

0 comments on commit f02232d

Please sign in to comment.