Week 06
HW1_練習期中考題函式
glPushMatrix();//備份矩陣glRotatef(angle,x,y,z);//(旋轉角度,x,y,z)
glTranslatef(x,y,z);//移動
glScalef(x,y,z);//縮放
glBegin(GL_POLYGON);//開始畫
glNormal3f(nx,ny,nz);//打光的法向量
glTexCoord2f(tx,ty);//貼圖座標
glColor3f(r,g,b);//顏色
glVertex3f(x,y,z);//頂點
glEnd();//結束
glPopMatrix();//還原矩陣
HW2_理解函式運作邏輯
glPushMatrix();
glRotatef(angle,x,y,z);
glTranslatef(x,y,z);
glScalef(x,y,z);
glBegin(GL_POLYGON);
glNormal3f(nx,ny,nz);
glTexCoord2f(tx,ty);
glColor3f(r,g,b);
glVertex3f(x,y,z);
glEnd();
glPopMatrix();
glut函式具有階層性的轉動,先執行Begin(開始)~End(結束)函式及其內部函式。接續到外層的縮放(Scalef)、移動(Translatef)、在旋轉(Rotatef),由內而外的運行glut函式。
理解在在Transformation.exe檔中,可以利用右手來判別物體旋轉的方向。
Rotatef(x,y,y軸的方向,z)
HW3_T-R-T
#include <GL/glut.h>float mouseX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(mouseX, 0,0,1);
glColor3f(1,0,0);glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14,0);//把白色茶壺手把移動到紅色茶壺嘴
glRotatef(mouseX, 0,0,1);//step2滑鼠轉動
glTranslatef(0.41, -0.05,0);//step1 把手把移到轉盤位置
glColor3f(1,1,1); glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX = x;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("TRT robot");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言