Order of transformation in a software renderer?
I'm writing a very simple software renderer. Due to size constraints I'm not using matrices but rather an all purpose transform(vertex[], posxyz, anglexyz) function that rotates and then translates a vertex. First I transform the models in model space then transform() it again with the camera position and angle.
The thing is this; I discovered I can't just do the camera transform like the model transform ie:
rotate-->translate
it needs to be:
translate-->rotate
I've read alot of stuff online about software renderering and I don't recall reading this before. I suspect it has something to do with matrix math (that's what I'm not really strong on).
Is this right? Can anyone explain what I'm missing here?
It is true that the order is important, because matrix multiplication is not commutative (eg. matrix1 * matrix2 != matrix2 * matrix1).
For example, take 2x2 matrices:
Edit: Mixed up associativity and commutativity..
For example, take 2x2 matrices:
Matrix1 = | a b | | c d |Matrix2 = | e f | | g h |Matrix1 x Matrix2 = | (a * e) + (b * g) (a * f) + (b * h) | | (c * e) + (d * g) (c * f) + (d * h) |Matrix2 x Matrix1 = | (e * a) + (f * c) (e * b) + (f * d) | | (g * a) + (h * c) (g * b) + (h * d) |
Edit: Mixed up associativity and commutativity..
Quote:matrix multiplication is not commutative
I've read this quiet a few times; I suppose this is a real world application that displays that fact. I didn't realize rotating/translating more than once would be a multiplication operation in linear algebra.
Thanks!
Trying it out by hand may help understanding. A simple example:
Consider a vertex at the origin. Rotate it counter-clockwise 90 degrees, then translate it 5 units right. It will be at (5,0).
Now, consider another vertex at the origin. Translate it 5 units right, then rotate it counter-clockwise 90 degrees. It will be at (0,5).
Consider a vertex at the origin. Rotate it counter-clockwise 90 degrees, then translate it 5 units right. It will be at (5,0).
Now, consider another vertex at the origin. Translate it 5 units right, then rotate it counter-clockwise 90 degrees. It will be at (0,5).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement