Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TonyFish

OGL Matrix confusion

This topic is 5483 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

Hi, I'm a bit confused as to the ordering of matrices in opengl. I wrote a simple matrix class and am testing it out on the following code (which is a simple convertion of a NeHe project which simply displays three triangles). Here it is.
void Application::DrawTestB(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	Matrix4x4 s_Identity(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);
	glLoadMatrixf(s_Identity.m_fMatrix);
	Matrix4x4 s_FirstTranslation(1,0,0,0,0,1,0,0,0,0,1,0,0,0,-6,1);
	glMultMatrixf(s_FirstTranslation.m_fMatrix);

		glColor3ub(0,0,255);
		DrawTestTriangle(0,0,0,1,1);

		Matrix4x4 s_Translation1(1,0,0,0,0,1,0,0,0,0,1,0,1,0,-1,1);
		glMultMatrixf(s_Translation1.m_fMatrix);

			glColor3ub(0,255,0);
			DrawTestTriangle(0,0,0,1,1);

		glLoadMatrixf(s_FirstTranslation.m_fMatrix);

		Matrix4x4 s_Translation2(1,0,0,0,0,1,0,0,0,0,1,0,-1,0,-1,1);
		glMultMatrixf(s_Translation2.m_fMatrix);

			glColor3ub(255,0,0);
			DrawTestTriangle(0,0,0,1,1);

		glLoadMatrixf(s_FirstTranslation.m_fMatrix);

	glLoadMatrixf(s_Identity.m_fMatrix);
}
Now my problem is that this code works! It shouldn't! My matrix class is in row major format (using a 1D float array). As I haven't written an OGL matrix passing method yet, I should transpose all the matrices before passing them to OGL functions to work. This is because OGL is in column major format. But somehow it works fine without. I can't understand it. Here is the constructor for my matrix class, maybe you can see what's happening:
   
	Matrix4x4(float p_fM00=0,float p_fM01=0,float p_fM02=0,float p_fM03=0,
			  float p_fM10=0,float p_fM11=0,float p_fM12=0,float p_fM13=0,
			  float p_fM20=0,float p_fM21=0,float p_fM22=0,float p_fM23=0,	
			  float p_fM30=0,float p_fM31=0,float p_fM32=0,float p_fM33=0)
	{
		m_fMatrix[0] =p_fM00; m_fMatrix[1] =p_fM01; m_fMatrix[2] =p_fM02; m_fMatrix[3] =p_fM03;
		m_fMatrix[4] =p_fM10; m_fMatrix[5] =p_fM11; m_fMatrix[6] =p_fM12; m_fMatrix[7] =p_fM13;
		m_fMatrix[8] =p_fM20; m_fMatrix[9] =p_fM21; m_fMatrix[10]=p_fM22; m_fMatrix[11]=p_fM23;
		m_fMatrix[12]=p_fM30; m_fMatrix[13]=p_fM31; m_fMatrix[14]=p_fM32; m_fMatrix[15]=p_fM33;
	}
Many Thanks Anthony [edited by - TonyFish on August 18, 2003 9:48:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
Don''t forget OpenGL defines translation matrix:


( 1 0 0 x )
( 0 1 0 y )
( 0 0 1 z )
( 0 0 0 1 )


And you are specifying the transpose of that, which when passed to OGL is data-transposed and is correct.. er.. hehe

Share this post


Link to post
Share on other sites
oh duh stupid me...
Phew at least that means I don''t have to worry about my matrix class anymore!
Thanks



<Fish>{

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!