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 & HelpPrograms › model space, identity and camera transformation
Page Index Toggle Pages: 1
model space, identity and camera transformation (Read 432 times)
model space, identity and camera transformation
Apr 1st, 2010, 4:47am
 
I would say that if you take the origin (0,0,0) in modelspace and apply the identity transformation (resetMatrix()) that if would give you coordinate (0,0,0) back. But it does not:

Code:

void setup()
{
 size(256,256,P3D);
}

void draw()
{
 resetMatrix();
 translate(-width/2,-height/2,0);
 print("model (0,0,0) = (");
 print(modelX(0,0,0));
 print(", ");
 print(modelY(0,0,0));
 print(", ");
 print(modelZ(0,0,0));
 print(")\n\n");
 box(64);
}


gives: model (0,0,0) = (0.0, 0.0, 221.70251)

Furthermore, why does the camera position influence the model coordinates?

Code:

void setup()
{
 size(256,256,P3D);
 noFill();
}

void draw()
{
 background(0);
 
//  camera(mouseX,mouseY,200,width/2,height/2,0,0,1,0);

 pushMatrix();  
 translate(width/2,height/2, 0);
 rotateX(QUARTER_PI);
 rotateY(2*QUARTER_PI/3);
 final float x = modelX(0,0,0);
 final float y = modelY(0,0,0);
 final float z = modelZ(0,0,0);
 stroke(255);
 box(64);
 popMatrix();

 // draw "copy"
 translate(x,y,z);
 stroke(255,0,0);
 box(32);
}


If you uncomment the camera(...) line you will see that the boxes don't stick together...

Whatsup?
Re: model space, identity and camera transformation
Reply #1 - Apr 1st, 2010, 3:50pm
 
Answer to first question, about the Z coordinate not being 0 -- I think it has to do with the perspective() function, in which, by default:
cameraZ is ((height/2.0) / tan(PI*60.0/360.0));
(from http://processing.org/reference/perspective_.html)

Second question:
I think you are confusing modelX,Y,Z with screenX,Y,Z.  Try replacing modelX with screenX, modelY with screenY, etc.  modelXYZ is used to find the absolute coordinates in model space, screenXYZ is for absolute position in screen space.
Page Index Toggle Pages: 1