💻電腦圖學💻
本日主題:移動、旋轉、放大縮小
電腦圖學 Week04 2021-03-151. 主題: 移動、旋轉、放大縮小2. glTranslatef(x, y, z);3. glRotatef( angle, x, y, z);4. glScalef(x, y, z);5. 主題: mouse motion函式
#include <GL/glut.h>#include <stdio.h>void display(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glEnd();glutSwapBuffers();///交換兩倍的buffers}void mouse(int button,int state,int x,int y){printf("button:%d state:%d x:%d y:%d\n",button,state,x,y);if(state==GLUT_DOWN){/printf("glVertex3f((%d-150)/150.0,-(%d-150)/150.0,0);\n",x,y);}}int main(int argc,char ** argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);glutCreateWindow("08160201賣女孩的小火柴");///開啟視窗glutDisplayFunc(display);///顯示的函示glutMouseFunc(mouse);glutMainLoop();///主要迴圈}
#include <GL/glut.h>#include <stdio.h>float teapotX=0,teapotY=0;void display(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslatef(teapotX,teapotY,0);glutSolidTeapot(0.3);glPopMatrix();glEnd();glutSwapBuffers();///交換兩倍的buffers}void motion(int x,int y){teapotX=(x-150)/150.0;teapotY=-(y-150)/150.0;display();}int main(int argc,char ** argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);glutCreateWindow("08160201賣女孩的小火柴");///開啟視窗glutDisplayFunc(display);///顯示的函示glutMotionFunc(motion);glutMainLoop();///主要迴圈}
glTranslatef(0.00, 0.00, 0.00);改變物體的 ( X , Y , Z )
glRptatef (0.0,1.00,0.00,0.00);
改變物體旋轉方向
旋轉可用右手定律了解旋轉的方向
glRptatef (0.0,1.00,0.00,0.00);
開始旋轉
glRptatef (0.0,1.00,0.00,0.00);
glRptatef (0.0,1.00,0.00,0.00);







沒有留言:
張貼留言