1.練習其中考考題
glPushMatrix(); //備份矩陣
glRotatef(angle,x,y,z); //旋轉
glranslatef(x,y,z); //縮放
glBegin(GL_POLYGON); //開始畫
glNormal3f(nx,ny,nz); //打光的法向量
glTexCoord2f(tx,ty); //貼圖座標
glColor3f(r,g,b); //顏色
glVertex3f(x,y,z); //頂點
glEnd(); //結束畫
glPopMatrix(); //還原矩陣
2.理解
自行調整看看車子的變化。
自行調整看看車子的變化。
3.TRT(中心點錯誤)
#include <GL/glut.h>
float mouseX=0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPushMatrix();
glRotatef(mouseX, 0,0,1);
glTranslatef(0.5, 0,0);
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");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
4.製作變色茶壺
#include <GL/glut.h>
float mouseX=0;void display(void)
{
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); //使白色茶壺可以轉動
glTranslatef(0.41,-0.05,0); //將把手移至轉盤的中心
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");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言