jdf / peasycam

Dead-simple mouse-driven camera for Processing
http://MrFeinberg.com/peasycam/
Apache License 2.0
116 stars 35 forks source link

PeasyCam should support set position, and set default #19

Closed sdbugs closed 9 years ago

sdbugs commented 9 years ago

I really like how PeasyCam works - especially with the double-clicking returning you to the default position. The only thing I'm missing is setting this default position of PeasyCam programmatically. So far, on this issue I've found:

How to change PeasyCam position - Processing Forum

PeasyCam is meant to provide intuitive mouse-driven camera movement, and not programmatic control. There are a few excellent libraries for non-interactive camera control.

3d - Rotating camera around object axis with Peasycam - Stack Overflow

Peasycam is not well-suited to programmatic control. If you want to manipulate the view yourself, you'd be better off with the excellent Proscene or OCD libraries.

However, looking at the code, I notice peasycam/src/peasy/CameraState.java has:

    final Rotation rotation;
    final Vector3D center;
    final double distance;

I'm not sure if the center refers to the camera position (cannot tell, because printing it fails the compilation with "The field CameraState.center is not visible"; and I couldn't really test with a new class, because of Is javac supposed to be included with Processing 2* or not? · Issue #2929 · processing/processing · GitHub), but if it does, then all that is needed is to make these properties public instead of final; then I could in principle do (pseudocode):

void setup(){
  size(640, 480, OPENGL);
  cam = new PeasyCam(this, 60);
  CameraState cstate = cam.getState();
  cstate.center = new Vector3D(10, 20, 30); // set new position?
  cam.setState(cstate);
  cam.lookAt(0,0,0);
  cam.setDefaultPosition(); // new API
}

... and then, if something like cam.setDefaultPosition() is added to the API, I could "memorize" the new position (and rotation, as per the lookAt()) as the default, to which the PeasyCam would return upon doubleclick.

However, I'm primarily interested in setting the position programatically - I can somewhat do it with .pan(x,y) (in the x/y plane normal to the camera at start, I guess); but if I do lookAt() after it, the position seemingly gets reset. Is there a way I can do it with the current API? If not, what are the chances for changes to the current API, so that something like the above pseudocode becomes possible?

jdf commented 9 years ago

lookAt() does set the center.

The camera does not have a position, except implicitly, as a result of the composition of rotation, center, and distance.

hmdeif commented 5 years ago

void SetCamVector(float x, float y, float z) { Rotation rot=new Rotation(new Vector3D(0,0,10),new Vector3D(x,y,z)); camera.setState(new CameraState(rot, new Vector3D(0,0,0), camera.getDistance())); }

alexanderwallin commented 5 years ago

A setPosition() would be very handy, as I find working with explicit position a lot more intuitive! Would a PR be of interest?

jdf commented 5 years ago

No; thank you, but I really think something like the OCD library, or just manual camera control, would be better.