jsyeh.org/3dcg10 下載Window、data、glut32.dll
解壓縮,執行Transformation
1.改變Rotate
車子會原地旋轉
改變Translate一樣是原地旋轉
2.按右鍵,點選swap
先改變Translate
然後Rotate就會繞著中心點旋轉
作業二:
使茶壺旋轉(mouse)
程式碼:
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(0.5,0.5,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//備份Matrix
glRotatef(rotX, 0,1,0);
glColor3f(1,1,0.5);
glutSolidTeapot(0.3);
glPopMatrix();//還原Matrix
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX=x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMotionFunc(motion);
/// glutMouseFunc(mouse);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(0.5,0.5,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//備份Matrix
glRotatef(rotX, 0,1,0);
glColor3f(1,1,0.5);
glutSolidTeapot(0.3);
glPopMatrix();//還原Matrix
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX=x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMotionFunc(motion);
/// glutMouseFunc(mouse);
glutMainLoop();
}
作業三:
同時對X、Y軸做旋轉
程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(0.5,0.5,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotX, 0,1,0);//X的移動量,對Y軸做旋轉
glRotated(rotY, 1,0,0);//Y的移動量,對X軸 轉
glColor3f(1,1,0.5);
glutSolidTeapot(0.3);
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);
glutInitWindowSize(400,400);glutInitWindowPosition(600,0);//hello 3D的視窗設定
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
同時對X、Y軸做旋轉
程式碼:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(0.5,0.5,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotX, 0,1,0);//X的移動量,對Y軸做旋轉
glRotated(rotY, 1,0,0);//Y的移動量,對X軸 轉
glColor3f(1,1,0.5);
glutSolidTeapot(0.3);
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);
glutInitWindowSize(400,400);glutInitWindowPosition(600,0);//hello 3D的視窗設定
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}






沒有留言:
張貼留言