Created
May 18, 2012 22:30
-
-
Save bmander/2727908 to your computer and use it in GitHub Desktop.
straightforward click drag to rotate camera around object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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