去http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載
下載data,win32,glut32.dll
glTranslatef:是移動位置
glRotatef:是旋轉位置
glScalef:是改變車型
可以隨你改你想要的位址跟車型
作業2 打開GLUT
下載feeglut
找資料來源放入feeglut資料夾
就可以進入main
單旋轉茶壺
#include <GL/glut.h>float rotX=0;
void display()
{
glClearColor(1,1,1,1);//背景顏色
glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色
glPushMatrix();//備份位置
glRotatef(rotX,0,1,0);//將滑鼠移動的x轉換為rotate-x
glColor3f(1,0,0);//紅色
glutSolidTeapot(0.3);//茶壺
glPopMatrix();//取出位置使用
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;//將滑鼠移動的x轉換為rotate-x
display();
}
int main(int argc,char**argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glutMotionFunc(motion);//motion函式
glutMainLoop();
}
雙旋轉茶壺
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);//背景顏色
glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色
glPushMatrix();//備份位置
glRotatef(rotY,1,0,0);//將滑鼠Y的移動量對x軸旋轉
glRotatef(rotX,0,1,0);//將滑鼠X的移動量對y軸旋轉
glColor3f(1,0,0);//紅色
glutSolidTeapot(0.3);//茶壺
glPopMatrix();//取出位置使用
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;//將滑鼠x的移動量轉換為rotate-x
rotY=y;//將滑鼠y的移動量轉換為rotate-y
display();
}
int main(int argc,char**argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glutMotionFunc(motion);//motion函式
glutMainLoop();
沒有留言:
張貼留言