- Before Roatate or Translate a object, having to push matrix to stack, and after this, pop it.
glPushMatrix(), glPopMatrix()
/*
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; //Get ELAPSED_TIME
const double a = t*90.0;
glPushMatrix() //Push current matrix to stack.
glTranslated(-2.4,-1.2,-6); //Move the object, the end 'd' mean 'double' type. glTranslatef() work the same with this.
glRotated(60,1,0,0); //Rotate the object ; argument = (angle, x, y, z) rotate.
glRotated(a,1,0,0); //Add time variable to rotate as time goes.
glScaled(3,3,3); //Scale object
glutWireSphere(1,slices,stacks); //Add object
glPopMatrix(); //Pop current matrix .
*/
- Resize
glFrustum()
- Mouse Control
In main(): glutMouseFunc(mouse) and glutMotionFunc(motion) add function to control with mouse.
And add two fuctions below.
float dx,dy,dz;
int oldX, oldY,oldZ;
void motion(int x, int y)
{
dx +=(x-oldX)/150.0; //At the previous point, add the displacement.
dy += -(y-oldY)/150.0;
oldX = x;
oldY = y;
glutPostRedisplay(); //Redraw display.
}
- - -
void mouse(int button, int state, int x, int y)
{
if(state == GLUT_DOWN) //When mouse down, update oldX, oldY
{
oldX = x;
oldY = y;
}
}
沒有留言:
張貼留言