2014 電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2014年4月24日 星期四
week10
#include <Gl/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0;
float angleX=0,startX=0;
void keyboard(unsigned char key, int x, int y)
{
printf("%c %d %d\n",key, x, y);
if(key=='a' || key=='A') teapotX+=0.1;
if(key=='b' || key=='B') teapotX-=0.1;
if(key=='c' || key=='C') teapotY+=0.1;
if(key=='d' || key=='D') teapotY-=0.1;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button ,state ,x ,y);
}
void motion(int x, int y)
{
printf("%d %d\n", x, y);
angleX+=(x-startX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
glRotatef(angleX,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
訂閱:
張貼留言 (Atom)


沒有留言:
張貼留言