week15
第一步
去https://jsyeh.org/3dcg10/下載window跟 data
把data放入windows
開啟projection
開始測試
*改變up
安裝git
安裝git並打開git bash
開新的glut專案
把檔案放到桌面的2023graphicsb
使用之前的freeglut
了解LookAt
week15-1
...
float eyeX = 0, eyeY = 0;
void motion(int x, int y){
eyeX = 3*(x-320)/320.0;
eyeY = 3*(240-y)/240.0;
glLoadIdentity();
gluLookAt(eyeX, eyeY, 3, 0, 0, -6, 0, 1, 0);
glutPostOverlayRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutMotionFunc(motion);
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
...
投影
week15-2
測試
1.臺狀投影glFrustum()
2.垂直投影glOriho()
3.透視投影gluPerspective
...
static void resize(int width, int height)
{ ///aspective ratio長寬比
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);///切換成投影矩陣
glLoadIdentity();
///glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
///glOrtho(-ar*3, ar*3, -1.0*3, 1.0*3, 2.0, 100.0);
gluPerspective(60, ar, 0.01, 1000);
glMatrixMode(GL_MODELVIEW);///切換到model view 矩陣
glLoadIdentity() ;///設成單位矩陣
}
...
week15-3
透視投影
#include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void motion(int x, int y){
glLoadIdentity();
float eyeX = (x-150)/150.0, eyeY = (150-y)/150.0;
gluLookAt(eyeX, eyeY, 1, 0, 0, 0, 0, 1, 0);
glutPostOverlayRedisplay();
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
week15-4
#include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void motion(int x, int y){
glLoadIdentity();
float eyeX = (x-150)/150.0, eyeY = (150-y)/150.0;
gluLookAt(eyeX, eyeY, 1, 0, 0, 0, 0, 1, 0);
glutPostOverlayRedisplay();
}
void reshape(int w, int h){
float ar = w / (float) h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, ar, 0.01, 1000);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15");
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}











沒有留言:
張貼留言