marcg11
marcg11

Reputation: 732

Objective-c OpenGLES knowing the screen coordinates of the objects/models

Is there a way to get the screen coordinates of the objects in the 3d world?

Upvotes: 1

Views: 695

Answers (2)

genpfault
genpfault

Reputation: 52094

Implement gluProject().

EDIT: Mesa/SGI has some code.

EDIT2: Or grab a copy of GLU for iOS.

Upvotes: 2

Christian Rau
Christian Rau

Reputation: 45948

Just implement the transformations of the OpenGL pipeline: modelview, projection, perspective devide, viewport. You get query the current matrices with glGetDoublev and the viewort with glGetIntegerv.

Then you have to compute projection matrix times modelview matrix = MVP.

now for each vertex v compute MVP*v.

then compute v /= v.w;

So you got coordinates in range [-1,1]x[-1,1], the last thing is scaling and translating this into [x,x+w]x[y,y+h] (which are the values of the viewport).

You can also take a look info pages of the OpenGL reference for glFrustum, glViewport, to see how all these transformations are done.

Upvotes: 1

Related Questions