/*
Example of Matrix multiplication
*/
var m1 = XSIMath.CreateMatrix4( 1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0,
9.0, 10.0,11.0,12.0,
13.0,14.0,15.0,16.0 );
var m2 = XSIMath.CreateMatrix4( 1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0 ) ;
var m3 = XSIMath.CreateMatrix4();
var m4 = XSIMath.CreateMatrix4();
// The m2 matrix will swap 2 and 3rd rows
// m3 is the composition of m1 and m2
m3.Mul( m2, m1 ) ;
Application.LogMessage( "Multipled matrix" ) ;
PrintMatrix( m3 ) ;
// m2 is invertible, so we can restore
// the original matrix
// (In fact this is not necessary
// because inversion of m2 = m2)
m2.InvertInPlace() ;
PrintMatrix( m2 ) ;
m4.Mul( m2, m3 ) ;
Application.LogMessage( "Restored matrix" ) ;
PrintMatrix( m4 ) ;
function PrintMatrix( oMatrix4 )
{
for ( var row = 0 ; row < 4 ; row++ )
{
strLine = "" ;
for( var col = 0 ; col < 4 ; col++ )
{
strLine += oMatrix4.Value( row, col ) + "\t\t";
}
Application.LogMessage( strLine ) ;
}
}
//INFO : Multipled matrix
//INFO : 1 2 3 4
//INFO : 9 10 11 12
//INFO : 5 6 7 8
//INFO : 13 14 15 16
//INFO : Restored matrix
//INFO : 1 2 3 4
//INFO : 5 6 7 8
//INFO : 9 10 11 12
//INFO : 13 14 15 16
|