Okay I got it to work. The idea here is to use a 6 element float array to represent the current state of an object, which I'm using a cube (eight sides!), not a spaceship:
Code:
typedef struct {
float x;
float y;
float z;
float xR;
float yR;
float zR;
} Thing;
Thing Cube={0.0f} /* we begin at the origin */
I have two functions to deal with Cube, both of which get called in my glutDisplayFunc() if you want to learn with glut. Anyway, the second one builds a cube, bells, whistles, textures, rocket launchers, what have you, using the Cube coordinates. The first one is what's important here, because it controls the position of the cube:
Code:
void movecube () { /* think borg ;) */
float trix[16];
glPushMatrix(); /* reserve current state */
glTranslatef(Cube.x,Cube.y,Cube.z); /* move to */
glRotatef(Cube.xR, 1.0f, 0.0f, 0.0f); /* where we */
glRotatef(Cube.yR, 0.0f, 1.0f, 0.0f); /* should be */
glRotatef(Cube.zR, 0.0f, 0.0f, 1.0f); /* INCLUDE ROTATION */
glTranslatef(0.0f,0.0f,0.5f); /* now move FORWARD slowly... */
glGetFloatv(GL_MODELVIEW_MATRIX,trix);
Cube.x=trix[12]; /* this saves the new position of the Cube */
Cube.y=trix[13];
Cube.z=trix[14];
glPopMatrix(); /* restore state (IMPORTANT) */
}
Like I said, this gets called before the routine which uses the Cube.elements to draw the cube in the right place.
You control the xR, yR, zR with arrow keys + pgup/pgdown (glut handles this mostly). You have no choice about the acceleration, it is constant (nice simple demo), but it is relative to the cube; ie, it always moves front face forward, so you can steer it around all three dimensions (and notice, the forward is always because of a Z translation, just what you wanted!!).
So it works fine. I can keep it spiralling around the viewport perpetually, but of course steering an object you are watching from the ground is tricky (get the camera to follow: next step). Sorry there are no quaternions.
ps. That is some crazy C++ tish found by the OP! I thot it was supposed to be better! "Object oriented" AHAHAHA!!