Skip to content

@geotheory /gist:2770618
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rotation problem
// 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
Something went wrong with that request. Please try again.