opengl中对象的旋转
Rotation of an object in opengl
我需要在按下左箭头键时旋转矩形对象。
我不能旋转它,也许是。可能是缓冲区有问题。
rotatef()
函数是否正确放置或问题所在。
#include<stdlib.h>
#include<glut.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
void rot()
{ glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glRotatef(30,0.0,0.0,1.0);
glBegin(GL_POLYGON);
glVertex2i(50,50);
glVertex2i(170,50);
glVertex2i(170,100);
glVertex2i(50,100);
glEnd();
glPopMatrix();
}
void shape()
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2i(50,50);
glVertex2i(170,50);
glVertex2i(170,100);
glVertex2i(50,100);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
shape();
glutSwapBuffers();
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0,700,0,700,-1,1);
glMatrixMode(GL_MODELVIEW);
}
void Keys(int key,int x,int y)
{
if(key==GLUT_KEY_LEFT)
rot();
glutPostRedisplay();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(700,700);
glutCreateWindow("tetris");
glutDisplayFunc(display);
glutSpecialFunc(Keys);
init();
glutMainLoop();
}
绘制旋转顶点后立即发布重新显示。因此,在绘制旋转的顶点后,在显示回调函数中,您可以清除窗口,然后在不旋转的情况下绘制顶点。这就是您将看到的(不旋转),直到下一次更新。
一种方法是:
- 在显示功能中绘制所有图形
- 作为对按键的反应,只需更新角度(我想你想增量旋转)并重新显示。不要画任何东西,您的显示功能将使用更新后的角度
相关文章:
- 形状对象的旋转和缩放不正确C++
- 鼠标单击 OpenGL 时无法围绕其自己的中心旋转对象
- 无法在D2D1中旋转对象
- 如何使用OpenCV从图像中检测旋转对象
- 无法从非原点的其他位置旋转对象
- 使用键旋转对象
- OpenGL C++围绕场景中心旋转对象
- 围绕另一个对象旋转对象
- 旋转对象及其'children'
- OpenGL 在屏幕上渲染之前旋转对象以设置其正确的表面
- OpenGL 平移和旋转对象
- OpenGL,如何相互独立地旋转对象
- 旋转对象时缺少像素
- 如何在opengl中旋转对象
- 在OpenGL中,在对象自己的轴上旋转对象
- 旋转对象,但保持照明固定DirectX
- 在OpenGL中围绕特定点旋转对象
- Opencv动画使用旋转矩阵旋转对象
- 如何在opengl中使用矩阵移动和旋转对象
- 围绕中心点旋转对象的函数