Adding two 4x4 matrix objects to form another

Started by
17 comments, last by jpetrie 18 years ago
Yeah, camera code is copy pasted stuff..


But I understand your average matrix math, adding, subtracting, multiplying, determinents, etc...

But I believe it is logic here that is failing me, or opengl syntax..

LocalMatrix * ParentNode->FinalMatrix should result in a matrix that looks like this

[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

As I havn't set any informations inside the matrices

With these elements being the translation:

[0 0 0 X]
[0 0 0 Y]
[0 0 0 Z]
[0 0 0 0]

It should be exactly the same as calling glTranslatef(0.0, 0.0, 0.0);

Or glLoadIdentity...

Or maybe the problem is that the scalar value is 0? I don't see why though..

I really believe that it is a matter of not understanding the gl matrix and transformation functions..

the MODELVIEW matrix should be in use, it is set after setting up the opengl world matrix in the resize_gl function..


Advertisement
I still suggest to read more on matrices, it seems that you don't really understand multiplications, or additions, or other things. If you previously learned matrices in school or something, you may need to refresh knowledge.
Also, the way how matrices is used to transform vertices you render is
transformed vector = matrix*vector . It is not some "opengl thing", it's how you apply linear transformations (e.g. rotations, etc).

You don't "add" matrix to vector to transform(i.e. rotate or whatever) things . It doesn't even make sense. You multiply it. So the matrix that leaves vector unchanged after multiplication is identity matrix
1 0 0 00 1 0 00 0 1 00 0 0 1

, not zero matrix. (if you multiply by zero matrix, all your points just get compressed into infinitely small dot, kind of)

As for other problems, you probably confused "add" as in english language (e.g. add more code to get some effect, "add rotation", etc), and "add" as in mathematics. It's rather common mistake, actually.
Did you read my last post?

I didn't say the word add for, quite some time, in fact I havn't said add since like, my first 2 or 3 posts?

And the only reason it would end up as a 0 matrix is the fact that I didn't set up the scalar values of the matrices when I initialized them.
Yep, sure i did read it. It's just that, if you knew the matrices, how and why matrices is used for rotations etc. you'd see why these matrices needs 1's on diagonal, for example, and would also be able to solve your problem already.

edit: What i mean is that when problem arises purely because of lack of information the best suggestion is to get this information and this will solve the problem.
Quote:Original post by Xetheriel
...

LocalMatrix * ParentNode->FinalMatrix should result in a matrix that looks like this

[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

As I havn't set any informations inside the matrices

With these elements being the translation:

[0 0 0 X]
[0 0 0 Y]
[0 0 0 Z]
[0 0 0 0]

It should be exactly the same as calling glTranslatef(0.0, 0.0, 0.0);

Or glLoadIdentity...

Or maybe the problem is that the scalar value is 0? I don't see why though..

I really believe that it is a matter of not understanding the gl matrix and transformation functions..

the MODELVIEW matrix should be in use, it is set after setting up the opengl world matrix in the resize_gl function..


Calling glTranslatef(X, Y, Z) does not produce the matrix:
[0 0 0 X]
[0 0 0 Y]
[0 0 0 Z]
[0 0 0 0]

It actually produces:
[1 0 0 X]
[0 1 0 Y]
[0 0 1 Z]
[0 0 0 1]

The reason starts to make sense when you try transformation using matrices on a piece of paper. Lets say you have a point (5, 6, 7, 1) in 3D homogenous coordinates. Try multiplying out the translation matrix with the point:

[1 0 0 X]   [5][0 1 0 Y]   [6][0 0 1 Z] * [7][0 0 0 1]   [1]


You'll see that the answer is [5+X, 6+Y, 7+Z, 1] which is just what you want to do translation. If you don't have the ones along the diagonal, you'll see that it just doesn't work out mathematically.

If you want to combine transformation, you have to multiply the matrices together. Search on google to get a better idea on how transformations using matrices work.
See now we're getting helpful..

You have to understand, the last thing I feel like doing is diving into math tutorials when I already know how to do basic matrix multiplication/addition/translation etc etc..

What I didn't understand was a three dimensional concept - you need those 1's in there to get the right results.. I believe those are the scalar values?

Now that I know this, I can fix my program so I set them to an identity matrix before I initialize any translation. Because multiplying those two matrices together was like, messing up (I don't feel like doing a bit of matrix math to figure out exactly what is happening, but i know it isn't good)...

I think the fact that I need the scalar values was quite different from "revisiting the basics of matrices again"..

Sorry for getting a little short, i just really didn't feel like opening up a math book on this one, and I really didn't think i needed to..

So, yeah, please spare my rating :)

We learn arbitrary stuff in school, not the specifics of 3dimensional rendering via 4x4 matrices :)
Well, it's simply phenomena of copy paste programming, where code is copy-pasted from elsewhere... you sure can make something kind of work this way, but will have ton of very simple problems that you could easily solve if you learn and/or refresh knowledge.

Thing is, if one does know relevant math (and how and why this math is used in this case) at adequate level to program 3D software, one will necessarily see why these 1's in diagonal is necessary(even if he didn't learn any specifics). 3D game programming is math-intensive thing, and it's for most part not some exotic math but general stuff. Also, it is easy to misjudge own knowledge of mathematics.

As for some basic things, check out matrix and quaternion FAQ. Forum FAQ also contains few good links.

(btw i didn't touch your rating either way)
Ew lame, who did then :\....

The nerve of people :
I rated you and the other guy up.
Mentioning your rating is a sure way to get rated down in any case.

This topic is closed to new replies.

Advertisement