I'm trying to use Jonathan Feinberg's Peasycam library for processing to rotate the camera around the objects' Z axis. The documentation specifies for rotation is around subject, but not the object. This seems incredibly difficult to achieve. The peasycam rotations act around the subject (i.e. camera) not object, although in control sense peasycam's emphasis is object-oriented. And setting the camera()
seems problematic too, as I can't get the peasycam to remember the assigned camera's position. There's also a discrepancy whereby the peasycam's y axis maps to the data-space's z axis.
I've made a basic model to help explain this interactively. Grateful if some fresh eyes can help untangle this. Peasycam may need installing to the application's library folder. The overall aim is to be able to spin 3D data-plots on Z axis for animation purposes. Thanks in advance.
import peasy.*;
PVector camPos;
PVector[] points = new PVector[50];
float angleXY, d;
PeasyCam cam;
void setup() {
size(300,300,P3D);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(150);
for(int i=0; i<50; i++) points[i] = new PVector(random(-15,15),random(-15,15),random(-15,15));
}
void draw() {
background(250);
noFill();
box(30);
// axes for frame of reference
stroke(255,0,0); // red = Z
line(0,0,-100,0,0,100);
stroke(0,255,0); // green = Y
line(0,-100,0,0,100,0);
stroke(0,0,255); // blue = X
line(-100,0,0,100,0,0);
// points on axes to denote positive orientation
strokeWeight(3);
for(PVector p:points) point(p.x, p.y, p.z);
strokeWeight(5);
point(40,0,0);
point(0,40,0);
point(0,0,40);
strokeWeight(1);
stroke(0);
camPos = new PVector(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
angleXY = degrees(atan2(camPos.z, camPos.x)); // camera XY angle from origin
d = sqrt(pow(camPos.z, 2) + pow(camPos.x, 2)); // camera-object XY distance (compare to cam.getDistance())
// ZX campera slots map to XY data plane:
println("campos: " + camPos + " " + ", ang: " + angleXY + ", dist:" + d);
}
void keyPressed(){
if(key=='r') setup(); // restart
if(key==' ') camera(camPos.x, camPos.y, camPos.z, 0, 0, 0, 0, 0, 1); // stabilise image on Z axis
if(key=='d') {
angleXY += radians(1);
camera(sin(angleXY)*d, camPos.y, cos(angleXY)*d, 0, 0, 0, 0, 1, 0);
}
// peasycam's rotations work around the subject:
if(key=='p') cam.rotateY(radians(2));
}