Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Project and unProject

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    7

    Project and unProject

    How to write the projection(..) and unprojecton(..) likes gluProject and gluUnproject?
    Does anybody know it? Thanks

  2. #2
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Sheffield, Yorkshire, UK
    Posts
    31

    Re: Project and unProject

    This is explained in the blue book, and should be in the glu source from SGI

  3. #3
    Intern Newbie
    Join Date
    Jan 2004
    Location
    Keller, TX
    Posts
    42

    Re: Project and unProject

    I don't know why you want to unproject, but this is how you project a point. Do this for each point in your triangle.

    // Create your 1/z value
    double OneOverZ = ( double )1.0 / ( double )tri[i].z;

    // Project the X point
    point.X = ((tri[i].x * gfCameraScale) * OneOverZ) + (ScreenWidth / 2);

    // Project the Y point
    point.Y = ((tri[i].y * (-gfCameraScale)) * OneOverZ) + (ScreenHeight / 2);

    // Project the UV of the triangle if need be
    tri[i].U = ( double ) NewA[ Count ].U * OneOverZ;
    tri[i].V = ( double ) NewA[ Count ].V * OneOverZ;

    gfCameraScale is usually a value between 100 and 600 depending on the screen width and height and the angle of the fustrum. I don't know how to calculate that.

  4. #4
    Intern Newbie
    Join Date
    Jan 2004
    Location
    Keller, TX
    Posts
    42

    Re: Project and unProject

    do the above with your translated points.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    11

    Re: Project and unProject

    howie's responce is no where near what it takes to project a point in 3D space. for one thing, it does not take into account parallel projections.

    The process of projecting a point is very complex. The red book MIGHT have it (though I don't recall it), I doubt the blue book has it, as that is just documentation on the ogl functions.

    Pickup a copy (it's expensive though) of "Computer Graphics: Principles and Practice" by Foley, Va Dam, Feiner, and Hughes. It will have all of what you need, practically for anything related to graphics (unless it's something uber-new). I don't really think I can explain all of what you have to do in order to project a point.

    However, once you figure out how to project a point, unprojecting it is easy. You just find the inverse of the projection matrix and use THAT matrix to "project" your point.
    capn_midnight | Captain Midnight | deviantArt
    ACM | SIGGRAPH | Generation5

  6. #6
    Intern Newbie
    Join Date
    Jan 2004
    Location
    Keller, TX
    Posts
    42

    Re: Project and unProject

    I've written 2 software rendering, texture mapping, Gouraud shaded, 3D engines. I know how to project a point. Perhaps your thinking about clipping and translation.

    The code above assumes the point has been translated by your matrix. Before you project a point, say on a quad or a try, you have to clip all the points to the near Z plain. But that was not part of his question.

    He asked how to project a point, and that's how I do it. Perhaps there's more then one way to do it, but that's how I do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •