Jump to content
  • Advertisement
Sign in to follow this  
webwraith

matrices with glLoadMatrix()

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using matrices to set my objects and camera, but when I create a 4x4 matrix and apply the translation and the 3x3 rotational matrix, I end up translating the camera before it rotates. Obviously, this isn't helpful when I need a FPS-like camera. How would I set up my matrix/matrices to translate after rotating?

Share this post


Link to post
Share on other sites
Advertisement
Which would be great, but if the translation is only applied to three values in the matrix it wouldn't make a difference what order I apply the translation in.

Share this post


Link to post
Share on other sites
Then you are not properly applying the transformations. Applying translation is not about changing three values in a matrix, you create a translation matrix and multiply it with the other matrix.

Share this post


Link to post
Share on other sites
The function I came up with is;

template < class _type >
void TranslateM( basic_matrix < _type, 4, 4 >& tmat, basic_vector < _type, 3 > tvec )
{
basic_matrix < _type, 4, 4 > trans;
sw_math::LoadIdentityM(trans);
trans(12) += tvec(0);
trans(13) += tvec(1);
trans(14) += tvec(2);
tmat = tmat*trans;
}



My matrix class uses a 1D array for the elements, which are considered to be in column order. Both vector and matrix classes (as shown) use overloaded parenthesis for element access, with the matrix overloading this to allow access in (row,column) convention.

Is this the right method to translate a matrix?

Share this post


Link to post
Share on other sites
Quote:
Original post by webwraith
Is this the right method to translate a matrix?
Ja, that looks reasonable, although I can't comment on the order of multiplication.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!