### Author Topic: Matrix3f  (Read 2462 times)

#### Hmm

• byte
• • Posts: 6 ##### 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! #### Hmm

• byte
• • Posts: 6 ##### 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; //The array holding the values in the new Matrix float[] rowDump = new float;     //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; insertDump[targetElement + 1] = rowDump; insertDump[targetElement + 2] = rowDump; //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 = 1.0f; //Create the new Matrix and load in the values Matrix output = new Matrix(); output.setDump(insertDump); //Return return output; }`

#### EgonOlsen

•     •  