GLUT程式(Transformation)
Transformation程式 |
glTranslatef --- 控制位置
glRotatef --- 控制旋轉
glScalef --- 控制大小
->將原本的glutSolidTeapot改成glutWireTeapot
茶壺會變成只有框架的茶壺
->加上glutWireCone畫出圓錐
->更改位置及旋轉點 讓圓錐點對準茶壺嘴
->加上滑鼠控制旋轉的程式碼 可讓圓椎透過滑鼠移動旋轉
程式碼
#include<GL/glut.h> float angle=0; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0,0.5,0); glutWireTeapot(0.3); glPopMatrix(); glPushMatrix(); glTranslated(0.51,0.63,0); glRotatef(angle,0,0,1); glTranslatef(0.6,0,0); glRotatef(-90,0,1,0); glutWireCone(0.1,0.6,10,10); glPopMatrix(); glutSwapBuffers(); } void motion(int x,int y) { angle = x; display(); } int main(int argc, char**argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("week10 TRT"); glutDisplayFunc(display); glutMotionFunc(motion); glutMainLoop(); }
->先畫出茶壺
茶壺會變成只有框架的茶壺
->加上glutWireCone畫出圓錐
->更改位置及旋轉點 讓圓錐點對準茶壺嘴
->加上滑鼠控制旋轉的程式碼 可讓圓椎透過滑鼠移動旋轉
程式碼
#include<GL/glut.h> float angle=0; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0,0.5,0); glutWireTeapot(0.3); glPopMatrix(); glPushMatrix(); glTranslated(0.51,0.63,0); glRotatef(angle,0,0,1); glTranslatef(0.6,0,0); glRotatef(-90,0,1,0); glutWireCone(0.1,0.6,10,10); glPopMatrix(); glutSwapBuffers(); } void motion(int x,int y) { angle = x; display(); } int main(int argc, char**argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("week10 TRT"); glutDisplayFunc(display); glutMotionFunc(motion); glutMainLoop(); }
沒有留言:
張貼留言