Skip to main content
gamedev.net
🔒 Locked

rotating matrix

Started by teslaa66 1 reply 700+ views
Original Post
teslaa66
teslaa66
Is there a way i can make a matrix

float newMatrix[16];
apply a rotation of 10 degrees on the X axis and 60 degrees on the Z axis but simulataneously so it doesnt rotate an already rotated matrix? then load the matrix before a model in my scene

glLoadMatrixf(newMatrix);
So now i can perform two rotations without one rotation rotating an already rotated scene? If this is all possible how do i apply a rotation of 10 degrees on the X axis and 60 degrees on the Z axis of a matrix please?
Graz
Graz
See this page. About half way down, there's an explanation of how to create a 4x4 matrix representing compound rotations.

However, unless you really need this matrix for some reason, I'd suggest using glLoadIdentity and glRotatef to build the matrix on-the-fly. It will produce the same result as calling glLoadMatrix but will make your code a little easier to read.

Also, if you want to transform already positioned objects, try using glMultMatrix or omitting glLoadIdentity.
teslaa66
teslaa66
probably be easier if i show u my display

  glLoadMatrixf(carMatrix); //Loads Car Matrix  glTranslatef(0,0,9.03+carHeight); //Translates the car to the correct height  glScalef(0.035,0.025,0.023); //Scales the car to the right side  glBindTexture(GL_TEXTURE_2D, texture[5]); //Textures the car  glRotatef(carRoll, 1, 0, 0); //Rolls the car  glRotatef(carPitch, 0, 1, 0); //Effects the pitch of the car  rendermd2(car); //Renders the car



Here if i effect the roll of the car then applying the pitch doesnt pitch the car it pitches the already rolled car.

If i apply a glLoadIdentity after the first rotate then the car loses the scale and translate as well as the first rotate. Any ideas?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.