到https://jsyeh.org/3dcg10/ 下載win32及data,將data資料夾放到windows資料夾,打開projection.exe,
glPerspective:調整投影機大小位置
eye:從哪裡看
center:看哪裡
up:順時針轉動
fovy(fov):視野範圍
將glFrustum改成glOrtho
控制看茶壺的鏡頭
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void reshape(int w,int h){
glViewport(0,0,w,h);///視窗裡,會看到2D範圍
float ar =w/(float) h;///aspect ratio長寬比
glMatrixMode(GL_PROJECTION);///先切換到Project矩陣
glLoadIdentity();
gluPerspective(60,ar,0.01,1000);///
glMatrixMode(GL_MODELVIEW);///做好後馬上切回model view矩陣
glLoadIdentity();///矩陣清空,成為單位矩陣
gluLookAt(0,0,1, 0,0,0, 0,1,0);
///在0,0,1看著茶壺0,0,0,up是,0,1,0
glutPostRedisplay();
}
float eyeX=0, eyeY=0;
void motion(int x, int y){
eyeX=(x-150.0)/150.0;
eyeY=(150.0-y)/150.0;
glMatrixMode(GL_MODELVIEW);///做好後馬上切回modelview矩陣
glLoadIdentity();///矩陣清空,成為單位矩陣
gluLookAt(eyeX,eyeY,1, 0,0,0, 0,1,0);
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}



沒有留言:
張貼留言