gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
按空白鍵,改變拍攝方向
#include <GL/glut.h>
float angleX =0, angle2=0, angle3=0, angle4=0, angle5=0,angle6=0,angle7=0;
float eyeX=0.3 ,eyeY=0.2, eyeZ=0.4, objX=0, objY=0, objZ=0, upX=0, upY=1, upZ=0;
void keyboard(unsigned char key, int x, int y)
{
int i=1;
if(key=='1') angleX+=5;//身體
if(key=='2') angleX-=5;
if(key=='q') angle2+=5;//左手臂
if(key=='w') angle2-=5;
if(key=='e') angle6+=5;//右手臂
if(key=='r') angle6-=5;
if(key=='a') angle3+=5;//左小手臂
if(key=='s') angle3-=5;
if(key=='d') angle7+=5;//右小手臂
if(key=='f') angle7-=5;
if(key=='7') angle4+=5;//左右大腿
if(key=='8') angle4-=5;
if(key=='9') angle5+=5;//左右小腿
if(key=='0') angle5-=5;
if(key==' ')//利用空白鍵改變拍攝方向
{
eyeX-=0.02;eyeY-=0.02;
}
glutPostRedisplay();//請電腦重新畫一次畫面
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.25);
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.25,30,30);
glPopMatrix();
glPushMatrix();//右肩
glTranslatef(0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//右手臂
glRotatef(angle6,0,0,1);
glTranslatef(0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(angle7,0,0,1);
glTranslatef(0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//左手臂
glRotatef(-angle2,0,0,1);
glTranslatef(-0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(-0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(-angle3,0,0,1);
glTranslatef(-0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//右邊大腿
glTranslatef(0.12,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左邊大腿
glTranslatef(-0.1,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glutMainLoop();
}
--------------------------------------------------------------------------
按t,讓機器人旋轉,以及調整邊界使圖不要破洞
#include<math.h>
#include <GL/glut.h>
float angleX =0, angle2=0, angle3=0, angle4=0, angle5=0,angle6=0,angle7=0;
float eyeX=0.3 ,eyeY=0.2, eyeZ=0.4, objX=0, objY=0, objZ=0, upX=0, upY=1, upZ=0;
void timerRotateShow(int t);
void keyboard(unsigned char key, int x, int y)
{
int i=1;
if(key=='1') angleX+=5;//身體
if(key=='2') angleX-=5;
if(key=='q') angle2+=5;//左手臂
if(key=='w') angle2-=5;
if(key=='e') angle6+=5;//右手臂
if(key=='r') angle6-=5;
if(key=='a') angle3+=5;//左小手臂
if(key=='s') angle3-=5;
if(key=='d') angle7+=5;//右小手臂
if(key=='f') angle7-=5;
if(key=='7') angle4+=5;//左右大腿
if(key=='8') angle4-=5;
if(key=='9') angle5+=5;//左右小腿
if(key=='0') angle5-=5;
if(key==' ')
{
eyeX-=0.02;eyeY-=0.02;
}
else if(key=='o')//按o調整邊界
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
}
else if(key=='t')
{
glutTimerFunc(0,timerRotateShow,0);
}
glutPostRedisplay();//請電腦重新畫一次畫面
}
void timerRotateShow(int t)
{
glutTimerFunc(30,timerRotateShow,t+1);
eyeX=cos(t/100.0*3.1415);eyeZ=sin(t/100.0*3.1415);eyeY-=0.005;
glutPostRedisplay();
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };//打光方向
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.25);
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.25,30,30);
glPopMatrix();
glPushMatrix();//右肩
glTranslatef(0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//右手臂
glRotatef(angle6,0,0,1);
glTranslatef(0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(angle7,0,0,1);
glTranslatef(0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//左手臂
glRotatef(-angle2,0,0,1);
glTranslatef(-0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(-0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(-angle3,0,0,1);
glTranslatef(-0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//右邊大腿
glTranslatef(0.12,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左邊大腿
glTranslatef(-0.1,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
按t,讓機器人旋轉,以及調整邊界使圖不要破洞
#include<math.h>
#include <GL/glut.h>
float angleX =0, angle2=0, angle3=0, angle4=0, angle5=0,angle6=0,angle7=0;
float eyeX=0.3 ,eyeY=0.2, eyeZ=0.4, objX=0, objY=0, objZ=0, upX=0, upY=1, upZ=0;
void timerRotateShow(int t);
void keyboard(unsigned char key, int x, int y)
{
int i=1;
if(key=='1') angleX+=5;//身體
if(key=='2') angleX-=5;
if(key=='q') angle2+=5;//左手臂
if(key=='w') angle2-=5;
if(key=='e') angle6+=5;//右手臂
if(key=='r') angle6-=5;
if(key=='a') angle3+=5;//左小手臂
if(key=='s') angle3-=5;
if(key=='d') angle7+=5;//右小手臂
if(key=='f') angle7-=5;
if(key=='7') angle4+=5;//左右大腿
if(key=='8') angle4-=5;
if(key=='9') angle5+=5;//左右小腿
if(key=='0') angle5-=5;
if(key==' ')
{
eyeX-=0.02;eyeY-=0.02;
}
else if(key=='o')//按o調整邊界
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
}
else if(key=='t')
{
glutTimerFunc(0,timerRotateShow,0);
}
glutPostRedisplay();//請電腦重新畫一次畫面
}
void timerRotateShow(int t)
{
glutTimerFunc(30,timerRotateShow,t+1);
eyeX=cos(t/100.0*3.1415);eyeZ=sin(t/100.0*3.1415);eyeY-=0.005;
glutPostRedisplay();
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };//打光方向
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.25);
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.25,30,30);
glPopMatrix();
glPushMatrix();//右肩
glTranslatef(0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//右手臂
glRotatef(angle6,0,0,1);
glTranslatef(0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(angle7,0,0,1);
glTranslatef(0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//左手臂
glRotatef(-angle2,0,0,1);
glTranslatef(-0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(-0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(-angle3,0,0,1);
glTranslatef(-0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//右邊大腿
glTranslatef(0.12,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左邊大腿
glTranslatef(-0.1,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
---------------------------------------------------------------------------------
使他變大及背景變顏色
#include<math.h>
#include <GL/glut.h>
#include<stdlib.h>
float angleX =0, angle2=0, angle3=0, angle4=0, angle5=0,angle6=0,angle7=0;
float eyeX=0.3 ,eyeY=0.2, eyeZ=0.4, objX=0, objY=0.5, objZ=0, upX=0, upY=1, upZ=0;
void timerRotateShow(int t);
void keyboard(unsigned char key, int x, int y)
{
int i=1;
if(key=='1') angleX+=5;//身體
if(key=='2') angleX-=5;
if(key=='q') angle2+=5;//左手臂
if(key=='w') angle2-=5;
if(key=='e') angle6+=5;//右手臂
if(key=='r') angle6-=5;
if(key=='a') angle3+=5;//左小手臂
if(key=='s') angle3-=5;
if(key=='d') angle7+=5;//右小手臂
if(key=='f') angle7-=5;
if(key=='7') angle4+=5;//左右大腿
if(key=='8') angle4-=5;
if(key=='9') angle5+=5;//左右小腿
if(key=='0') angle5-=5;
if(key==' ')
{
eyeX-=0.02;eyeY-=0.02;
}
else if(key=='o')//按o調整邊界
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
}
else if(key=='t')
{
glutTimerFunc(0,timerRotateShow,0);
}
glutPostRedisplay();//請電腦重新畫一次畫面
}
float color=0;
float thesize=1;
void timerRotateShow(int t)//改變背景顏色
{
if(t%30==0)glClearColor((rand()%255)/255.0,(rand()%255)/255.0,(rand()%255)/255.0, (rand()%255)/255.0);
glutTimerFunc(30,timerRotateShow,t+1);
eyeX=cos(t/100.0*3.1415);eyeZ=sin(t/100.0*3.1415);eyeY-=0.005;thesize+=0.01;
glutPostRedisplay();
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };//打光方向
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
glScalef(thesize,thesize,thesize);
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.25);
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.25,30,30);
glPopMatrix();
glPushMatrix();//右肩
glTranslatef(0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//右手臂
glRotatef(angle6,0,0,1);
glTranslatef(0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(angle7,0,0,1);
glTranslatef(0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//左手臂
glRotatef(-angle2,0,0,1);
glTranslatef(-0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(-0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(-angle3,0,0,1);
glTranslatef(-0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//右邊大腿
glTranslatef(0.12,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左邊大腿
glTranslatef(-0.1,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
使他變大及背景變顏色
#include<math.h>
#include <GL/glut.h>
#include<stdlib.h>
float angleX =0, angle2=0, angle3=0, angle4=0, angle5=0,angle6=0,angle7=0;
float eyeX=0.3 ,eyeY=0.2, eyeZ=0.4, objX=0, objY=0.5, objZ=0, upX=0, upY=1, upZ=0;
void timerRotateShow(int t);
void keyboard(unsigned char key, int x, int y)
{
int i=1;
if(key=='1') angleX+=5;//身體
if(key=='2') angleX-=5;
if(key=='q') angle2+=5;//左手臂
if(key=='w') angle2-=5;
if(key=='e') angle6+=5;//右手臂
if(key=='r') angle6-=5;
if(key=='a') angle3+=5;//左小手臂
if(key=='s') angle3-=5;
if(key=='d') angle7+=5;//右小手臂
if(key=='f') angle7-=5;
if(key=='7') angle4+=5;//左右大腿
if(key=='8') angle4-=5;
if(key=='9') angle5+=5;//左右小腿
if(key=='0') angle5-=5;
if(key==' ')
{
eyeX-=0.02;eyeY-=0.02;
}
else if(key=='o')//按o調整邊界
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
}
else if(key=='t')
{
glutTimerFunc(0,timerRotateShow,0);
}
glutPostRedisplay();//請電腦重新畫一次畫面
}
float color=0;
float thesize=1;
void timerRotateShow(int t)//改變背景顏色
{
if(t%30==0)glClearColor((rand()%255)/255.0,(rand()%255)/255.0,(rand()%255)/255.0, (rand()%255)/255.0);
glutTimerFunc(30,timerRotateShow,t+1);
eyeX=cos(t/100.0*3.1415);eyeZ=sin(t/100.0*3.1415);eyeY-=0.005;thesize+=0.01;
glutPostRedisplay();
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };//打光方向
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, upX, upY, upZ);
glScalef(thesize,thesize,thesize);
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.25);
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.25,30,30);
glPopMatrix();
glPushMatrix();//右肩
glTranslatef(0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//右手臂
glRotatef(angle6,0,0,1);
glTranslatef(0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(angle7,0,0,1);
glTranslatef(0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.4,0,0);
glutSolidSphere(0.12,30,30);
glPushMatrix();//左手臂
glRotatef(-angle2,0,0,1);
glTranslatef(-0.18,0,0);
glScalef(0.2,0.2,0.2);
glutSolidCube(1);
glPushMatrix();
glTranslatef(-0.95,0,0);
glutSolidSphere(0.5,30,30);
glPushMatrix();
glRotatef(-angle3,0,0,1);
glTranslatef(-0.9,0,0);
glScalef(1,0.8,0.8);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//右邊大腿
glTranslatef(0.12,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//左邊大腿
glTranslatef(-0.1,-0.1,0);
glRotatef(angle4,1,0,0);
glTranslatef(0,-0.25,0);
glPushMatrix();
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//
glTranslatef(0,-0.24,0);
glutSolidSphere(0.1,30,30);
glPushMatrix();
glRotatef(angle5,1,0,0);
glTranslatef(0,-0.24,0);
glScalef(0.18,0.3,0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);//左右 上下 前後(邊界) 設大一點才不會破圖
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
沒有留言:
張貼留言