(1)移動Translate
glTranslatef(mouseX,mouseY,0);
茶壺像飛起來一樣好QQQQQ
(2)旋轉 Rotate
glRotatef(rotX,0,0,1);
(3)縮放Scale
讓他會放大縮小
glScalef(mouseX,mouseY,0);
(3.5)今天的程式碼
#include <GL/glut.h>
float mouseX=0,mouseY=0,rotX=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
// glScalef(mouseX,mouseY,0);
//glTranslatef(mouseX,mouseY,0);
glRotatef(rotX,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y){
mouseX =(x-150)/150.0;
mouseY =-(y-150)/150.0;
rotX = x;
glutPostRedisplay();
}
int main( int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("04160303 translate rotate scale");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
(5)
設定y軸的時候往右+往左-
設定x軸的時候+的俯視-的仰視
設定y軸的時候+右邊往上轉-左邊往上轉
沒有留言:
張貼留言