Basic matrix question

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

Recommended Posts

Hi Guys,

I have decided to take the plunge and try to de-mystify matrices in my own mind.

I have managed to write a simple calculator to multiply two matrices together to give an output.

So multiplying a simple identity matrix against a translation matrix gives me this (assuming translation is 5, 6 ,7 -xyz for learning purposes).

1 0 0 0
0 1 0 0
0 0 1 0
5 6 7 0

If I were to now use the x, y, and z co-ordinates for this single vertex (assuming the vertex is originally 0,0,0) would the location of the new vertex always be stored in elements 12, 13, and 14?

If so, when I start playing with rotation matrices etc and start getting numbers that aren't easy to predict (as they are above). Is the new x, y, and z of the vertex always going to be in 12, 13, and 14?

Sorry if this sounds overly basic and noobish, but I literally started learning matrices around 20 minutes ago

Share on other sites
It depends how the matrix is ordered in memory, but if it is
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

then your position will be at 12,13,14.

The trick about hormogoneous matricies in game dev is, that you can read the important vectors (position, lookat, right, up) directly from the matrix most of the time.

But, before you break your fingers by reinventing the wheel (aka writing your own math lib) , try to use a math library like glm (free, and header only lib, no lib linking necessary !).

Share on other sites

Looks like I am on the right track then.

Do you think it is worth persisting learning a little more about matrices or should I ditch the idea and go straight for a lib?

Share on other sites

If I were to now use the x, y, and z co-ordinates for this single vertex (assuming the vertex is originally 0,0,0) would the location of the new vertex always be stored in elements 12, 13, and 14?
A vertex is a 1x4 matrix, or a 4x1 matrix (depending on which mathematical conventions you're using)

Depending on your convention, a transformation matrix multiplied by a vertex looks like:

1x4 * 4x4 = 1x4

4x4 * 4x1 = 4x1

i.e. your matrix has 16 elements, but your input vertex and your result only have 4 elements each.

Share on other sites
I think I get what you are saying there.

In other words less calculations, because it is a transform matrix?

I was playing around with the full 16 elements as I'll move on to trying out rotations etc next and wanted to make sure I was going about the whole thing correctly.

But (if I understand your post correctly) you can abbreviate some of the calculations somewhat. Right?

Share on other sites

In other words less calculations, because it is a transform matrix?
No. You were talking about vertices... which are very different from matrices. I assumed you were talking about transforming a vertex using a matrix (which is what my post is about).

Share on other sites

In other words less calculations, because it is a transform matrix?

No. You were talking about vertices... which are very different from matrices. I assumed you were talking about transforming a vertex using a matrix (which is what my post is about).

Yep, I was talking about verts as well.

Obviously I am missing something. As I said completely new to matrix calculations.

Share on other sites
You should learn about matrix calculation, at least about the special subset of homogenous 4x4 matricies typically used in 3d game development. The special matricies are rotation, translation, scaling, and the inverse, order of multiplication, accessing position/lookat/up/right vector of a hom. 4x4 matrix,the difference between multiplying a hom. 4x4 matrix with a (x,y,z,0) and (x,y,z,1) vector etc. This should be really the baseline for coding a 3d game.

You should use a lib to get a fast and robust implmentation, still you need to learn how and when to apply what type of matrix.

Share on other sites
It's definately worth demystifying further. I suggest you use one of the first chapters of the frank d Luna d3d11 book, this covers all the basics and some usefull exercises.

Also note that in theory there can be a difference on row major vs column major (depending on the API and or settings/ HLSL usage)

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• Forum Statistics

• Total Topics
632948
• Total Posts
3009401
• Who's Online (See full list)

There are no registered users currently online

×