Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add rotation constraint modes.

  • Loading branch information...
commit 3ac449a80eace090b47e20d01dbc95344fd27ed0 1 parent 7757dba
@jdf authored
View
12 README.textile
@@ -27,6 +27,16 @@ h3. Methods
<pre>camera.setActive(boolean active); // false to make this camera stop responding to mouse
+// By default, the camera is in "free rotation" mode, but you can
+// constrain it to any axis, around the look-at point:
+camera.setYawRotationMode(); // like spinning a globe
+camera.setPitchRotationMode(); // like a somersault
+camera.setRollRotationMode(); // like a radio knob
+camera.setSuppressRollRotationMode(); // Permit pitch/yaw only.
+
+// Then you can set it back to its default mode:
+camera.setFreeRotationMode();
+
// reassign particular drag gestures, or set them to null
camera.setLeftDragHandler(PeasyDragHandler handler);
camera.setCenterDragHandler(PeasyDragHandler handler);
@@ -75,4 +85,4 @@ PeasyCam is impervious to gimbal lock, and has no known "singularities" or disco
h3. Contributors
-Thanks: "Michael Kaufmann":http://www.michael-kaufmann.ch/, "Oori Shalev":http://ooish.com/, Jeffrey Gentes, "A.W. Martin":http://imaginationfeed.com, "Yiannis Chatzikonstantinou":http://prototy.blogspot.com/, and "Donald Ephraim Curtis":http://milkbox.net/ for bug reports and feature suggestions.
+Thanks: "Gennaro Senatore":http://wiki.uelceca.net/msc0809/published/gennaro+senatore, "Michael Kaufmann":http://www.michael-kaufmann.ch/, "Oori Shalev":http://ooish.com/, Jeffrey Gentes, "A.W. Martin":http://imaginationfeed.com, "Yiannis Chatzikonstantinou":http://prototy.blogspot.com/, and "Donald Ephraim Curtis":http://milkbox.net/ for bug reports and feature suggestions.
View
2  build.xml
@@ -5,7 +5,7 @@
</description>
<property name="processing" location="../processing-1.5.1" />
- <property name="processingLibraries" location="../sketchbook/libraries" />
+ <property name="processingLibraries" location="C:/Documents and Settings/Administrator/My Documents/Processing/libraries" />
<property name="libraryClasspath" location="${processing}/lib" />
<path id="library-classpath">
View
2  library.properties
@@ -3,4 +3,4 @@ authorList = [Jonathan Feinberg](http://mrfeinberg.com/)
url = http://mrfeinberg.com/peasycam/
category = 3D
sentence = A mouse driven camera-control library for 3D sketches.
-version = 102
+version = 105
View
2  src/peasy/DampedAction.java
@@ -29,7 +29,7 @@
abstract public class DampedAction {
private final PeasyCam p;
private double velocity;
- final double damping;
+ private final double damping;
public DampedAction(final PeasyCam p) {
this(p, 0.16);
View
106 src/peasy/PeasyCam.java
@@ -41,7 +41,7 @@
private static final Vector3D UP = Vector3D.plusJ;
private static enum Constraint {
- X, Y
+ YAW, PITCH, ROLL, SUPPRESS_ROLL
}
private final PApplet p;
@@ -61,6 +61,7 @@
private Rotation rotation;
private Constraint dragConstraint = null;
+ private Constraint permaConstraint = null;
private final InterpolationManager rotationInterps = new InterpolationManager();
private final InterpolationManager centerInterps = new InterpolationManager();
@@ -102,7 +103,7 @@ public void handleWheel(final int delta) {
private final PMatrix3D originalMatrix; // for HUD restore
- public final String VERSION = "102";
+ public final String VERSION = "105";
public PeasyCam(final PApplet parent, final double distance) {
this(parent, 0, 0, 0, distance);
@@ -183,7 +184,7 @@ public void setActive(final boolean active) {
public boolean isActive() {
return isActive;
}
-
+
/**
* <p>
* Turn on or off default mouse-handling behavior:
@@ -211,6 +212,7 @@ public boolean isActive() {
* @param isMouseControlled
* @deprecated use {@link #setActive(boolean)}
*/
+ @Deprecated
public void setMouseControlled(final boolean isMouseControlled) {
setActive(isMouseControlled);
}
@@ -219,7 +221,7 @@ public double getWheelScale() {
return wheelScale;
}
- public void setWheelScale(double wheelScale) {
+ public void setWheelScale(final double wheelScale) {
this.wheelScale = wheelScale;
}
@@ -290,9 +292,11 @@ public void mouseEvent(final MouseEvent e) {
if (e.isShiftDown()) {
if (dragConstraint == null && Math.abs(dx - dy) > 1) {
- dragConstraint = Math.abs(dx) > Math.abs(dy) ? Constraint.X
- : Constraint.Y;
+ dragConstraint = Math.abs(dx) > Math.abs(dy) ? Constraint.YAW
+ : Constraint.PITCH;
}
+ } else if (permaConstraint != null) {
+ dragConstraint = permaConstraint;
} else {
dragConstraint = null;
}
@@ -318,36 +322,45 @@ private void mouseZoom(final double delta) {
private void mousePan(final double dxMouse, final double dyMouse) {
final double panScale = Math.sqrt(distance * .005);
- pan(dragConstraint == Constraint.Y ? 0 : -dxMouse * panScale,
- dragConstraint == Constraint.X ? 0 : -dyMouse * panScale);
+ pan(dragConstraint == Constraint.PITCH ? 0 : -dxMouse * panScale,
+ dragConstraint == Constraint.YAW ? 0 : -dyMouse * panScale);
}
private void mouseRotate(final double dx, final double dy) {
final Vector3D u = LOOK.scalarMultiply(100 + .6 * startDistance).negate();
- if (dragConstraint != Constraint.X) {
- final double rho = Math.abs((p.width / 2d) - p.mouseX) / (p.width / 2d);
- final double adz = Math.abs(dy) * rho;
- final double ady = Math.abs(dy) * (1 - rho);
- final int ySign = dy < 0 ? -1 : 1;
- final Vector3D vy = u.add(new Vector3D(0, ady, 0));
- rotateX.impulse(Vector3D.angle(u, vy) * ySign);
- final Vector3D vz = u.add(new Vector3D(0, adz, 0));
- rotateZ.impulse(Vector3D.angle(u, vz) * -ySign
- * (p.mouseX < p.width / 2 ? -1 : 1));
- }
+ final int xSign = dx > 0 ? -1 : 1;
+ final int ySign = dy < 0 ? -1 : 1;
- if (dragConstraint != Constraint.Y) {
- final double eccentricity = Math.abs((p.height / 2d) - p.mouseY)
- / (p.height / 2d);
- final int xSign = dx > 0 ? -1 : 1;
- final double adz = Math.abs(dx) * eccentricity;
+ final double eccentricity = Math.abs((p.height / 2d) - p.mouseY)
+ / (p.height / 2d);
+ final double rho = Math.abs((p.width / 2d) - p.mouseX) / (p.width / 2d);
+
+ if (dragConstraint == null || dragConstraint == Constraint.YAW
+ || dragConstraint == Constraint.SUPPRESS_ROLL) {
final double adx = Math.abs(dx) * (1 - eccentricity);
final Vector3D vx = u.add(new Vector3D(adx, 0, 0));
rotateY.impulse(Vector3D.angle(u, vx) * xSign);
- final Vector3D vz = u.add(new Vector3D(0, adz, 0));
- rotateZ.impulse(Vector3D.angle(u, vz) * xSign
- * (p.mouseY > p.height / 2 ? -1 : 1));
+ }
+ if (dragConstraint == null || dragConstraint == Constraint.PITCH
+ || dragConstraint == Constraint.SUPPRESS_ROLL) {
+ final double ady = Math.abs(dy) * (1 - rho);
+ final Vector3D vy = u.add(new Vector3D(0, ady, 0));
+ rotateX.impulse(Vector3D.angle(u, vy) * ySign);
+ }
+ if (dragConstraint == null || dragConstraint == Constraint.ROLL) {
+ {
+ final double adz = Math.abs(dy) * rho;
+ final Vector3D vz = u.add(new Vector3D(0, adz, 0));
+ rotateZ.impulse(Vector3D.angle(u, vz) * -ySign
+ * (p.mouseX < p.width / 2 ? -1 : 1));
+ }
+ {
+ final double adz = Math.abs(dx) * eccentricity;
+ final Vector3D vz = u.add(new Vector3D(0, adz, 0));
+ rotateZ.impulse(Vector3D.angle(u, vz) * xSign
+ * (p.mouseY > p.height / 2 ? -1 : 1));
+ }
}
}
@@ -459,6 +472,41 @@ public CameraState getState() {
return new CameraState(rotation, center, distance);
}
+ /**
+ * Permit arbitrary rotation. (Default mode.)
+ */
+ public void setFreeRotationMode() {
+ permaConstraint = null;
+ }
+
+ /**
+ * Only permit yaw.
+ */
+ public void setYawRotationMode() {
+ permaConstraint = Constraint.YAW;
+ }
+
+ /**
+ * Only permit pitch.
+ */
+ public void setPitchRotationMode() {
+ permaConstraint = Constraint.PITCH;
+ }
+
+ /**
+ * Only permit roll.
+ */
+ public void setRollRotationMode() {
+ permaConstraint = Constraint.ROLL;
+ }
+
+ /**
+ * Only suppress roll.
+ */
+ public void setSuppressRollRotationMode() {
+ permaConstraint = Constraint.SUPPRESS_ROLL;
+ }
+
public void setMinimumDistance(final double minimumDistance) {
this.minimumDistance = minimumDistance;
safeSetDistance(distance);
@@ -586,8 +634,8 @@ public void draw() {
public DistanceInterp(final double endDistance, final long timeInMillis) {
super(timeInMillis);
- this.endDistance = Math.min(maximumDistance, Math.max(minimumDistance,
- endDistance));
+ this.endDistance = Math.min(maximumDistance,
+ Math.max(minimumDistance, endDistance));
}
@Override
View
11 web/index.html
@@ -179,6 +179,7 @@
<li><a href="http://prototy.blogspot.com/">Yiannis Chatzikonstantinou</a></li>
<li><a href="http://milkbox.net/">Donald Ephraim Curtis</a></li>
<li><a href="http://www.michael-kaufmann.ch/">Michael Kaufmann</a></li>
+<li><a href="http://wiki.uelceca.net/msc0809/published/gennaro+senatore">Gennaro Senatore</a></li>
</ul>
<p>Please let me know if I've forgotten to acknowledge you.</p>
@@ -203,6 +204,16 @@
<h3>Methods</h3>
<pre class="prettyprint">camera.setActive(boolean active); // false to make this camera stop responding to mouse
+// By default, the camera is in "free rotation" mode, but you can
+// constrain it to any axis, around the look-at point:
+camera.setYawRotationMode(); // like spinning a globe
+camera.setPitchRotationMode(); // like a somersault
+camera.setRollRotationMode(); // like a radio knob
+camera.setSuppressRollRotationMode(); // Permit pitch/yaw only.
+
+// Then you can set it back to its default mode:
+camera.setFreeRotationMode();
+
// reassign particular drag gestures, or set them to null
camera.setLeftDragHandler(PeasyDragHandler handler);
camera.setCenterDragHandler(PeasyDragHandler handler);
Please sign in to comment.
Something went wrong with that request. Please try again.