简体   繁体   English

iPhone OpenGL ES - 如何选择

[英]iPhone OpenGL ES - How to Pick

I'm working on an OpenGL ES1 app which displays a 2D grid and allows user to navigate and scale/rotate it. 我正在开发一个OpenGL ES1应用程序,它可以显示2D网格并允许用户导航和缩放/旋转它。 I need to know the exact translation of View Touch coordinates into my opengl world and grid cell. 我需要知道View Touch坐标到我的opengl世界和网格单元的确切转换。 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 ? 或者我应该手工计算并做矩阵的东西?

Sounds like what you're looking for is an unproject method. 听起来像你正在寻找的是一个非项目方法。 The glut library comes with one, but it's not available on OpenGL ES. glut库附带一个,但它在OpenGL ES上不可用。 It's possible to rewrite the glut code yourself to be iphone compatible You could also write your own code to unproject, which would involve needing to scale the touchpoint to your viewport, multiply it by the inverse of your projection*modelview matrices, and divide by w to get a 3D vector. 您可以自己重写过剩代码以兼容iphone您也可以编写自己的代码来进行非项目,这需要将接触点缩放到您的视口,将其乘以投影*模型视图矩阵的倒数,然后除以w得到一个3D矢量。

Picking mode is not available in openGL ES. 拣配模式在openGL ES中不可用。 But it's easy to calculate the screen coordinate of any 3d point using the projection matrix retrieved from current openGL state. 但是使用从当前openGL状态检索的投影矩阵可以很容易地计算任何3d点的屏幕坐标。 Here is how I do it (IMPoint2D and IMPoint3D are basic (x,y) and (x,y,z) structures) 我是这样做的(IMPoint2D和IMPoint3D是基本(x,y)和(x,y,z)结构)

+ (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};
}

Could be possible to do this with GL_MODELVIEW_MATRIX? 可以用GL_MODELVIEW_MATRIX做到这一点吗? or GL_MODLVIEW, I´m not modifing the view position, only del modelview. 或者GL_MODLVIEW,我没有修改视图位置,只有del modelview。 I´m doing this: 我这样做:

            glMatrixMode(GL_MODELVIEW);

// Setup model view matrix
            glLoadIdentity();
            [gAccel GetAccelerometerMatrix:(GLfloat *) matrix headingX:headx headingY: heady headingZ:headz];

            // Finally load matrix
            glLoadMatrixf((GLfloat*)matrix);

            glPushMatrix();
            glRotatef(-90, 1, 0, 0);
            glScalef(0.0005, 0.0005, 0.0005);
            glTranslatef(x, 0.0, z);

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM