Say I want to draw a Ball in the scene and here are two different ways to do them.
float SUN_TRANSLATION_MATRIX[] = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, -15.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
void displaySolarSystem1(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -15.f);
glColor3f(1.0f, 0.8f, 0.5f);
glutSolidSphere(2.0, 50, 40);
glutSwapBuffers();
}
void displaySolarSystem(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(SUN_TRANSLATION_MATRIX);
glColor3f(1.0f, 0.8f, 0.5f);
glutSolidSphere(2.0, 50, 40);
glutSwapBuffers();
}
displaySolarSystem1 applies glTranslatef where displaySolarSystem uses Matrix operation the problem is that displaySolarSystem1 works as expected but the matrix failed.
What went wrong with displaySolarSystem()?