
這次一樣是先到這裡先下載這三個檔案
網誌是:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
1-1
先開啟3D模型然後在下塗黑色的區域案右鍵把兩個對調
並寫出其差異性

1-2
把車子縮小然後移到左邊比較其差異性


當rotate 在第二個的時候 他是以車子的中心點為旋轉軸所以怎麼旋轉都會只看到車子中心打轉

當rotate在第一個的時候 他以整張圖的中心為旋轉軸 所以你會看到車著以中圖的中心做旋轉
2-1

這次是講如何讓物體旋轉 程式碼如下
#include <GL/glut.h>
#include <stdio.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//這一行會先備份原始的旋轉量大小的各種量質
glRotated(rotX, 0,1,0);//這一行是用來選擇旋轉軸 可以選擇Y軸或X軸
glColor3f(0.3,0.5,0);//這是選擇茶壺的顏色
glutSolidTeapot(0.5);//這是茶壺的大小
glPopMatrix();//這用來還原成最原始的量質
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
display();
}
int main (int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);//double是指雙倍
glutCreateWindow(":)");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
3-1

這個跟上一個比只是多了一個選轉軸這樣看起來就是立體的了
#include <GL/glut.h>
#include <stdio.h>
float rotX=0, rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotY, 1,0,0);
glRotated(rotX, 0,1,0);
glColor3f(0.3,0.5,0);
glutSolidTeapot(0.5);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
rotY=y;
display();
}
int main (int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(":)");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

這個跟上一個比只是多了一個選轉軸這樣看起來就是立體的了
#include <GL/glut.h>
#include <stdio.h>
float rotX=0, rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotY, 1,0,0);
glRotated(rotX, 0,1,0);
glColor3f(0.3,0.5,0);
glutSolidTeapot(0.5);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
rotY=y;
display();
}
int main (int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(":)");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
多了Y的rotate主要是讓我們能控制另一個角度的旋轉
沒有留言:
張貼留言