Well, I was able to do something close to what you listed, but I’m not sure if it’s correct cause I don’t quite understand it (and it’s not what’s listed above, no pushing, popping).
I think I’m trying to do a fixed coordinate system. So I’m thinking of multiplication occuring in the opposite order that the code is listed (chpt. 3 of the red book). All I did was add the glTranslates you had and changed each sign.
But I don’t understand why I translate to the + centroid, apply my arcball rotation, then translate back to the - centroid, which I think is back at the origin since I think this is a fixed coord system. Or would be w/o the second translate. I’m just confused. And what exactly would the push and pop do if I only draw one model? I don’t have methods that draw different parts of the model in different locations like the car, wheel and lugnuts example in the redbook. I just have vertex arrays populated from coords from an input file and draw the entire thing at once.
What I have below works, but … I don’t think it’s what I wanted, or if it’s what was intended. I found out that by doing this, I no longer need a viewing tranformation (or point my camera at the centroid of the model since we’re moving the model to the origin).
Any advice or comments on below would be great.
// my display()
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Projection transformation.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-winWidth, winWidth, -winHeight, winHeight, 1000, -1000);
// Reset the modelview matrix.
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
// Modeling tranformation.
gl.glTranslatef((float) centroid.getX(), (float) centroid.getY(), (float) centroid.getZ());
gl.glScalef(getZoomFactor(), getZoomFactor(), getZoomFactor());
arcBall.getTransform().get(transf);
gl.glMultMatrixf(transf);
gl.glTranslatef((float) -centroid.getX(), (float) -centroid.getY(), (float) -centroid.getZ());
// Draw the model.
drawModel(drawable);