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 › camera coordinates
Page Index Toggle Pages: 1
camera coordinates (Read 783 times)
camera coordinates
Jan 2nd, 2007, 9:24pm
 
How can I get the coordinates of the camera rect?
Re: camera coordinates
Reply #1 - Jan 2nd, 2007, 10:53pm
 
not sure, but doesn't screenX(), ..., screenZ() work for that?

upper left:
int x1 = screenX(0,0,0);
int y1 = screenY(0,0,0);
int z1 = screenZ(0,0,0);

lower right:
int x2 = screenX(width,height,0);
int y2 = screenY(width,height,0);
int z2 = screenZ(width,height,0);

just a guess though ..
F
Re: camera coordinates
Reply #2 - Jan 3rd, 2007, 1:17am
 
Unfortunately screenX/Y/Z just tell you where a point in 3D space maps to the display window, so screenX(0,0,0) will tell you where a cube at 0,0,0 would be centred on screen.

modelX/Y/Z do the reverse, screen->world.. exccept they don't exactly map.. they go to some internal half-way values instead.

It is possible to work out the bounds of the view frustrum, but it's a right pain in the arse.
Re: camera coordinates
Reply #3 - Jan 3rd, 2007, 2:10am
 
Quote:
It is possible to work out the bounds of the view frustrum, but it's a right pain in the arse.


Ah... tell me about it. I've spent two or three days trying to wrap my head around that and gave up.

In any case, if you can avoid using translateZ completely and go with scale() (in case you're doing something 2D but need to  zoom in and out) that would make life a lot easier.
Re: camera coordinates
Reply #4 - Jan 3rd, 2007, 4:41am
 
Quote:
modelX/Y/Z do the reverse, screen->world.. exccept they don't exactly map.. they go to some internal half-way values instead.

It is possible to work out the bounds of the view frustrum, but it's a right pain in the arse.

no, modelX/Y/Z give you the coordinates in model space. this is the coordinates of the object after any user-specific translate/rotate/scale, but before the camera settings have been applied to manipulate the points. i just noticed that the reference on this has not been written, i'm guessing either casey asked me to and i haven't yet, or i did at some point and we forgot to update it, sorry.

to get the view coordinates, you can look at the source of PGraphics3D. since you're looking for the frustum, you might try searching for the text 'frustum', which turns up the 'frustum' function. working backwards from that, you can see it gets called from perspective():

Code:

public void perspective(float fov, float aspect, float zNear, float zFar) {
float ymax = zNear * tan(fov / 2.0f);
float ymin = -ymax;

float xmin = ymin * aspect;
float xmax = ymax * aspect;

frustum(xmin, xmax, ymin, ymax, zNear, zFar);
}


so those are the coords for the viewing frustum. this perspective() function is called from the overloaded no args version:

Code:

public void perspective() {
perspective(cameraFOV, cameraAspect, cameraNear, cameraFar);
}


searching for cameraFOV et al turns up the resize() method, in which you'll find:

Code:

cameraFOV = 60 * DEG_TO_RAD; // at least for now
cameraX = width / 2.0f;
cameraY = height / 2.0f;
cameraZ = cameraY / ((float) tan(cameraFOV / 2.0f));
cameraNear = cameraZ / 10.0f;
cameraFar = cameraZ * 10.0f;

cameraAspect = (float)width / (float)height;


now you can frustum with the best of em.
Page Index Toggle Pages: 1