Created
May 22, 2012 18:03
-
-
Save geotheory/2770618 to your computer and use it in GitHub Desktop.
Rotation problem
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
// Processing script to resolve a frame rotation problem | |
float zoom; | |
PVector a, b, pvec; | |
void setup() | |
{ | |
size(800, 600, P3D); | |
a = new PVector(0.0, 0.0, 0.0); | |
b = new PVector(200.0, 400.0, -600.0); | |
} | |
void draw() | |
{ | |
background(255); | |
directionalLight(150, 150, 150, 0.3, -0.6, 0.3); | |
ambientLight(100, 100, 100); | |
camera(1200 * sin(mouseX/800.0), 1200 * cos(mouseX/800.0), -mouseY*4, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); | |
stroke(0); | |
line(a.x, a.y, a.z, b.x, b.y, b.z ); | |
// Plot coloured axes | |
stroke(255, 0, 0); | |
line(-1000, 0, 0, 1000, 0, 0); | |
stroke(0, 255, 0); | |
line(0, -1000, 0, 0, 1000, 0); | |
stroke(0, 0, 255); | |
line(0, 0, -1000, 0, 0, 1000); | |
noStroke(); | |
pushMatrix(); | |
pvec = PVector.sub(b, a); | |
translate(pvec.x/2, pvec.y/2, pvec.z/2); | |
// ROTATE FRAME OF REFERENCE TO PLOT A BOX AS A LINE | |
rotateZ(atan(-pvec.x/pvec.y)); | |
rotateX(atan(-pvec.y/pvec.z)); | |
//rotateY(atan(pvec.x/pvec.y)); | |
box(10.0, 10.0, pvec.mag()); | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment