Location of 3D in 2D
I wasn't sure what to title this one, and I'm not having any luck finding any info about this out there. I had a hard enough time getting my 3D meshes to draw in an Orthographic projection.
So, I have these 3D objects drawing in an orthographic projection. I figured out that translating them is a little bit different because although there is a Z, you can't see any changes until it reaches a clipping plane and the unit of movement is different.
Since the units are different, I'm clueless as to how I can determine the object's size on screen or how I could determine a certain position in the mesh at all times through rotations and all.
Does anyone have any info as to how I can measure 3D objects drawn in an orthographic scene and most importantly, always identify a specific location in that mesh regardless of rotation or position? What I need is the screen space information about the objects. Thanks in advance!
So, I have these 3D objects drawing in an orthographic projection. I figured out that translating them is a little bit different because although there is a Z, you can't see any changes until it reaches a clipping plane and the unit of movement is different.
Since the units are different, I'm clueless as to how I can determine the object's size on screen or how I could determine a certain position in the mesh at all times through rotations and all.
Does anyone have any info as to how I can measure 3D objects drawn in an orthographic scene and most importantly, always identify a specific location in that mesh regardless of rotation or position? What I need is the screen space information about the objects. Thanks in advance!
Oooh, no glu for me. I'm doing an iPhone game.
Then you need to learn linear algebra, and implement software transform.
I have some knowledge of linear algebra. Thanks for narrowing it down for me. I'll just go ahead with that software transform right away. Thanks for your help, now I know exactly what to do now.
Or you can grab it from the mesa source. (I never remember where that is, sorry... try google )
[edit] ... silly me, try: http://www.mesa3d.org/
[edit] ... silly me, try: http://www.mesa3d.org/
http://cgit.freedesktop.org/mesa/mesa/tr.../project.c
Code:
static void __gluMultMatrixVecd(const GLdouble matrix[16], const GLdouble in[4],
GLdouble out[4])
{
int i;
for (i=0; i<4; i++) {
out[i] =
in[0] * matrix[0*4+i] +
in[1] * matrix[1*4+i] +
in[2] * matrix[2*4+i] +
in[3] * matrix[3*4+i];
}
}
GLint GLAPIENTRY
gluProject(GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy, GLdouble *winz)
{
double in[4];
double out[4];
in[0]=objx;
in[1]=objy;
in[2]=objz;
in[3]=1.0;
__gluMultMatrixVecd(modelMatrix, in, out);
__gluMultMatrixVecd(projMatrix, out, in);
if (in[3] == 0.0) return(GL_FALSE);
in[0] /= in[3];
in[1] /= in[3];
in[2] /= in[3];
/* Map x, y and z to range 0-1 */
in[0] = in[0] * 0.5 + 0.5;
in[1] = in[1] * 0.5 + 0.5;
in[2] = in[2] * 0.5 + 0.5;
/* Map x,y to viewport */
in[0] = in[0] * viewport[2] + viewport[0];
in[1] = in[1] * viewport[3] + viewport[1];
*winx=in[0];
*winy=in[1];
*winz=in[2];
return(GL_TRUE);
}
Very helpful and greatly appreciated, thank you Took and Jake.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Subwindow & windows location | CyberWraith | 1 | 3,110 |
Jul 26, 2005 01:30 PM Last Post: OneSadCookie |