开发者

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?


Implement gluProject().

EDIT: Mesa/SGI has some code.

EDIT2: Or grab a copy of GLU for iOS.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜