iDevGames Forums
Location of 3D in 2D - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Location of 3D in 2D (/thread-2027.html)

Location of 3D in 2D - bmantzey - Dec 17, 2008 11:04 AM

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!

Location of 3D in 2D - ThemsAllTook - Dec 17, 2008 11:16 AM

Location of 3D in 2D - bmantzey - Dec 17, 2008 10:53 PM

Oooh, no glu for me. Sad I'm doing an iPhone game.

Location of 3D in 2D - arekkusu - Dec 17, 2008 11:45 PM

Then you need to learn linear algebra, and implement software transform.

Location of 3D in 2D - bmantzey - Dec 18, 2008 12:07 AM

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.

Location of 3D in 2D - AnotherJake - Dec 18, 2008 12:34 AM

Or you can grab it from the mesa source. (I never remember where that is, sorry... try google Sneaky )

[edit] ... silly me, try:

Location of 3D in 2D - ThemsAllTook - Dec 18, 2008 07:59 AM

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];

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];

    __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];


Location of 3D in 2D - bmantzey - Dec 18, 2008 10:05 PM

Very helpful and greatly appreciated, thank you Took and Jake.