Skip to content

Commit

Permalink
put back get/set rotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Feinberg committed Apr 23, 2010
1 parent 326ecf4 commit 5bb5201
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/peasy/PeasyCam.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

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;
Expand Down Expand Up @@ -470,6 +472,43 @@ public void setState(final CameraState state, final long animationTimeMillis) {
feed();
}

public void setRotations(final double pitch, final double yaw, final double roll) {
rotationInterps.cancelInterpolation();
this.rotation = new Rotation(RotationOrder.XYZ, pitch, yaw, roll);
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 (final CardanEulerSingularityException e) {
}
try {
final double[] angles = rotation.getAngles(RotationOrder.YXZ);
return new float[] { (float)angles[1], (float)angles[0], (float)angles[2] };
} catch (final CardanEulerSingularityException e) {
}
try {
final double[] angles = rotation.getAngles(RotationOrder.ZXY);
return new float[] { (float)angles[2], (float)angles[0], (float)angles[1] };
} catch (final CardanEulerSingularityException e) {
}
return new float[] { 0, 0, 0 };
}

/**
* Thanks to A.W. Martin for the code to do HUD
*/
Expand Down

0 comments on commit 5bb5201

Please sign in to comment.