iPhone OpenGL ES - 如何选择 [英] iPhone OpenGL ES - How to Pick

查看:111
本文介绍了iPhone OpenGL ES - 如何选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个OpenGL ES1应用程序,该应用程序显示2D网格并允许用户导航和缩放/旋转它。我需要知道View Touch坐标到我的opengl世界和网格单元的确切转换。是否有任何助手可以完成我为导航做的最后几次变换的反向操作?或者我应该手工计算和做矩阵的东西?

I'm working on an OpenGL ES1 app which displays a 2D grid and allows user to navigate and scale/rotate it. I need to know the exact translation of View Touch coordinates into my opengl world and grid cell. Are there any helpers to do the reverse of last few transforms which I do for navigation ? or I should calculate and do the matrix stuff by hand ?

推荐答案

在openGL ES中没有拣货模式。但是使用从当前openGL状态检索的投影矩阵来计算任何3d点的屏幕坐标都很容易。
我是这样做的(IMPoint2D和IMPoint3D是基本的(x,y)和(x,y,z)结构)

Picking mode is not available in openGL ES. But it's easy to calculate the screen coordinate of any 3d point using the projection matrix retrieved from current openGL state. Here is how I do it (IMPoint2D and IMPoint3D are basic (x,y) and (x,y,z) structures)

+ (IMPoint2D) getScreenCoorOfPoint:(IMPoint3D)_point3D
{
    GLfloat     p[16];                                              // Where The 16 Doubles Of The Projection Matrix Are To Be Stored
    glGetFloatv(GL_PROJECTION_MATRIX, p);                           // Retrieve The Projection Matrix
/*
Multiply M * point
*/
    GLfloat _p[] = {p[0]*_point3D.x +p[4]*_point3D.y +p[8]*_point3D.z + p[12],
                    p[1]*_point3D.x +p[5]*_point3D.y +p[9]*_point3D.z + p[13],
                    p[2]*_point3D.x +p[6]*_point3D.y +p[10]*_point3D.z+ p[14],
                    p[3]*_point3D.x +p[7]*_point3D.y +p[11]*_point3D.z+ p[15]};
/*
divide by scale factor
*/
    IMPoint2D _p2D = {_p[0]/_p[3], _p[1]/_p[3]};
/*
get result in screen coordinates. In this case I'm in landscape mode
*/
    return (IMPoint2D) {_p2D.x*240.0f + 240.0f, (1.0f - _p2D.y) *160.0f};
}

这篇关于iPhone OpenGL ES - 如何选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆