2
* Make a donation http://sourceforge.net/donate/index.php?group_id=98797
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Contact Josh DeFord jdeford@microcrowd.com
22
package com.microcrowd.loader.java3d.max3ds.chunks;
24
import java.util.ArrayList;
25
import java.util.List;
26
import javax.vecmath.Quat4f;
27
import javax.vecmath.Vector3f;
28
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
31
* Extracts the rotation information from the 3ds file.
32
* Rotations occur about a pivot at a position within
33
* a local coordinate system. The rotation information
34
* is provided to the KeyFramerInfoChunk which then converts
35
* it to a global coordinate system and applies animation
37
* {@see KeyFramerInfoChunk} for more information about using
38
* animations from a 3ds file
40
public class RotationChunk extends Chunk
43
* String that will be used as a data object in the transform that the
44
* RotationInterpolator will be a child of so it may be look up later.
46
public static String ROTATION_TAG = "ROTATION_INTERPOLATOR";
49
* Loads the quaternion for a rotation of a shape
50
* and notifies mesh info chunk.
52
* @param chopper the ChunkChopper containing the state of the parser.
54
public void loadData(ChunkChopper chopper)
56
int flags = chopper.getUnsignedShort();
58
int numKeys = chopper.getUnsignedInt();
60
Quat4f previousQuat = null;
62
List quats = new ArrayList();
63
for(int i =0; i < numKeys; i++)
65
long frameNumber = chopper.getUnsignedInt();//Part of the track header
66
int accelerationData = chopper.getUnsignedShort();//Part of the track header
67
getSplineTerms(accelerationData, chopper);//Part of the track header
69
float angle = chopper.getFloat();
70
Vector3f vector = chopper.getVector();
72
Quat4f quat = getQuaternion(vector, angle);
73
if(previousQuat != null) {
74
quat.mul(previousQuat, quat);
81
chopper.getKeyFramer().setRotation(quat);
84
chopper.getKeyFramer().setOrientationKeys(quats);
88
* This only reads the spline data and should be part
89
* of the track header when it gets invented.
90
* @param chopper an integer representing the bits that
91
* determine which of the five possible spline terms are present in the
92
* data and should be read.
93
* @param chopper what to read the data from
94
* The possible spline values are are
103
private void getSplineTerms(final int accelerationData, ChunkChopper chopper)
105
int bits = accelerationData;
106
for(int i=0; i < 5; i++)
117
* This converts a 3ds angle and axis to
118
* a quaternion rotation. Successive
119
* rotations are relative to the first so each
120
* rotation must be made absolute by multiplying
121
* it with its predecessor
123
public Quat4f getQuaternion(Vector3f axis, float angle)
125
float sinA = (float)(java.lang.Math.sin(angle/2.0f));
126
float cosA = (float)(java.lang.Math.cos(angle/2.0f));
127
return new Quat4f(axis.x * sinA, axis.y * sinA, axis.z * sinA, cosA);