Search the Community
Showing results for tags 'matrix'.
-
I have something like: for(j=0; j<columnsNumber; j++) { for(i=0; i<rowsNumber; i++) { bufferMatix[j][i] = sourceMatrix[i][j]; } But it works only when rowsNumber=colsNumber Thanks!
-
Hi, I noticed, Leadwerks has functions for transforming vectors and points to different spaces. However, I am not really sure, what to think of the following things: I would have thought, transformation of the point A into the space of the matrix M simply means multiplying the matrix (from left) with setting the fourth coordinate of the point to 1: A' = M*A The same for vectors but just have the fourth coordinate be 0 instead of 1. I wrote the following code to do a matrix multiplication: ret = Vec4(0) for i = 0,3,1 do ret[i] = 0 for j = 0,3,1 do ret[i] = ret[i] + M[i][j] * A[j] end end (I also noticed, the matrix of self.entity:GetMatrix() has to be transposed before doing this because otherwise the last row is not 0,0,0,1, which is a MUST for transformation-matrices). However, Transform:Vector() and Transform:Point() all yield different results and I can't figure out, why. Transform:Vector yields quite similar results to my function, if I do not transpose the matrix beforehand, except for the fourth coordinate. The values yielded by Transform:Point() don't seem to be related to my values at all. Consider the following example code: local M = self.entity:GetMatrix():Transpose() local A = Vec4(0,0,1,0) System:Print(mat) ret = Vec4(0) for i = 0,3,1 do ret[i] = 0 for j = 0,3,1 do ret[i] = ret[i] + M[i][j] * A[j] end end local a = Vec3(0,0,1) local v = Transform:Vector(a, nil, self.entity) System:Print(v[0] .. "," .. v[1] .. "," .. v[2] .. "," .. v[3]) local v = Transform:Point(a, nil, self.entity) System:Print(v[0] .. "," .. v[1] .. "," .. v[2] .. "," .. v[3]) System:Print(ret[0] .. "," .. ret1] .. "," .. ret[2] .. "," .. ret[3]) All of these yield different values, when actually Transform:Vector should be the same. If I change the last coordinate of A to 1 instead of 0, Transform:Point should be the same. Can anyone enlighten me on this?