Jump to content
  • Advertisement


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


Simle matrix optimizations, are they valid???

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

When multiplying a vector by a (homogenous) matrix (ie. doing 4 dot products), is it always safe to ommit the last dot product, and just hard-code the result.w to one? (not counting projection matrices). What will make the bottom matrix row become something else than {0,0,0,1} ? If so, I guess I can also apply the same technique to matrix multiplication? -meZ

Share this post

Link to post
Share on other sites
This is basically what I do. The vector classes I use are of length 3, and the matrix is 3x4. But they are logically homogenous, and will stay such as long as you don't do things such as perspective transforms or similar.

Partitioning matrices can help to see how this works. Let's say we're dealing with just rotation and translation (although scale should work as well):

| R R R t |
| R R R t |
| R R R t |
| 0 0 0 1 |

is the matrix. We can partition this into four submatrices: a 3x3 in the upper-left, a 3x1 in the upper-right, a 1x3 in the lower-left, and a 1x1 in the lower-right, like so:

| R R R | T |
| R R R | T |
| R R R | T |
| 0 0 0 | 1 |

which in a simpler syntax is:


Now, when multiplying by another matrix, you get something that looks like this:

|R|T| |r|t|
+-+-+ * +-+-+
|0|1| |0|1|

Use your 2x2 matrix multiply rules to get:

| Rr + T0 | Rt + T1 |
| 0r + 10 | 0t + 11 |

And you can see that because both R and r are 3x3 they can multiply; likewise, Rt is a 3x3 matrix times 3x1 vector which is okay (creating a 3x1 vector); and so forth. The final result is:

| Rr | Rt+T |
| 0 | 1 |

So you can immediately see that the bottom row always remains [0 0 0 1]. Likewise, if you work out the matrix*vector, the 4th component remains 1. So in my code, the last row of the matrix and last component of the vector are never stored.

Obviously when you get to the end and need to do a perspective transform (or other "strange" transform), you need to handle things a little differently , but it's usually trivial to work it out.

---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Edited by - mossmoss on February 7, 2002 5:52:18 PM

Share this post

Link to post
Share on other sites
Thanks for the explanation. It''s more or less what I do, but it''s good to get confirmation that it''s actually correct.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!