1.主題:旋轉、移動
稍微移動一下他的位置
課堂作業二
讓茶壺左右旋轉
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT); //背景顏色
glPushMatrix(); //備份Matrix (Rotate/Translate/Scale等資料)
glRotatef(rotX,0,1,0); //x的移動量 , 讓他對y軸轉
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix(); //還原Matrix (Push前的資料形式)
glutSwapBuffers(); //把上面準備好的程式一次全展現出來
}
void motion(int x,int y) //旋轉的函式
{
rotX=x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); //兩倍記憶體和深度用於3D
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
課堂作業三
x向量是他左右旋轉,加了y向量就可以上下旋轉
#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; rotY=y;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(300,300); glutInitWindowPosition(600,0); //放大和位置
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
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; rotY=y;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(300,300); glutInitWindowPosition(600,0); //放大和位置
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}





沒有留言:
張貼留言