Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code you have is hard to work off (as an outsider), since we need to know how the class <code>Matrixf</code> works. I will outline a method anyway, which may point you in the right direction. The simplest way you could represent a matrix in C/C++ is simply a 2D array of floating points like so:</p> <pre><code>float matrix[3][3]; // 3x3 Matrix </code></pre> <p>Considering you already know the maths, I think all you need is some guidance in terms of coding what you need. To multiply elements of two of these matrices simply do this:</p> <pre><code>matrixC[0][1] = matrixA[0][0] * matrixB[0][0]; </code></pre> <p>This will store the result of multiplying the top-left element of <code>matrixA</code> and the top-left element of <code>matrixB</code> in the top-middle element of <code>matrixC</code>. Essentially the first square bracket represents the <em>row</em> and the second square bracket represents the <em>column</em> (however it is totally up to you which order you want the rows and columns to be, just so long as you stay consistent).</p> <p>Vectors can be represented similarly:</p> <pre><code>float vector[3]; // 3d vector </code></pre> <p>Of course, since we are using C++, there are nicer ways to do this. It seems you have some resources that describe a class-centric method to doing this. The nice thing about a class based method is you can abstract multiplication operations in a neat manner like this:</p> <pre><code>Matrix3x3f matrix( 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f ); Vector3f vector( 0.2f, 1.4f, -3.1f ); matrix.multVec( vector ); </code></pre> <p>...or something along these lines.</p> <p>(It is also worth mentioning that there are libraries out there that already do this sort of thing, and efficiently too.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload