View Full Version : Display lists and glLoadIdentity();

10-11-2002, 07:30 PM
The way I'm generating maps in my v. simple space flying game is to have a parametric function trace out points and to generate toruses (tori? http://www.opengl.org/discussion_boards/ubb/smile.gif. Another function returns the tangent vector at any given point on the parametric curve so that I can align the tori with it.

* Handles the generation of game
* levels based upon any parametric
* function.
public void genLevel()
for(float t = 0; t <= 2*M_PI; t += (2*M_PI / 8))
Vector2 v = cqLevelOneFunc(t);
float x = v.getx();
float z = v.gety();

// Calculate the amount to rotate each torus by
// so they are parallel to the tangent vector.
float rotateBy = 0.0f;
Vector3 forward = new Vector3(0,0,1); // Vector pointing along z-axis.
Vector3 tangVector = cqLevelOneTangent(t); // Tangent vector at this t value.
float dot = gameUtils.dot(forward, tangVector); // Calculate dot product.
// Calculate theta.
float cos = dot / (gameUtils.length(forward) * gameUtils.length(tangVector));
float theta = (float) Math.toDegrees(Math.acos(cos));

Torus tor = new Torus(this,x * 20,0,-z * 20,theta,0,1,0);
gl.glLoadIdentity(); //Where should this go? level.add(tor);

Torus(translate_x, translate_y, translate_z, rotation_amount, rotVectorx, rotVectory, rotVectorz) returns a Torus object conatining a new display list rotated and translated by the specified amounts and about the specified vector.

Now this worked fine until I started trying to rotate each torus by the calculated theta and translating, instead of just translating. I think I need a glLoadIdentity() *somwhere* because it the glRotatatef() commands used by each Torus object are compounding. But it seems that no matter where I place the glLoadIdentity() things look very screwy.