Rotating model in openGL 2 in iOS
I'm working with OpenGl on iOS and Android, what I'm trying to do is draw a model, a sphere, set the camera/eye coords inside the sphere, set a texture and enable panning and zoom to achieve a 360 degree effect, I just made for Android using OpenGl 1.0, but I was having a lot of problems in iOS, so I made it using OpenGl 2.0, everything is set and working, but I'm having a problem with the panning, in order to rotate the Model View matrix, I'm applying the rotate transformation, it works but if I change any axis rotation, it messes up the other two axis, At the end if I apply a rotation in both axis, X and Y, the sphere rotates like if some kind of transformation has been don in the Z axis, the texture ends upside-down or being displayed in diagonal, I'm doing the exact same transformations in Android and I don't have any problem there, anybody has some experience with this issue? Any suggestion? clue? code? article? I think that when I apply the first transformation the coords in the space just change and the next transformation is not being applied properly.
Here's my iOS code :
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClear(GL_COLOR_BUFFER_BIT);
GLKMatrixStackPush(_obStack);
GLKMatrixStackRotate(_obStack,
GLKMathDegreesToRadians(_obAngleX),
0.0f, 1.0f, 0.0f);
GLKMatrixStackRotate(_obStack,
GLKMathDegreesToRadians(_obAngleY),
1.0f, 0.0f, 0.0f);
GLKMatrixStackScale(_obStack,
_obScaleFactor,
_obScaleFactor,
_obScaleFactor);
self.obEffect.transform.modelviewMatrix = GLKMatrixStackGetMatrix4(_obStack);
// Prepare effect
[self.obEffect prepareToDraw];
// Draw Model
glDrawArrays(GL_TRIANGLES, 0, panoramaVertices);
GLKMatrixStackPop(_obStack);
self.obEffect.transform.modelviewMatrix = GLKMatrixStackGetMatrix4(_obStack);
}
This is my Android code :
public void onDrawFrame(GL10 arGl) {
arGl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
arGl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
arGl.glPushMatrix();
arGl.glRotatef(obAngleY, 1.0f, 0.0f, 0.0f);
arGl.glRotatef(obAngleX, 0.0f, 1.0f, 0.0f);
arGl.glScalef(obScaleFactor, obScaleFactor, obScaleFactor);
if (obModel != null) {
obModel.draw(arGl);
}
arGl.glPopMatrix();
}
我反复尝试了几次,每次都没有成功,最后,我回去实现了适用于iOS的OpenGL 1.0版本,在这种情况下,无论矩阵何时旋转,轴都不是,所以这是我的解决方案,实现OpenGL 1.0版本。
链接地址: http://www.djcxy.com/p/81828.html上一篇: OpenGL围绕某个点旋转摄像头
下一篇: 在iOS中使用openGL 2旋转模型