thats right, the fourth dimension is W. yep. thats right. W.
as a matrix is (essentially) a multidimensional array, of X, Y, and Z usually, the fourth dimension should follow on from those, and seeings as theres no more alphabet after Z, we'll start working our way backwards, to W. With this Knowledge firmly in my somewhat bemused hand (mind), i set forth into this strange new dimension, a place where objects are transformed, translated, and translucent...wait...forget that last bit.
i chose to base my Matrix class directly on the framework of my Vectors class, this however did cause some problems, including but not limited to:
- How am i relating static voids to my main. (turns out in the matrix class the "static" part is dropped, and they become voids, which are called in the usual manner of Matrix::add(variables)
- multiplication seeming far more complex (something that i will comparing shortly)
- the Matrix Header issue.
Lets start with the last point shall we, there is a peculiar effect, when adding a file to a solution from outside of the solutions containing folder (ie from my documents rather than my document/visualstudio2008/projects/Vector etc), as when you do add that file, a file of that name is created within the containing folder, but all changes and saves are written to the original file. This causes 2 major problems.
The first is that, while you are updating the original file, the solution is attempting to read from the copy within its containing folder, the one that hasn't changed, thus preventing it from compiling correctly.
the second is that when you've finished your programming session, deep into the long hours of the night, you save, and you backup that solution, the updated file is lost from the backup, causing you to lose what could be hours of work.
however, a lesson learned is the first part of winning the programming war, and from now on i'll make sure i put my new external files into the containing folder before trying to add them.
now then, multiplication. Multiplication with a scalar is, as is typical, very simple, however multiplication of vectors becomes a long and drawn out process. Within this process a simple formula exists, row A X collumn B(as it was explained to me by a peer).
in reality that turned out as the heaving monstrocity shown below
result._m[0][0] = matrix1._m[0][0] * matrix2._m[0][0] + matrix1._m[0][1] * matrix2._m[1][0] + matrix1._m[0][2] * matrix2._m[2][0] + matrix1._m[0][3] * matrix2._m[3][0] ;
result._m[0][1] = matrix1._m[0][0] * matrix2._m[0][1] + matrix1._m[0][1] * matrix2._m[1][1] + matrix1._m[0][2] * matrix2._m[2][1] + matrix1._m[0][3] * matrix2._m[3][1] ;
result._m[0][2] = matrix1._m[0][0] * matrix2._m[0][2] + matrix1._m[0][1] * matrix2._m[1][2] + matrix1._m[0][2] * matrix2._m[2][2] + matrix1._m[0][3] * matrix2._m[3][2] ;
result._m[0][3] = matrix1._m[0][0] * matrix2._m[0][3] + matrix1._m[0][1] * matrix2._m[1][3] + matrix1._m[0][2] * matrix2._m[2][3] + matrix1._m[0][3] * matrix2._m[3][3] ;
result._m[1][0] = matrix1._m[1][0] * matrix2._m[0][0] + matrix1._m[1][1] * matrix2._m[1][0] + matrix1._m[1][2] * matrix2._m[2][0] + matrix1._m[1][3] * matrix2._m[3][0] ;
result._m[1][1] = matrix1._m[1][0] * matrix2._m[0][1] + matrix1._m[1][1] * matrix2._m[1][1] + matrix1._m[1][2] * matrix2._m[2][1] + matrix1._m[1][3] * matrix2._m[3][1] ;
result._m[1][2] = matrix1._m[1][0] * matrix2._m[0][2] + matrix1._m[1][1] * matrix2._m[1][2] + matrix1._m[1][2] * matrix2._m[2][2] + matrix1._m[1][3] * matrix2._m[3][2] ;
result._m[1][3] = matrix1._m[1][0] * matrix2._m[0][3] + matrix1._m[1][1] * matrix2._m[1][3] + matrix1._m[1][2] * matrix2._m[2][3] + matrix1._m[1][3] * matrix2._m[3][3] ;
result._m[2][0] = matrix1._m[2][0] * matrix2._m[0][0] + matrix1._m[2][1] * matrix2._m[2][0] + matrix1._m[2][2] * matrix2._m[2][0] + matrix1._m[2][3] * matrix2._m[3][0] ;
result._m[2][1] = matrix1._m[2][0] * matrix2._m[0][1] + matrix1._m[2][1] * matrix2._m[2][1] + matrix1._m[2][2] * matrix2._m[2][1] + matrix1._m[2][3] * matrix2._m[3][1] ;
result._m[2][2] = matrix1._m[2][0] * matrix2._m[0][2] + matrix1._m[2][1] * matrix2._m[2][2] + matrix1._m[2][2] * matrix2._m[2][2] + matrix1._m[2][3] * matrix2._m[3][2] ;
result._m[2][3] = matrix1._m[2][0] * matrix2._m[0][3] + matrix1._m[2][1] * matrix2._m[2][3] + matrix1._m[2][2] * matrix2._m[2][3] + matrix1._m[2][3] * matrix2._m[3][3] ;
result._m[3][0] = matrix1._m[3][0] * matrix2._m[0][0] + matrix1._m[3][1] * matrix2._m[1][0] + matrix1._m[3][2] * matrix2._m[2][0] + matrix1._m[3][3] * matrix2._m[3][0] ;
result._m[3][1] = matrix1._m[3][0] * matrix2._m[0][1] + matrix1._m[3][1] * matrix2._m[1][1] + matrix1._m[3][2] * matrix2._m[2][1] + matrix1._m[3][3] * matrix2._m[3][1] ;
result._m[3][2] = matrix1._m[3][0] * matrix2._m[0][2] + matrix1._m[3][1] * matrix2._m[1][2] + matrix1._m[3][2] * matrix2._m[2][2] + matrix1._m[3][3] * matrix2._m[3][2] ;
result._m[3][3] = matrix1._m[3][0] * matrix2._m[0][3] + matrix1._m[3][1] * matrix2._m[1][3] + matrix1._m[3][2] * matrix2._m[2][3] + matrix1._m[3][3] * matrix2._m[3][3] ;
yeah, isn't that grand. though to be fair, it follows a simple logic, and parts are easily copied and pasted into the right places.
for more on transformations, check back next time, when my brain has resolidified enough to make a coherent and informative post (the above is due some editing)
No comments:
Post a Comment