ios - opengl根据点坐标构图后,不在屏幕可视范围内怎么解决
迷茫
迷茫 2017-04-17 17:25:15
0
1
410

在ios端利用opengl建模,成功展示了一个3d模型,update内容如下

CGSize size = self.view.bounds.size; float aspect = fabs(size.width / size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(bigSize), aspect, 1.0f, 10.0f);//GLKMathDegreesToRadians值越大,模型越小(0-180) self.effect.transform.projectionMatrix = projectionMatrix; GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, 0.0f, 0.0f, 0.0f); modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, 0.0f, 0.0f, -2.0f); //平移 modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 0.1f, xxx, 1.0f); //旋转 GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); GLint mat = glGetUniformLocation(0.0f, "modelViewProjectionMatrix"); glUniformMatrix4fv(mat, 1, GL_FALSE, modelViewProjectionMatrix.m);`

由于物体的坐标位置是在屏幕坐标范围外的,所以看不到物体。如何设置当物体显示的时候,物体实在屏幕中央?
简而言之,如何改变物体的中心点坐标或者某点坐标为屏幕中心点坐标?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (1)
Peter_Zhu

Solved, I finally found the maximum and minimum xyz values based on all the vertex data in the model file, calculated the center point coordinates of the model based on the xyz values, and then positioned the model at (0.0.0) based on the scale Redrawing enables the model to be displayed in the center of the screen. As for the appropriate size, you need to find the maximum length of the model, and then find a suitable proportion on the screen based on the length of the model. Multiply all xyz values by this ratio. . . . Perfect solution. Hope someone can use it!

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!