public
Created

Rotation problem

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// 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();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.