1

I'm having trouble converting pixel coordinates from the mouse to a 3D frustum. I'm using code similar to glProject() on OGL ES 1.1 . I have tried using glUnProject() but I couldn't get the vector to work and I know there is an easier way to do this. I was hoping to be able to compare the 3D and 2D coordinates and figure it out but I have not succeeded. So here's what I know:

  1. I am using a 3D Vertex from the polygon that is being picked:

    -1.0,1.0,0.0

  2. Then I convert it to pixels coordinates with glProject():

    140.0, 259.0, 0.0

  3. I then use the mouse pixel coordinates:

    140.0, 220.0, 0.0

  4. This is the part I can't figure out:

    -1.0, -1.0, 0.0

I got the #3 coordinates from the coordinates of #4 but what I want to do is the opposite which is convert pixels to 3D.

All I really need to know is how far the mouse has been dragged in 3D coordinates from another 3D point.

Jon White
  • 67
  • 4

1 Answers1

0

Okay I got an approximate algorithm working. The way I got it working was by using:

glFrustum(ax,bx,ay,by,az,bz);

I used the ratio of ax and az multiplied by the length of z to find the length of the tx and ty sides of the triangle. Then I used the pixel coordinates to find x and y. I'm not sure if gluUnProject() is any better but the one I used is a lot smaller and easier to understand.

Jon White
  • 67
  • 4