下載data、win32、glut32.dll 這三個檔案
將win32解壓縮然後把glut32.dll 放入window資料夾
執行Transfromation
安培右手定則
glRotatef( 角度, X軸, Y軸, Z軸);
X軸:正值>右手大拇指向右 轉動向內
負值>右手大拇指向左 轉動向外
Y軸:正值>右手大拇指向上 轉動向內
負值>右手大拇指向下 轉動向外
Z軸:正值>右手大拇指向內 逆時針轉動
負值>右手大拇指向外 順時針轉動
期中考考題

可以轉動的茶壺
#include <stdio.h>
#include <GL/glut.h>
float angle=0,teapotX=0,teapotY=0;
int oldX=0,oldY=0,nowRotate=0;///
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);///
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
///printf("%.1f\n",angle);
///angle++;
}
void mouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)nowRotate=1;
if(button==GLUT_RIGHT_BUTTON&&state==GLUT_DOWN)nowRotate=0;
oldX=x;oldY=y;///
}
void motion(int x,int y)
{
if(nowRotate==1)angle+=(x-oldX);
else
{
teapotX += (x-oldX)/150.0;///
teapotY += (oldY-y)/150.0;///
}
oldX=x; oldY=y;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("05160133_week04 transformation");
glutMouseFunc(mouse);
glutMotionFunc(motion);
///glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言