Hi, this was briefly covered in another thread, but I'm still not able to get it right. I'm working with a quake3 format MD3 loader/renderer and the way it works is you have seperate models for legs, torso, and head. Then you have tags that contain data on how they attach, and you multiply the model matrix in order to draw one after the other. So I have working 0.6 code, but can't quite get it to work in 0.8. Here is the 0.6 code:
// Get a pointer to the start of the 3x3 rotation matrix for the current frame
float[] pMatrix = Math3D.t2DArray21DArray(pModel.tags[pModel.currentFrame * pModel.numOfTags + i].rotation);
// Get a pointer to the start of the 3x3 rotation matrix for the next frame
float[] pNextMatrix = Math3D.t2DArray21DArray(pModel.tags[pModel.nextFrame * pModel.numOfTags + i].rotation);
// Now that we have 2 1D arrays that store the matrices, let's interpolate them
// Convert the current and next key frame 3x3 matrix into a quaternion
qQuat = JQuaternion.CreateFromMatrix(pMatrix);
qNextQuat = JQuaternion.CreateFromMatrix(pNextMatrix);
// Using spherical linear interpolation, we find the interpolated quaternion
qInterpolatedQuat = JQuaternion.SLERP(qQuat, qNextQuat, pModel.t);
// Here we convert the interpolated quaternion into a 4x4 matrix
finalMatrix = JQuaternion.CreateMatrix(qInterpolatedQuat);
// To cut out the need for 2 matrix calls, we can just slip the translation
// into the same matrix that holds the rotation. That is what index 12-14 holds.
finalMatrix[12] = vPosition.X; //x
finalMatrix[13] = vPosition.Z; //z
finalMatrix[14] = vPosition.Y; // y
AppContext.gl.pushMatrix();
AppContext.gl.multMatrixf(Sys.getDirectBufferAddress(ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer().put(finalMatrix)));
DrawLink(pLink);
AppContext.gl.popMatrix();
So far i've come up with this for 0.8, however when recursively drawing the next link, REALLY unexpected things happen like fuzzy distortion all over the window ( I cut out some of the matrix generation code for clarity, I know this is the erroneous portion):
FloatBuffer scratch = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
scratch.put(finalMatrix);
scratch.rewind();
scratch.flip();
GL.glPushMatrix();
GL.glMultMatrixf(scratch);
DrawLink(pLink);
GL.glPopMatrix();