作業1
(a)

作業2

#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();///備份Matrix (Matrix裡面有translate,rotate,scale的量值)
glRotatef(rotX, 0,1,0);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原Matrix(回到剛剛push時的樣子)
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;///(拿來旋轉)
display();///glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///double buffers兩倍記憶體
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
先旋轉後移動
先移動後旋轉
Rotate
Translate
Scale
Translate
Scale
以整個畫面的中間為中心點做旋轉
作業2
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();///備份Matrix (Matrix裡面有translate,rotate,scale的量值)
glRotatef(rotX, 0,1,0);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原Matrix(回到剛剛push時的樣子)
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;///(拿來旋轉)
display();///glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///double buffers兩倍記憶體
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
Q1:什麼是 glPushMatrix();
glPopMatrix();
glPushMatrix()是記住自己現在的位置,而glPopMatrix()是回到之前記住的位置!!
Q2:什麼是 BUFFER?
DOUBLE?
作業3
有X有Y
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();///備份Matrix (Matrix裡面有translate,rotate,scale的量值)
glRotatef(rotY, 1,0,0);///Y的移動量,讓他對x軸轉
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;rotY=y;///(拿來旋轉)
display();///glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///double buffers兩倍記憶體
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言