貼上上周的TRT_robot
改變angel++
先畫一個茶壺,把茶壺中心移到正中間!
>>>>>>>
#include <GL/glut.h>
| float angle = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void display() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutSolidSphere(0.02 , 30 , 30); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glPushMatrix(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glTranslatef(0.46,-0.05,0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutSolidTeapot(0.3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glPopMatrix(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutSwapBuffers(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| angle++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int main(int argc, char* argv[] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutInit(&argc, argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutCreateWindow("week05"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutDisplayFunc(display); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutIdleFunc(display); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| glutMainLoop(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }
讓茶壺轉動 >>>>>>>
>>>>>>>
|
>>>>>>>
| #include <GL/glut.h> | |
| float angle = 0; | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); | |
| glutSolidSphere(0.02 , 30 , 30); | |
| glutSolidTeapot(0.3); | |
| glPushMatrix(); | |
| ///glTranslatef( 0.5 , 0.5 , 0 ); | |
| glRotatef(angle,0,0,1); | |
| glTranslatef(0.46,-0.05,0); | |
| glutSolidTeapot(0.3); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char* argv[] ) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); | |
| glutCreateWindow("week05"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |
改茶壺座標
>>>>>>>
| #include <GL/glut.h> | |
| float angle = 0; | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); | |
| glutSolidSphere(0.02 , 30 , 30); ///圓在正中心 | |
| glutSolidTeapot(0.3); ///身體 | |
| glPushMatrix(); | |
| ///glTranslatef( 0.5 , 0.5 , 0 ); 先註解掉 | |
| glTranslatef( 0.49 , 0.13 , 0 ); | |
| glRotatef(angle,0,0,1); | |
| glTranslatef(0.46,-0.05,0); | |
| glutSolidTeapot(0.3); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char* argv[] ) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); | |
| glutCreateWindow("week05"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |
| #include <GL/glut.h> | |
| float angle = 0; | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); | |
| ///glutSolidSphere(0.02 , 30 , 30); ///圓在正中心 | |
| glutSolidTeapot(0.3); ///身體 | |
| glPushMatrix(); | |
| ///glTranslatef( 0.5 , 0.5 , 0 ); 先註解掉 | |
| glTranslatef( 0.49 , 0.13 , 0 ); | |
| glRotatef(angle,0,0,1); | |
| glTranslatef(0.46,-0.05,0); | |
| glutSolidTeapot(0.3); | |
| glPushMatrix(); ///右手肘 | |
| glTranslatef( 0.49 , 0.13 , 0 ); | |
| glRotatef(angle,0,0,1); | |
| glTranslatef(0.46,-0.05,0); | |
| glutSolidTeapot(0.3); | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char* argv[] ) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); | |
| glutCreateWindow("week05"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |
week06_2
讓方塊旋轉
>>>>>>>
#include <GL/glut.h>
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
畫手肘
>>>>>>>
| #include <GL/glut.h> | |
| float angle = 0; | |
| void drawHand() | |
| { | |
| glPushMatrix(); | |
| glScalef(1,0.3,0.3); | |
| glutSolidCube(0.5); | |
| glPopMatrix(); | |
| } | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///清背景 | |
| glPushMatrix(); | |
| ///(3)要掛上去 | |
| ///glRotatef(angle , 0 , 0 , 1); ///軸動 | |
| ///glTranslatef( 0.25 , 0 , 0); ///(1)把中心點放在正中間 | |
| drawHand(); | |
| glPushMatrix(); | |
| glRotatef( angle, 0, 0, 1); | |
| glTranslatef( 0.25 , 0 , 0); | |
| drawHand(); | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
| glutCreateWindow("week04"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |
讓兩個方塊都旋轉
>>>>>>>
| include <GL/glut.h> | |
| float angle = 0; | |
| void drawHand() | |
| { | |
| glPushMatrix(); | |
| glScalef(1,0.3,0.3); | |
| glutSolidCube(0.5); | |
| glPopMatrix(); | |
| } | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///清背景 | |
| glPushMatrix(); | |
| glTranslatef( 0.25 , 0 , 0); ///(3)要掛上去 | |
| glRotatef(angle , 0 , 0 , 1); ///(2)軸動 | |
| glTranslatef( 0.25 , 0 , 0); ///(1)把中心點放在正中間 | |
| drawHand(); | |
| glPushMatrix(); | |
| glTranslatef( 0.25 , 0 , 0);///(3)要掛上去 | |
| glRotatef( angle, 0, 0, 1);///(2)軸動 | |
| glTranslatef( 0.25 , 0 , 0);///(1)把中心點放在正中間 | |
| drawHand(); | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
| glutCreateWindow("week04"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |
加左上跟左下手肘
>>>>>>>
| #include <GL/glut.h> | |
| float angle = 0; | |
| void drawHand() | |
| { | |
| glPushMatrix(); | |
| glScalef(1,0.3,0.3); | |
| glutSolidCube(0.5); | |
| glPopMatrix(); | |
| } | |
| void display() | |
| { | |
| glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///清背景 | |
| glPushMatrix(); ///右上手臂 | |
| glTranslatef( 0.25 , 0 , 0); ///(3)要掛上去 | |
| glRotatef(angle , 0 , 0 , 1); ///(2)軸動 | |
| glTranslatef( 0.25 , 0 , 0); ///(1)把中心點放在正中間 | |
| drawHand();///右上手臂 | |
| glPushMatrix();///右下手肘 | |
| glTranslatef( 0.25 , 0 , 0);///(3)要掛上去 | |
| glRotatef( angle, 0, 0, 1);///(2)軸動 | |
| glTranslatef( 0.25 , 0 , 0);///(1)把中心點放在正中間 | |
| drawHand();///右下手肘 | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glPushMatrix(); ///左上手臂 | |
| glTranslatef( -0.25 , 0 , 0); ///(3)要掛上去 | |
| glRotatef(angle , 0 , 0 , 1); ///(2)軸動 | |
| glTranslatef( -0.25 , 0 , 0); ///(1)把中心點放在正中間 | |
| drawHand(); ///左上手臂 | |
| glPushMatrix(); ///左下手肘 | |
| glTranslatef( -0.25 , 0 , 0);///(3)要掛上去 | |
| glRotatef( angle, 0, 0, 1);///(2)軸動 | |
| glTranslatef( -0.25 , 0 , 0);///(1)把中心點放在正中間 | |
| drawHand(); ///左下手肘 | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| angle++; | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
| glutCreateWindow("week04"); | |
| glutDisplayFunc(display); | |
| glutIdleFunc(display); | |
| glutMainLoop(); | |
| } |


沒有留言:
張貼留言