Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 26 Oct 2003
Offline Last Active Apr 22 2012 01:36 PM

Topics I've Started

Another Matrix Order Question :)

13 April 2012 - 10:04 AM

I'm trying to get my head around row/column major matrices and row/column vectors. Mostly, I'm using the following for reference:

So, trying to write a 4x4 matrix class, I have a class with an array of values:

float m_Values[16];

Now, I'm going to be using column vectors, so:

1) Am I right in saying the following:

Multiplication should be written like so: Matrix * Vector
Combining rotation matrices should be written (for example): Projection * View * World

2) Row/Column major matrices refers to the order the data is stored in memory, NOT whether or not the translation component should be down the right hand side / along the bottom.

The translation is down the right hand side of the matrix when using column vectors, and across the bottom when using row vectors. Is this correct?

3) OpenGL uses column vectors, and uses column major matrices, and we want to upload the matrices to OpenGL using glUniformMatrix4fv

I'm pretty sure this is right, so does that mean that the translation component should be in m_Values[12], m_Values[13] and m_Values[14]?

4) When multiplying two matrices together, the operator* should have something like the following

final.m_Values[0] = (this.m_Values[0] * other.m_Values[0]) + (this.m_Values[1] * other.m_Values[4]) + (this.m_Values[2] * other.m_Values[8]) + (this.m_Values[3] * other.m_Values[12]);

final.m_Values[1] = (this.m_Values[0] * other.m_Values[1]) + (this.m_Values[1] * other.m_Values[5]) + (this.m_Values[2] * other.m_Values[9]) + (this.m_Values[3] * other.m_Values[13]);

final.m_Values[2] = (this.m_Values[0] * other.m_Values[2]) + (this.m_Values[1] * other.m_Values[6]) + (this.m_Values[2] * other.m_Values[10]) + (this.m_Values[3] * other.m_Values[14]);

I'm not sure if this order is right, or if I need to multiply a different way because the matrices are stored in column major order in memory. Can anyone clarify if this is the right way or not?

5) The Matrix Quaternion FAQ I linked to at the top seems to be using column vectors, so vectors are multiplied on the right, as shown in Q13 of the FAQ. Q35 appears to suggest that matrices should be multiplied the other way though.

Q35 states that in order to get an X rotation, followed by a Y rotation, followed by a Z rotation, you multiply:

M = X.Y.Z

But I thought that, because it is using column vectors, the first transformation should be at the right hand side. I.e.:

M = Z.Y.X

In fact, looking at the function calls listed at the start of Q36, it seems to be multiplying in the order I'd think was correct (i.e. Z * Y * X), but still goes on to state that M = X.Y.Z.

Are Qs 35 & 36 wrong, or is it just a difference in notation for multiplying matrices instead of vectors (as Q13 says that V' = M.V, which seems like the right way round to me). Or is it just that I'm very confused? ;)

Hopefully someone can help me out on this, it would be very useful. Thanks :)

C# Encode shorts into uint

22 January 2010 - 02:25 AM

I'm trying to encode two signed shorts into an unsigned int, with the line below: uint Encoded = (uint)GridXPos | ((uint)GridYPos << 16); But the compiler is giving me a warning of: Bitwise-or operator used on a sign extended operand; consider casting to a smaller unsigned type first. Maybe my brain hasn't woken up yet, but I can't figure out what the correct way to do this would be. I'm pretty sure the above line is OK, and if I try something like this: uint Encoded = (uint)((ushort)GridXPos | ((ushort)GridYPos << 16)); I get the same warning. What's the correct way to cast this?

Combine blocks into geometry

20 January 2010 - 02:05 AM

I'm looking for an algorithm to combine tiles into a solid piece of geometry. The tiles are all the same size and are either square or a corner piece (right angle triangle taking up one half of the area of a square, if you get what I mean), and are placed on a regular grid. What I'd like is to get the corner vertices of the geometry that wraps a set of connected tiles. Any ideas what to search for, or does anyone know of any algorithms? Thanks.

Photos of Lego

30 July 2009 - 01:05 AM

I thought about building objects from Lego and then photographing them to get sprites for a game. Does anyone know if this is legal, or does it infringe copyright? There would be no Lego branding visible.

Thumbnail screenshot in XNA

11 June 2009 - 11:50 PM

OK, my brain's not working today. I'm trying to capture a thumbnail screenshot in XNA, so I create a 128x128 texture, set it as the render target, render, then save it. The problem is that it's only capturing the 128x128 top left corner of the screen, not rendering the full image to the texture. My view and projection matrices are the same as when I do the full render, and I've set the viewport to 128x128, so this should work, right?