Skip to content

Instantly share code, notes, and snippets.

@bmander
Created May 18, 2012 22:30
Show Gist options
  • Save bmander/2727908 to your computer and use it in GitHub Desktop.
Save bmander/2727908 to your computer and use it in GitHub Desktop.
straightforward click drag to rotate camera around object
float theta;
float phi;
float r;
void setup(){
size(640, 360, P3D);
smooth();
theta=0;
phi=0;
r=100;
}
void mouseDragged(){
theta += (mouseX-pmouseX)*0.01;
phi -= (mouseY-pmouseY)*0.01;
}
void draw(){
float x = cos(phi)*cos(theta)*r;
float z = cos(phi)*sin(theta)*r;
float y = sin(phi)*r;
lights();
background(0);
float up = floor((PI/2-phi)/PI)%2==0 ? 1 : -1;
camera(x, y, z, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, up, 0.0); // upX, upY, upZ
noStroke();
beginShape();
vertex(10,0,0);
vertex(0,0,10);
vertex(0,10,0);
vertex(10,0,0);
endShape();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment