Author Topic: Matrix3f  (Read 3698 times)

Offline Hmm

  • byte
  • *
  • Posts: 6
    • View Profile
Matrix3f
« on: May 13, 2007, 03:24:08 am »
Hello,

I have a rotation stored as a Matrix3f object, and need to use that to set the rotation of an Object3D.  Unfortunately, I don't quite understand how rotations are represented in this format, so I'm having trouble making the conversion to the Matrix object needed for the setRotationMatrix() method of the Object3D.

Is there any simple way to convert from a Matrix3f to a Matrix?

Thank you for any help! :)

Offline Hmm

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Matrix3f
« Reply #1 on: May 13, 2007, 06:18:21 pm »
Here's the code I ended up with for copying a Matrix3f into the format for a rotation Matrix:

Code: [Select]
protected Matrix Matrix3fToMatrix(Matrix3f input)
{
//Declare variables
float[] insertDump = new float[16]; //The array holding the values in the new Matrix
float[] rowDump = new float[3];     //The array for temporarily holding values from the rows of the Matrix3f
int targetElement = 0;              //Points to the next location in the insertDump to add data

//Loop through the rows of the Matrix3f
for (int sourceRow = 0; sourceRow < 3; sourceRow++)
{
//Grab the row from the Matrix3f
input.getRow(sourceRow, rowDump);

//Insert the 3 elements from the Matrix3f into the Matrix.  The fourth element has been initialized to 0.0f.
insertDump[targetElement] = rowDump[0];
insertDump[targetElement + 1] = rowDump[1];
insertDump[targetElement + 2] = rowDump[2];

//Move the target ahead by four spaces
targetElement += 4;
}

//The final row consists of { 0.0f, 0.0f, 0.0f, 1.0f }, since this is a rotation matrix
insertDump[15] = 1.0f;

//Create the new Matrix and load in the values
Matrix output = new Matrix();
output.setDump(insertDump);

//Return
return output;
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Matrix3f
« Reply #2 on: May 13, 2007, 09:26:03 pm »
That's exactly how to do it.