#Week10
- week10-1_glutWireCube_mybody_myArm
- 安裝freeglut,把lib\libfreeglut.a複製成libglut32.a
- File-New-Project, GLUT專案 week10-1_glutWireCube_mybody_myArm
- 貼上上周的week09-3_glutWireTeapot_glutWireCube_glutWireSphere的程式碼
.png)
- 要把void display()改寫一下,呼叫myBody() myArm()
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- myArm();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week09 Microsoft Visual Studio");
- glutDisplayFunc(display);
- glutMainLoop();
- }
- week10-2_rotate_myArm
- File-New-Project, GLUT專案week10-2_rotate_myArm
- 貼上week10-1_glutWireCube_mybody_myArm的程式
- 外面加上float angle=0;
- 在main()加上glutIdleFunc(display);
- 在display()裡,myArm()的前後,加上glPushMatrix(); glPopMatrix(); glRotatef(angle++,0,0,1);
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glRotatef(angle++,0,0,1);
- myArm();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week09 Microsoft Visual Studio");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-3_rotate_translate_myArm
- File-New-Project, GLUT專案week10-3_rotate_translate_myArm
- 貼上week10-2_rotate_myArm的程式
- 加上glTranslatef(0.15,0,0);
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week09 Microsoft Visual Studio");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-4_translate_rotate_translate_myArm
- File-New-Project, GLUT專案week10-4_translate_rotate_translate_myArm
- 貼上week10-3_rotate_translate_myArm的程式
- 加上最後一行glTranslatef(0.3,0.3,0);放最上面 掛上去
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10-4_translate_rotate_translate_myArm");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-5_TRT_TRT_myArm
- File-New-Project, GLUT專案week10-5_TRT_TRT_myArm
- 貼上week10-4_translate_rotate_translate_myArm的程式
- 把整套glPushMatrix(); glTranslatef(); glRotatef(); glTranslatef(); myArm(); glPopMatrix();
要插在中間 - 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(0.15,0.3,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10-4_translate_rotate_translate_myArm");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-6_left_right_myArm
- File-New-Project, GLUT專案week10-6_left_right_myArm
- 貼上week10-5_TRT_TRT_myArm的程式
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(0.15,0,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,0.3,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(-0.15,0,0);
- glRotatef(angle++,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10-4_translate_rotate_translate_myArm");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-7_mouse_motion_angle_myArm
- File-New-Project, GLUT專案week10-7_mouse_motion_angle_myArm
- 貼上week10-6_left_right_myArm的程式
- 想要用mouse motion來操控,所以angle++ 都改成angle(不要++)
- 在main()加glutMotionFunc(motion);
- 加一個void motion(int x,int y)函式
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(0.15,0,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,0.3,0);
- glRotatef(angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(-0.15,0,0);
- glRotatef(angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- void motion(int x,int y){
- angle=x;
- glutPostRedisplay();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10");
- glutDisplayFunc(display);
- glutMotionFunc(motion);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-8_mouse_motion_angle_2_myArm
- File-New-Project, GLUT專案week10-8_mouse_motion_angle_2_myArm
- 貼上week10-7_mouse_motion_angle_myArm的程式
- 把display()裡面的 左邊的angle改成 -angle(讓左右的角度,向負相反)
- 程式碼:
- #include <GL/glut.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(0.15,0,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,0.3,0);
- glRotatef(-angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(-0.15,0,0);
- glRotatef(-angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- void motion(int x,int y){
- angle=x;
- glutPostRedisplay();
- }
- int main(int argc, char*argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10");
- glutDisplayFunc(display);
- glutMotionFunc(motion);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week10-9_PlaySound
- File-New-Project, GLUT專案week10-9_PlaySound
- 貼上week10-8_mouse_motion_angle_2_myArm的程式
- 在#include 的地方,加上 #include <mmsystem.h>
- 在main()的第1行,加入PlaySound("你的wav檔.wav",NULL,SND_ASYNC)
- 把老師的horse.wav放在 C:跟目錄裡
- 程式碼:
- #include <GL/glut.h>
- #include <mmsystem.h>
- void myBody()
- {
- glPushMatrix();
- glColor3f(1,0,0);
- glutWireCube(0.6);///myBody()
- glPopMatrix();
- }
- void myArm()
- {
- glPushMatrix();
- glColor3f(0,1,0);
- glScalef(1,0.4,0.4);
- glutWireCube(0.3);///myBody()
- glPopMatrix();
- }
- float angle=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- myBody();
- glPushMatrix();
- glTranslatef(0.3,0.3,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(0.15,0,0);
- glRotatef(angle,0,0,1);
- glTranslatef(0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,0.3,0);
- glRotatef(-angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPushMatrix();
- glTranslatef(-0.15,0,0);
- glRotatef(-angle,0,0,1);
- glTranslatef(-0.15,0,0);
- myArm();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- void motion(int x,int y){
- angle=x;
- glutPostRedisplay();
- }
- int main(int argc, char*argv[])
- {
- PlaySound("C://horse.wav",NULL,SND_ASYNC);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("week10");
- glutDisplayFunc(display);
- glutMotionFunc(motion);
- glutIdleFunc(display);
- glutMainLoop();
- }
.png)
.png)
沒有留言:
張貼留言