OpenGl -对象在旋转180度后反转
OpenGl - Object inverts after 180 degrees of rotation
我有一个对象渲染,我试图用鼠标旋转对象。对象将旋转180度,但在此之后,对象将反转(如果面向摄像机,则切换到远离摄像机),就像预期的鼠标移动一样,即如果向右拖动鼠标使对象顺时针旋转,那么它现在将逆时针旋转。一旦它达到下一个180度,它再次反转,恢复正常。我相信一定有什么简单的东西是我没有看到的?
下面是我的代码:// Detect mouse state
void
mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
moving = 1;
beginX = x;
beginY = y;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
moving = 0;
}
}
// Detect mouse movement
void motion(int x, int y)
{
if (moving)
{
angleX = (angleX + (x - beginX));
angleY = (angleY + (y - beginY));
beginX = x;
beginY = y;
newModel = 1;
glutPostRedisplay();
}
}
// Rotate object
void recalcModelView(void)
{
// Get object's centre
int hh = head->GetHeight() / 2;
int hw = head->GetWidth() / 2;
int hd = head->GetDepth() / 2;
glPopMatrix();
glPushMatrix();
// Rotate object based on mouse movement
glTranslatef(hw, hd, hh);
float temp1 = angleX / 5;
float temp2 = angleY / 5;
printf("TEMP1: %gn", temp1);
printf("TEMP2: %gn", temp2);
glRotatef(temp1, 0.0, 1.0, 0.0);
glRotatef(-temp2, 1.0, 0.0, 0.0);
glTranslatef(-hw, -hd, -hh);
newModel = 0;
}
使用archball之类的东西来修复这个问题
相关文章:
- 在C++中使用OpenCV矩阵中的特征将图像旋转90度
- 顺时针旋转 M*N 矩阵 90 度,C++
- 从iPhone相机拍摄的视频似乎被OpenCV旋转了90度?我该如何解决这个问题?
- 顺时针旋转90度图像
- 将矩阵逆时针旋转 180 度的问题
- C++向量的向量.阵列旋转 90 度
- 如何使用四元数来描述超过360度的旋转角度?
- 在C 中旋转矩阵(2D阵列)45度
- 在C 中旋转像素阵列90度
- 将轴对齐的矩形旋转90度
- 如何使OpenGL相机旋转360度
- 在 iOS 中将 Spirte 矩形旋转 90 度不会显示纵横比
- OpenCV从T形主体获得360度旋转
- 将2D转换的1D阵列顺时针旋转90度
- 对象不沿其面向的方向移动,除非旋转为 0 度或 180 度
- 如何用OpenCV将图像分成四个象限,并将象限1和象限4旋转180度
- OpenGl -对象在旋转180度后反转
- 将Opencv矩阵旋转90、180、270度
- 从帧缓冲区创建的JPEG被旋转180度
- 在c++中以任意给定度旋转像素数组(例如45度)