忙到凌晨
很累很累 但還是準時來上課
也加了分 很開心
(1)投影矩陣
{Ortho 垂直 & Perspecfive 透視}
(2)攝影機,運鏡
(3)播放MP3
TODAY:
(1)看jsyeh/3dcg10
下載Viewing in 3D
PDF檔
(2)課本範例 Projection.exe
gluLookAt(eyex,eyey,eyez 運鏡 ,眼睛從哪裡
centerx,centery,centerz , 看哪裡
upx,upy,upz) , 上面在哪裡
#include <GL/glut.h>
void display()
{
glPushMatrix();
glutSolidTeapot(100);
glPopMatrix();
glFlush();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitWindowSize(800,600);
glutCreateWindow("02160562 PAN");
glutDisplayFunc(display);
///glutReshapeFunc(reshape);
glViewport(0,0, 800,600);
glMatrixMode(GL_PROJECTION);
glOrtho(-400,400, -300,300, -1000,1000);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
將茶壺都會在畫面置中
#include <GL/glut.h>
void display()
{
glPushMatrix();
glutSolidTeapot(100);
glPopMatrix();
glFlush();
}
void reshape(int w,int h) //置中
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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("02160562 PAN");
glutDisplayFunc(display);
///glutReshapeFunc(reshape);
glViewport(0,0, 800,600);
glMatrixMode(GL_PROJECTION);
glOrtho(-400,400, -300,300, -1000,1000);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
可拉視角
#include <GL/glut.h>
float eyeX=0,eyeY,eyeZ=-200;
void display()
{
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) //置中
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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("02160562 PAN");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMainLoop();
}
打光
#include <GL/glut.h>float eyeX=0,eyeY,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) //置中
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w/2,w/2, -h/2,h/2, -1000,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void timer(int t)
{
glutTimerFunc(20,timer,t+1);
eyeX+=2;
if(eyeX>300) eyeY+=4;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitWindowSize(800,600);
glutCreateWindow("02160562 PAN");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMainLoop();
}
MP3
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI MyMP3;
float eyeX=0,eyeY,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) //置中
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w/2,w/2, -h/2,h/2, -1000,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void timer(int t)
{
glutTimerFunc(20,timer,t+1);
eyeX+=2;
if(eyeX>300) eyeY+=4;
glutPostRedisplay();
}
void keyboard(unsigned char key,int x,int y)
{
MyMP3.Play();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitWindowSize(800,600);
glutCreateWindow("02160562 PAN");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutTimerFunc(0,timer,0);
glutKeyboardFunc(keyboard);
MyMP3.Load("music.mp3");
glutMainLoop();
}
沒有留言:
張貼留言