(1) 主題:旋轉Rotate
(2)主題: 移動Translate
(3)主題: 縮放 Scale
先畫一個茶壺, 這裡不多介紹。接著更改一些程式可以移動茶壺
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.5,0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion (int x, int y)
{
mouseX = (x-150)/ 150.0 ;
mouseY = -(y-150)/ 150.0;
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04162646 GGGGGGGGGGG");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
///glutMotionFunc(motion);
glutMainLoop();
}
void motion (int x, int y)
{
mouseX = (x-150)/ 150.0 ;
mouseY = -(y-150)/ 150.0;
glutPostRedisplay();
}
圖片支援
這樣就可以移動茶壺了
若將glTranslatef();更改為glScalef(); 茶壺就可以放大縮小了。
後面的f為float的表示。


沒有留言:
張貼留言