先畫好3D方塊
畫面自動旋轉glutIdleFunc(display)
用glBegin(GL_POLYGON);及glBegin(GL_QUAD_STRIP);
畫出長條形
用glMotionFunc(motion);///mouse motion drag 動作移動的函式
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef( angle, 0, 1, 0.3);
glBegin(GL_POLYGON);;
glColor3f(0,0,1);
glVertex3f(0.1, 0.1, 0.8);
glVertex3f(-0.1, 0.1, 0.8);
glVertex3f(-0.1, -0.1, 0.8);
glVertex3f(0.1, -0.1, 0.8);
glEnd();
glBegin(GL_POLYGON);;
glColor3f(0,1,1);
glVertex3f(0.1, 0.1, -0.8);
glVertex3f(-0.1, 0.1, -0.8);
glVertex3f(-0.1, 0.1, -0.8);
glVertex3f(0.1, -0.1, -0.8);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex3f(0.1, 0.1, 0.8);
glVertex3f(0.1, 0.1, -0.8);
glVertex3f(-0.1, 0.1, 0.8);
glVertex3f(-0.1, 0.1, -0.8);
glVertex3f(-0.1, -0.1, 0.8);
glVertex3f(-0.1, 0.1, -0.8);
glVertex3f(0.1, -0.1, 0.8);
glVertex3f(0.1, -0.1, -0.8);
glEnd();
glPopMatrix();
angle += 0.01;
glFlush();
}
int oldX=0;
void motion(int x, int y)
{
angle += (x-oldX);
oldX=x;
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("02161141 week05");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);///mouse motion drag 動作移動的函式
glutMainLoop();
}
沒有留言:
張貼留言