在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);`
由于物体的坐标位置是在屏幕坐标范围外的,所以看不到物体。如何设置当物体显示的时候,物体实在屏幕中央?
简而言之,如何改变物体的中心点坐标或者某点坐标为屏幕中心点坐标?
天蓬老师2017-04-17 17:27:15
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!