課堂作業1:
(1)網址:jsyeh/3dcg10
(2)下載data,win32,glut32
(3)解壓縮win32,移到桌面
(4)將data和glut32移到解壓縮檔裡面
(5)點Transformation
(2)下載data,win32,glut32
(3)解壓縮win32,移到桌面
(4)將data和glut32移到解壓縮檔裡面
(5)點Transformation
作業1-1
覺得旋轉位置可能不同吧。
作業1-2
先移 glTranslatef ->glRotatef
*不管移動到哪裡,都在原地旋轉
作業1-3
點 [s] Swap translate/rotate先移 glScalef ->glTranslatef ->glRotatef
*依據移動的位置,作圓周運動
物體越小,旋轉半徑越大
課堂作業2:
程式:
#include <GL/glut.h>
float rotX=0;//起始為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);//大小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);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
Q1:什麼是glPushMatrix? 什麼是glPopMatrix?
A:備份Matrix(Matrix裡有translate, rotate, scale 的量值) ; 還原Matrix (回到剛剛push的樣子)。
Q2:什麼是Buffer? 什麼是Double?
A:double buffers兩倍記憶體
課堂作業3:
*做出一個可以上下旋轉的茶壺!


程式:
#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");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言