Exactly! Because the vector contains scaling "factors", a factor of one means "keep this the same" (a * 1 = a).
Because the scaling vector contains factors, your code will not work:
[pascal]
function Mat4Scale(const M: TBrainMatrix; const V: TBrainVector): TBrainMatrix; inline;
begin
Result := M;
Result.M[0, 0] := Result.M[0, 0] + V.X;
Result.M[1, 1] := Result.M[1, 1] + V.Y;
Result.M[2, 2] := Result.M[2, 2] + V.Z;
end;
[/pascal]
Let's say you have an identity matrix:
And you want to make it twice as big (factor 2). Acoording to your code, this would result in:1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
0, 0, 0, 1
The numbers in the diagonal part of the matrix are also used as scaling factors. As you see, it will result in 3x scaling instead of 2x.3, 0, 0, 0
0, 3, 0, 0
0, 0, 3, 0
0, 0, 0, 1
So, first of all, treat the numbers as factors!
Secondly, concatenating two transforms is ALWAYS done by matrix multiplication. In this case we would have a scaling matrix, constructed by vector V. It would look like this:
Secondly, we have our original matrix M.V.x, 0, 0, 0
0, V.y, 0, 0
0, 0, V.z, 0
0, 0, 0, 1
We need to multiply these to get the matrix M with the scaling applied on it.
This brings me to a more difficult issue:
Matrix multiplication is not commutative, which means that A x B will not yield the same result as B x A. We should be aware of the order in which we multiply matrices.
I still haven't figured this part out, so I better don't give any advice, other than that you have to be carefull.
This is what I'd do:
[pascal]
function Mat4Scale(const M: TBrainMatrix; const V: TBrainVector): TBrainMatrix; inline;
begin
Result := MatIdentity();
Result.M[0, 0] := V.X; //The identity matrix has only 1's diagonally, so multiplying
Result.M[1, 1] := V.Y; //V with 1 makes no sense.. we can assign it directly
Result.M[2, 2] := V.Z;
//multiply with M here, this could be
Result = MatMultiply( Result, M)
// OR !!
Result = MatMultiply( M, Result )
end;
[/pascal]
Also, I suggest you study a few examples of matrices and see how they affect geometry:
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
(I know it's direct3D, but you can still use this knowledge).
Also, take a very close look at existing matrix code, instead of writing your own (I use math code written by others. )
Hope this helps
Bookmarks