Quaternions and transformation-Matrices -- Plz help me!

Im trying to learn bone animation. My designer has chosen the 3d-format, b3d.
If you want to help me with my problem but dont know the b3d-fileformat here is the specifications http://www.zen54709.zen.co.uk/b3dformat.htm#BB3D

So far I know how to make a glCanvas show a frozen non-animated version of my designers models. Now its time that I learn the animation part.

I have been told to read alot about quaternions and transformation matrices. I have also been told to make a tranformation and rotation matrix for each NODE in the model. I have writen a chunkWriter that println’s some info in each chunk to the screen - just to make me more comfortable with the way a b3d-file is build up. It looks more or less like this:

BB3D - 6184 Bytes - version: 1
TEXS - 43 Bytes - TexturePath: .\snowdrag.png - xpos: 0.0 ypos: 0.0 xscale: -0.0 yscale: -8.8E-44 rotation: 8.8E-44
BRUS - 47 Bytes
NODE - 6066 Bytes - Node name: ROOT. Position: (0.0, 0.0, -0.0). Scale: (1.0, 1.0, 1.0). Rotation: (1.0, 0.0, 0.0, -0.0).
MESH - 4372 Bytes - Master brush: -1
VRTS - 2332 Bytes - Flags: 0, 1, 2. 5 floats/vert.(x,y,z,u,v). All vertices writen to Vertices.txt
TRIS - 2020 Bytes - Brush: -1 - Triangles: 168 - All triangles has been writen to Triangles.txt and Pollies.txt
ANIM - 12 Bytes - Flag: 0 - Frames: 30 - Fps: 0.0
NODE - 1613 Bytes - Node name: joint1. Position: (0.04537487, 0.0, -22.83983). Scale: (1.0, 1.0, 1.0). Rotation: (-4.3711385E-8, -4.3711392E-8, 1.0, 4.3711392E-8).
BONE - 520 Bytes. Vertex1: 0 - Weight1: 1.0. Vertex2: 1 - Weight2: 1.0
KEYS - 84 Bytes - Flag: 1 - Frame: 1 - Position: (0.0453749, -0.3333354, -0.0064964294).
KEYS - 104 Bytes - Flag: 4 - Frame: 1 - Rotation: (-6.1817246E-8, -6.181724E-8, 0.70710695, -0.7071066).
NODE - 826 Bytes - Node name: joint2. Position: (0.0, 0.0, -23.25). Scale: (1.0, 1.0, 1.0). Rotation: (-4.3711488E-8, -3.1391647E-7, -3.1391647E-7, -1.0).
BONE - 408 Bytes. Vertex1: 3 - Weight1: 1.0. Vertex2: 4 - Weight2: 1.0
KEYS - 100 Bytes - Flag: 1 - Frame: 1 - Position: (-1.9895195E-13, -1.9895198E-13, -23.25).
KEYS - 124 Bytes - Flag: 4 - Frame: 1 - Rotation: (-4.3711488E-8, -3.1391647E-7, -3.1391647E-7, -1.0).
NODE - 115 Bytes - Node name: joint3. Position: (0.0, 0.0, -22.75). Scale: (1.0, 1.0, 1.0). Rotation: (1.0, 0.0, 0.0, -0.0).
BONE - 0 Bytes.
KEYS - 20 Bytes - Flag: 1 - Frame: 1 - Position: (0.0, 0.0, -22.75).
KEYS - 24 Bytes - Flag: 4 - Frame: 1 - Rotation: (1.0, 0.0, 0.0, 0.0).

I assume that the 4 floats in Rotation in each node is the quaternoin I have to use to make the matrix, is that right?
Also, the quaternion will only give me a 3x3matrix… isnt it a 4x4matrix I have make?
This is where im standing… this whole quaternion/transformation matrix stuff is quite a mouthfull for me!! So I hope someone can tell me what to do next. Each NODE gives also a position(3 floats) and a scale (3 floats). Where do I use them?

heres some math, whatelse do I need to do?

Matrix = [ 1 - 2y2 - 2z2 2xy - 2wz 2xz + 2wy
2xy + 2wz 1 - 2x2 - 2z2 2yz - 2wx
2xz - 2wy 2yz + 2wx 1 - 2x2 - 2y2 ]
given the quaternion Q (w, x, y, z)

From the spec:

[quote]Quaternions are used to specify general orientations. The first value is the quaternion ‘w’ value,
the next 3 are the quaternion ‘vector’. A ‘null’ rotation should be specified as 1,0,0,0. Time to read up on Quaternions I think…
[/quote]
The 4x4 matrix you want can be obtained by adding an extra row and column:

[1 - 2y2 - 2z2, 2xy - 2wz, 2xz + 2wy, 0
2xy + 2wz, 1 - 2x2 - 2z2, 2yz - 2wx, 0
2xz - 2wy, 2yz + 2wx, 1 - 2x2 - 2y2, 0
0, 0, 0, 1]

For more information I suggest you just google for some skeletal animation tutorials. I don’t have any experience doing that myself either.
Wikipedia has some pretty good info on rotation matrices and quaternions. You can also check out Mathworld for some more information.

Some helpfull guy helped me with the matrix…
Here’s what Arne wrote:

"Use javax.vecmath !!! Then it gets really simple:

Code:
Matrix4f m = new Matrix4f();
m.set(); //set the rotation
m.set(); //set the position

I don’t know how you can set scaling, but there’s probably also a method for that."

And I must admit… The vecmath package is very usefull!

I have a few more questions:

  1. Is this matrix the only one I have to make for each node? Do I need one for each axis?

  2. The Matrix4f constructor looks like this: Matrix4f(Quat4f q1, Vector3f t1, float s) .
    So the constructor makes use of the 4 floats in rotation, the 3 floats in position, but only 1 float from scale. Which one? This is why I ask if I have to make a matrix for each axis…

  3. And this question is a little embarasing: now that I have the matrix how exactly do I use it? I know it has to do with cross products and likely the vertices and their weights for each bone. Where do I read about this? If someone could throw me a link to a good page it would be great…

  4. I see I have 2 KEYS for each NODE. One for rotation and one for position of each keyframe. How do I use them?

Thanks in advance - and a great weekend to y’all!

Some more reading tips:
Matrix algebra
Scene graph basics
Those two should point you in the right direction.