2015 電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2015年5月20日 星期三
02160704 王庭翊
今天做出了跟一開始上課開出的程式一樣東西,覺得蠻有成就感的
#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)
{
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("3D");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutTimerFunc(0,timer,0);
glViewport(0,0,800,600);
glMatrixMode(GL_PROJECTION);
glOrtho(-400,400,-300,300,-1000,1000);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言