HW-1
Translate 是平移
rolate是旋轉
scale是放大
HW-2
如果先translate 再rolate
就會是繞著軸心點公轉
如果先rolate 再translate
就會是在軸心點自轉
HW-3
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//(備份Matrix (Matrix裡有Translate,rolate,scale的量值)
glRotatef(rotX, 0,1,0);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix();//還原Matrix(回到剛剛push時的樣子)
glutSwapBuffers();//buffers
}
void motion(int x,int y)
{
rotX=x;
display();
}
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();
Ans:glPushMatrix():是將資料丟進函式進行改變
glPopMatrix():是將程式輸出使用
Q2:什麼是Buffers?
Double?
Ans:Buffer:怕圖不完整要先進行一是測試處理
Double:多做一次讓圖更加完整
glPopMatrix();
Ans:glPushMatrix():是將資料丟進函式進行改變
glPopMatrix():是將程式輸出使用
Q2:什麼是Buffers?
Double?
Ans:Buffer:怕圖不完整要先進行一是測試處理
Double:多做一次讓圖更加完整
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotY, 1,0,0); //可以使茶壺做Y軸旋轉
glRotatef(rotX, 0,1,0);
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("hello 3d");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}







沒有留言:
張貼留言