是為了讓我們的XY軸變得更大、不在侷限在-1~1之間
首先運鏡的語法是:
gluLookAt(eye x,y,z
center x,y,z
up x,y,z);
這就是讓我們可以運鏡的與摟
第一節課就是讓大家try看看,小葉老師利用一個傳奇學長做的遊戲王遊戲當作運鏡的例子
第二節課我們就開始認真實作瞜,首先我們依照慣例利用茶壺當作這次矩正大小的的例子
#include <GL/glut.h>
{
glPushMatrix();
glutSolidTeapot(50);//改變圖案大小
glPopMatrix();
glFlush();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitWindowSize(800,600);//改變場景大小
glutCreateWindow("3D");
glutDisplayFunc(display);
glViewport(0,0, 800,600);
glMatrixMode(GL_PROJECTION);
glOrtho(-400,400,-300,300,1000,-1000);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
part2>
#include <GL/glut.h>
void display()
{
glPushMatrix();
glutSolidTeapot(50);//改變圖案大小
glPopMatrix();
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glOrtho(-w/2,w/2, -h/2,h/2,-1000,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitWindowSize(800,600);//改變場景大小
glutCreateWindow("3D");
glutDisplayFunc(display);
glViewport(0,0, 800,600);
glMatrixMode(GL_PROJECTION);
glOrtho(-400,400,-300,300,1000,-1000);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
紅字是新增的語法,是讓圖案不會因為視窗放大縮小而改變其圖案的比例
EX:放大後茶壺不會變胖胖的
第三節課
讓原本無聊平面的茶壺加上光和運鏡
使整個茶壺變得更精緻
#include <GL/glut.h>
成品是
第三節課
讓原本無聊平面的茶壺加上光和運鏡
使整個茶壺變得更精緻
#include <GL/glut.h>
float eyeX=-100,eyeY=80,eyeZ=-200;
void display()
{
GLfloat pos[]={0,0,200,0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX,eyeY,eyeZ,0,0,0, 0,1,0);
glPushMatrix();
glutSolidTeapot(100);
glPopMatrix();
glPopMatrix();
glFlush();
}
void motion(int x,int y)
{
eyeX=x-400;eyeY=300-y;
glutPostRedisplay();
}
void reshape(int w,int h) ///寫reshape使改變視窗大小,也不會讓茶壺變形!
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90,w/h,0.001,10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void timer(int t)
{
glutTimerFunc(20,timer,t+1);
eyeX+=2;
if(eyeX>300) eyeX+=4;
glutPostRedisplay();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitWindowSize(800,600);
glutCreateWindow("3D");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMainLoop();
} 成品是
最後加上音樂檔 就完成瞜~~
沒有留言:
張貼留言