backspaces 
		
		Junior Member
		 
		Offline 
		
		
		Posts: 66
		
		
		
		
 
	 
	
		
			
				UP vector: seems backwards  
				 Nov 19th , 2006, 11:42pm 
			 
			
				
	  
			 
		
		
			I'm trying to *really* understand homogeneous coords and affine transformations .. using the computer graphics book by F. S. Hill.  As a start, I'm playing with the camera. I'm a bit confused by the up vector used by the camera .. it seems to be backwards! Here's a tiny experiment: http://www.backspaces.net/files/testcam0/applet/ Its a rectangle in the x-y plane with x,y,z axes, and a center sphere which can be turned on/off. I can change the up vector by hitting the x,y,z keys, and reverse the sign of the vector by hitting the - key. The vectors seem reversed: [0,0,1] has the z axis pointing down.  But [0,0,-1] does what I want, aligning the camera with the positive Z axis. Is this the correct behavior?  If so, can anybody explain why? Owen The code: float upX, upY, upZ; boolean drawSphere = true; void setup() {   size(500, 500, P3D);   textFont(loadFont("AmericanTypewriter-Bold-24.vlw"));   frameRate(5);   setCamera(0,0,1); } void draw() {   background(200);   if(drawSphere) {     noStroke();     fill(200,0,0);     sphere(50);//box(100, 100, 100);   }   stroke(0);   fill(255, 255, 255, 200);   rect(-200,-200,400,400);   float len = width/2;   line(0,0,0,len,0,0);   line(0,0,0,0,len,0);   line(0,0,0,0,0,len);   fill(color(255,0,0));   text("X",len,0,0);   text("Y",0,len,0);   text("Z",0,0,len); } void setCamera(float upX, float upY, float upZ) {   this.upX = upX; this.upY = upY; this.upZ = upZ;   camera(width,width,width,  0,0,0,  upX,upY,upZ);   println("Up vector: ["+upX+" "+upY+" "+upZ+"]  drawSphere="+drawSphere);   printCamera(); } void keyPressed() {   switch(key) {   case 'x':      setCamera(1,0,0);     break;   case 'y':      setCamera(0,1,0);     break;   case 'z':      setCamera(0,0,1);     break;   case 's':      drawSphere = !drawSphere;     break;   case '-':      setCamera(neg(upX),neg(upY),neg(upZ));     break;   } } float neg(float f) { // avoid odd -0.0 float.   return f==0f? f:-f; }