Manual matrix multiplication (and this is just for 4x4 matrices)

  1. Believe it or not, but this is the fastest way to do it, and any other way is counterproductive, since you need such operations many times per frame.

  2. Surely the compiler can unroll a loop with a constant length though, so writing this code with loops would almost certainly be better.

  3. The thing is unless you specialize in optimization, it’s probably just better to leave it to the compiler. You have to really know what you’re doing to have a chance of outsmarting the compiler.

  4. The problem is not efficiency, it's readability and extendability. Why not use arrays and vector operations? And why would you need a specific class for a 4x4 matrix rather than a generic class?

  5. Processors are optimized for matrix*vector multiplications so the ideal solution is to use the instruction for that and just do it four times for the columns of the matrix

  6. Not horror. Very common in game or other performance oriented applications. You'll often special case common scenarios and general case uncommon ones.

  7. Eh, it's not too bad. Sure it's a little ugly, but the operation itself is well-understood so it's clear what the code is doing.

  8. In c# custom object variables are always an implicit pointer so it is effectively a pass by reference

  9. I've done the same many times, and a necessity when elements are stored in fields. This produces operations on the stack which is multiple times faster than the heap.

  10. Mine is like this, however I have an extra step where I cache the initial values first to remove some of the lookup time. It does make a difference when you are processing lots of matrices each frame.

  11. I had to do that in a university assignment. Yes we had to do 2x2 matrix multiplication before we learned about loops.

  12. does nobody see that he’s allocating a Matrix4x4 pointer but returning it as a copy? Why is every variable stored as a member variable instead of an array?

  13. This is basically the difference between scientist & engineer. (Computer) scientists see this and thing, woah, why is this coded for specific n = 4? I could make this an nxn matrix and solve it with that algorithm i learned in class! Whereas the (software) engineers see this and go "yep, this is how we do it because O(1) is a faster than that O(n^3) general matrix multiplication function. Duh.

Leave a Reply

Your email address will not be published. Required fields are marked *

Author: admin