~ubuntu-branches/debian/wheezy/java3ds-fileloader/wheezy

« back to all changes in this revision

Viewing changes to com/microcrowd/loader/java3d/max3ds/chunks/AxisChunk.java

  • Committer: Bazaar Package Importer
  • Author(s): Gabriele Giacone
  • Date: 2009-11-24 16:27:06 UTC
  • Revision ID: james.westby@ubuntu.com-20091124162706-yvyj5k4igsyct81k
Tags: 1.2-1
Initial release (Closes: #558259)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Make a donation http://sourceforge.net/donate/index.php?group_id=98797
 
3
 * Microcrowd
 
4
 *
 
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.
 
9
 * 
 
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.
 
14
 * 
 
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
 
18
 * 
 
19
 * Contact Josh DeFord jdeford@microcrowd.com
 
20
 */
 
21
 
 
22
package com.microcrowd.loader.java3d.max3ds.chunks;
 
23
 
 
24
import javax.media.j3d.Transform3D;
 
25
import javax.vecmath.Point3f;
 
26
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
 
27
 
 
28
/**
 
29
 * Extracts the local coordinate that will act 
 
30
 * as a shape's axis that will be used by the mesh 
 
31
 * info chunk.
 
32
 */
 
33
public class AxisChunk extends Chunk
 
34
{
 
35
    private float value;
 
36
 
 
37
    /**
 
38
     * Loads the local coordinate system for the current mesh.
 
39
     *
 
40
     * @param chopper the ChunkChopper containing the state of the parser. 
 
41
     *
 
42
     * The location of the local coordinate system is defined relative to 
 
43
     * positions and rotations at frame 0.  But the orientation is absolutely
 
44
     * defined.
 
45
     *
 
46
     * With either 3x3 or 4x4 rotation, translation, there
 
47
     * is a simple relationship between each matrix and the resulting coordinate
 
48
     * system. The first three columns of the matrix define the direction vector of the
 
49
     * X, Y and Z axii respectively.
 
50
     * If a 4x4 matrix is defined as:
 
51
     * <code>
 
52
     *     | A B C D |
 
53
     * M = | E F G H |
 
54
     *     | I J K L |
 
55
     *     | M N O P |
 
56
     * </code>
 
57
     * Then the direction vector for each axis is as follows:
 
58
     *
 
59
     * <code>
 
60
     * X-axis = [ A E I ]
 
61
     * Y-axis = [ B F J ]
 
62
     * Z-axis = [ C G K ]
 
63
     * </code>
 
64
     *
 
65
     * @return the actual number of bytes read.  
 
66
     */
 
67
    public void loadData(ChunkChopper chopper)
 
68
    {
 
69
        Point3f xAxis  = new Point3f();
 
70
        xAxis  = chopper.getPoint();
 
71
        Point3f zAxis  = chopper.getPoint();
 
72
        Point3f yAxis  = chopper.getPoint();
 
73
        Point3f origin = chopper.getPoint();
 
74
 
 
75
        Transform3D transform = new Transform3D(new double[]{
 
76
            xAxis.x,  xAxis.y,  xAxis.z, origin.x, 
 
77
            yAxis.x,  yAxis.y,  yAxis.z, origin.y,  
 
78
            -zAxis.x,  -zAxis.y,  -zAxis.z, origin.z,
 
79
            0,0,0,1});
 
80
        String meshName = chopper.getObjectName();
 
81
        chopper.getKeyFramer().setCoordinateSystem(meshName, transform);
 
82
    }
 
83
}