We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › camera() upX upY upZ
Page Index Toggle Pages: 1
camera() upX upY upZ (Read 513 times)
camera() upX upY upZ
Jan 17th, 2008, 9:17pm
 
I've been trying to figure how to reconcile the upX,Y,Z parameters for camera() and the global coord system. How does changing these parameters affect the coordinate system orientation?
Re: camera() upX upY upZ
Reply #1 - Jan 21st, 2008, 7:54pm
 
void setup(){
 size(1000,1000,P3D);
 x=1000;y=1000;
}
int z=1000;
int x=width/2;
int y=height/2;
int tx=x,ty=y,tz=0;
int bx=0,by=0,bz=0;
boolean follow=true;
void draw(){
background(255);

if(follow){
tx=x;
ty=y;
tz=0;
}

camera(x,y,z,tx,ty,tz,0,-1,0 );
pushMatrix();
 translate(bx,by,bz);
 fill(0);
 rect(0,0,width,height);
 translate(width,0,0);
 fill(126);
 rotateY(PI/2);
 rect(0,0,width,height);
 translate(0,height,0);
 fill(240,220,130);
 rotateX(-PI/2);
 rect(0,0,width,height);
 popMatrix();
 println(x+" "+y+" "+z);
 println("tx ty tz "+tx+" "+ty+" "+tz);
 println("bx by bz "+bx+" "+by+" "+bz);
}

void mouseDragged() {
 if (mouseX - pmouseX > 0)  
   x -=10;
 else  
   x +=10;

 if(mouseY-pmouseY>0)
   y-=10;
  else y+=10;

}
void keyPressed(){
if(noCaseKey('w')){
 y+=10;
}else if(noCaseKey('a')){
  x-=10;
}else if(noCaseKey('s')){
 y-=10;
}else if(noCaseKey('d')){
 x+=10;
}else if(noCaseKey('x')){
 z+=10;
}else if(noCaseKey('z')){
 z-=10;
}
 else if(noCaseKey('i')){
 ty+=10;
}else if(noCaseKey('j')){
  tx-=10;
}else if(noCaseKey('k')){
 ty-=10;
}else if(noCaseKey('l')){
 tx+=10;
}else if(noCaseKey('q')){
  follow=!follow;
}
else if(keyCode==UP){
 by+=10;
}else if(keyCode==LEFT){
  bx-=10;
}else if(keyCode==RIGHT){
  bx+=10;
}else if(keyCode==DOWN){
  by-=10;
}
}

boolean noCaseKey(char a){
 char k=Character.toUpperCase(a);
 if(key==a)return true;
 return false;
}



-----------------------------

right hopefully this will help someone out there. basically WASD ZX moves the camera. Q toggles whether where the camera is looking at moves together with the camera movement. IJKL moves where the camera is looking at. Arrow keys move the box.

The x,y,z and other coords are displayed in the console.
Re: camera() upX upY upZ
Reply #2 - Jan 21st, 2008, 10:16pm
 
It isn't clear what your question is - what's it not doing, or doing wrong?

You can think of the up-vector as the "roll" around the at-vector.  (yes, it's actually more complicated than that, but you can ignore it for simple cases unless manually orthonormalizing your axes sounds like fun Cheesy)  Stare at some distant object, now tilt your head until your ear touches your shoulder -- that's a change in the up-vector pointing out the top of your head.  Rolling camera clockwise looks same as rolling world counter-clockwise, and vice versa.

Here's what you might change to experiment with it, first define these variables:

float upx=0,upy=1,upz=0,roll=PI/2;

Then change your camera() statement so:

upx = cos(roll);
upy = -sin(roll);  // negate to match screen coords
camera(x,y,z,tx,ty,tz,upx,upy,upz );

Then ammend your keyboard handler so:

else if(noCaseKey('c')){
  roll -= 0.01f;
}else if(noCaseKey('v')){
 roll += 0.01f;
}
Re: camera() upX upY upZ
Reply #3 - Jan 22nd, 2008, 7:54am
 
Oh it's not that camera() is doing anything wrong. It's just the documentation doesn't say where the axes are pointing after you define the up vector. It's also because my understanding of the xyz axes are opposite of where it's pointing.

Page Index Toggle Pages: 1