然後我突然覺得我有讀題障礙
1.實作:壺之貴人
附錄:今天的程式碼
#include <GL/glut.h>
float angle1=0,angle2=0,angle3=0,angle4=0,angle5=0,angle6=0,angle7=0,angle8=0;
int jID=1;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslated(0,0,0);
glColor3f(1,1,0);
glutWireTeapot(0.3);
glPushMatrix();
glTranslated(0.3,0,0);
glRotatef(angle1,0,0,1);
glTranslated(0.15,0,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPushMatrix();
glTranslated(0.3,0,0);
glRotatef(angle2,0,0,1);
glTranslated(0.15,0,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslated(-0.3,0,0);
glRotatef(-angle3,0,0,1);
glTranslated(-0.15,0,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPushMatrix();
glTranslated(-0.3,0,0);
glRotatef(-angle4,0,0,1);
glTranslated(-0.15,0,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPopMatrix();
glPopMatrix();
glTranslated(0,0,0);
glColor3f(1,1,0);
glutWireTeapot(0.3);
glPushMatrix();
glTranslated(0.3,0,0);
glRotatef(angle5,0,0,1);
glTranslated(0.15,-0.2,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPushMatrix();
glTranslated(0.3,0,0);
glRotatef(angle6,0,0,1);
glTranslated(0.15,-0.2,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPopMatrix();
glPopMatrix();
glTranslated(0,0,0);
glColor3f(1,1,0);
glutWireTeapot(0.3);
glPushMatrix();
glTranslated(-0.3,0,0);
glRotatef(-angle7,0,0,1);
glTranslated(-0.15,-0.2,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPushMatrix();
glTranslated(-0.3,0,0);
glRotatef(-angle8,0,0,1);
glTranslated(-0.15,-0.2,0);
glColor3f(1,1,1);
glutSolidTeapot(0.15);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
//angle++;
}
int oldx,oldy;
void motion(int x,int y)
{
if(jID==1) angle1+=(x-oldx);
if(jID==2) angle2+=(x-oldx);
if(jID==3) angle3+=(x-oldx);
if(jID==4) angle4+=(x-oldx);
if(jID==5) angle5+=(x-oldx);
if(jID==6) angle6+=(x-oldx);
if(jID==7) angle7+=(x-oldx);
if(jID==8) angle8+=(x-oldx);
oldx=x;
display();
}
void mouse(int butten,int state,int x,int y)
{
oldx=x;
oldy=y;
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') jID=1;
if(key=='2') jID=2;
if(key=='3') jID=3;
if(key=='4') jID=4;
if(key=='5') jID=5;
if(key=='6') jID=6;
if(key=='7') jID=7;
if(key=='8') jID=8;
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
最後附上
沒有留言:
張貼留言