David Wicks
YaBB Newbies
Offline
Posts: 24
CA
Re: Perpendicular to Camera vector
Reply #6 - Jan 13th , 2008, 6:11pm
In order to avoid that weirdness, you should do the rotation to make the plane face the camera on a per-circle basis. The reason things start spinning is that your camera is turning to face midX, midY, midZ as you move around that point. You are drawing all the circles on a single plane right now, which prevents them from moving 'realistically' in space. The plane is the one you rotated your drawing environment to. When the plane rotates to face the camera, all the circles rotate with it. Make your transformation to place each circle and then rotate that circle to face the camera. Modified snippet from your draw loop: // place circles fill(255,255,00); for ( int i=0; i<circles_arr.length; i++ ) { pushMatrix(); float[] circle = circles_arr[i]; translate(circle[0],circle[1],circle[2]); rotate_to_cam_perpendicular(eyeX, eyeY, eyeZ, midX, midY, midZ); ellipse(0, 0, 10, 10); popMatrix(); }; As an optimization, since you are drawing each circle at the origin, you could calculate your rotations once (avoiding repeated trig calls), and then simply reapply them. //code begins inside draw loop //calculate normal angle to camera from origin float angleZ = getAngleZ( eyeX, eyeY, eyeZ ); float angleY = getAngleY( eyeX, eyeY, eyeZ ); fill(150); box(50); // place circles fill(255,255,00); for ( int i=0; i<circles_arr.length; i++ ) { pushMatrix(); float[] circle = circles_arr[i]; translate(circle[0],circle[1],circle[2]); rotateZ(angleZ); rotateY(angleY); ellipse(0, 0, 10, 10); popMatrix(); }; } //close draw loop float getAngleY( float eyeX, float eyeY, float eyeZ ){ float hyp=sqrt(sq(eyeX)+sq(eyeY)); float angleY=atan2(hyp,eyeZ); return angleY; } float getAngleZ( float eyeX, float eyeY, float eyeZ ){ float angleZ=atan2(eyeY,eyeX); return angleZ; }