功課1
網址:jsyeh/3dcg10/
下載[data][win32][glut32.dill]
開啟Transformation
glTranslatef 移動
glRotatef 旋轉
glScalef 縮放
程式由下往上跑
A) 以車子為中心點移動
先放大
旋轉
再移動
glBegin => glScalef => glTranslatef => glRotatef
B) 右鍵Swap translate/rotate
以鍋子為中心點來旋轉
放大又移動
再旋轉
功課2
茶壺上下左右旋轉
程式碼:
#include <GL/glut.h>
float rotX=0;
float rotY=0;
void motion(int x,int y)
{
rotX=x;
rotY=y;
}
void display()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,0,1,0); ///旋轉 角度rotX, 軸(0,1,0) y軸
glRotatef(rotY,1,0,0); ///旋轉 角度rotY, 軸(1,0,0) x軸
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DEPTH);
glutInitWindowSize(500,500); //視窗大小
glutInitWindowPosition(700,0); //視窗開啟位置
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}







沒有留言:
張貼留言