1.Translate:
code:
#include <GL/glut.h>
float mouseX=0 , mouseY=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(mouseX,mouseY,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("guoyu");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
2.Scale
code中加入glScalef(mouseX,mouseY,0);
沒有留言:
張貼留言