# Rotation and translation like in GTA 1 OpenGL

Okay, so I have a figure in XZ plain. I want to move it forward/backward and rotate at it's own Y axis, then move forward again in the rotation's direction, like the character in GTA 1.

Code so far:

Init:
spaceship_position = glm::vec3(0,0,0);
spaceship_rotation = glm::vec3(0,0,0);
spaceship_scale = glm::vec3(1, 1, 1);

Draw:
glm::mat4 transform = glm::scale<float>(spaceship_scale) *
glm::rotate<float>(spaceship_rotation.x, 1, 0, 0) *
glm::rotate<float>(spaceship_rotation.y, 0, 1, 0) *
glm::rotate<float>(spaceship_rotation.z, 0, 0, 1) *
glm::translate<float>(spaceship_position);
drawMesh(spaceship, texture, transform);
Update:
switch (key.keysym.sym) {
case SDLK_UP:
spaceship_position.z += 0.1;
break;
case SDLK_DOWN:
spaceship_position.z -= 0.1;
break;
case SDLK_LEFT:
spaceship_rotation.y += 1;
break;
case SDLK_RIGHT:
spaceship_rotation.y -= 1;
break;
}


So this only moves on the Z axis, but how can I move the object on both Z and X axis where the object is facing?

• It would be useful to actually state the problem that you are facing though. – radical Nov 10 '13 at 11:10
• You may want to check out this site: engineeringdotnet.blogspot.co.uk/2010/04/… It describes very basic physics of steering a car (or model in your case). If you solve it, please update your code above or answer your own question below – Reanimation Nov 10 '13 at 16:21

transform = rot * trans