Subversion Repositories AndroidProjects

Rev

Rev 1767 | Rev 1778 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1720 chris 1
package com.gebauz.bauzoid2.graphics.model;
2
 
1723 chris 3
import com.gebauz.bauzoid2.game.Engine;
4
import com.gebauz.bauzoid2.math.Matrix4;
1774 chris 5
import com.gebauz.bauzoid2.math.Quaternion;
6
import com.gebauz.bauzoid2.math.Vector3;
1767 chris 7
import com.gebauz.bauzoid2.math.Vector4;
1723 chris 8
 
1720 chris 9
/**
10
 * Created by chris on 14.12.2014.
11
 */
12
public class ModelNode
13
{
14
    // Constants========================================================================================
15
 
16
    // Embedded Types===================================================================================
17
 
18
    // Fields===========================================================================================
19
 
20
    private String mName = null;
21
 
1751 chris 22
    private int mParentIndex = -1;
23
 
1720 chris 24
    public ModelPart[] parts = null;
25
 
1751 chris 26
    private Matrix4 mGlobalTransform = Matrix4.createIdentity();
1774 chris 27
    //private Matrix4 mLocalTransform = Matrix4.createIdentity();
1723 chris 28
 
1774 chris 29
        private Vector3 mTranslation = null;
30
        private Quaternion mRotation = null;
31
        private Vector3 mScale = null;
32
 
1720 chris 33
    // Methods==========================================================================================
34
 
1751 chris 35
    public ModelNode(String name, int parentIndex)
1720 chris 36
    {
37
        mName = name;
1751 chris 38
        mParentIndex = parentIndex;
1720 chris 39
    }
40
 
1767 chris 41
        /*
1720 chris 42
    public void render()
43
    {
1723 chris 44
        Engine.graphics.renderStates.pushModelMatrix();
1751 chris 45
        Engine.graphics.renderStates.model.preMultiply(mLocalTransform);
1723 chris 46
 
1739 chris 47
        //Engine.graphics.getPrimitiveShader().activate(new Vector4(0, 0, 1, 1));
1723 chris 48
 
1720 chris 49
        if (parts != null)
50
        {
51
            for (ModelPart part : parts)
52
            {
53
                part.render();
54
            }
55
        }
1723 chris 56
 
1739 chris 57
        //Engine.graphics.getPrimitiveShader().deactivate();
1723 chris 58
 
59
        Engine.graphics.renderStates.popModelMatrix();
1767 chris 60
    }*/
1720 chris 61
 
1774 chris 62
        public Matrix4 calcLocalTransform()
63
        {
64
                Matrix4 local = Matrix4.createIdentity();
65
                if (mScale != null)
66
                        local.multiply(Matrix4.createScale(mScale));
67
                if (mRotation != null)
68
                        local.multiply(mRotation.toMatrix());
69
                if (mTranslation != null)
70
                        local.multiply(Matrix4.createTranslation(mTranslation));
71
                return local;
72
                /*nodes[newNodeIndex].getLocalTransform().identity();
73
                if (nodeData.scale != null)
74
                {
75
                        nodes[newNodeIndex].getLocalTransform().multiply(Matrix4.createScale(nodeData.scale[0], nodeData.scale[1], nodeData.scale[2]));
76
                }
77
                if (nodeData.rotation != null)
78
                {
79
                        Quaternion q = new Quaternion(nodeData.rotation);
80
                        nodes[newNodeIndex].getLocalTransform().multiply(q.toMatrix());
81
                }
82
                if (nodeData.translation != null)
83
                {
84
                        nodes[newNodeIndex].getLocalTransform().multiply(Matrix4.createTranslation(nodeData.translation[0], nodeData.translation[1], nodeData.translation[2]));
85
                }*/
86
        }
87
 
1720 chris 88
    // Getters/Setters==================================================================================
89
 
90
    public final String getName() { return mName; }
91
 
1774 chris 92
    /*public final Matrix4 getLocalTransform() { return mLocalTransform; }
93
    public final void setLocalTransform(Matrix4 transform) { mLocalTransform = transform; }*/
94
        public final Vector3 getTranslation() { return mTranslation; }
95
        public final void setTranslation(Vector3 v) { mTranslation = v; }
1751 chris 96
 
1774 chris 97
        public final Quaternion getRotation() { return mRotation; }
98
        public final void setRotation(Quaternion q) { mRotation = q; }
99
 
100
        public final Vector3 getScale() { return mScale; }
101
        public final void setScale(Vector3 v) { mScale = v; }
102
 
1752 chris 103
    public final Matrix4 getGlobalTransform() { return mGlobalTransform; }
104
    public final void setGlobalTransform(Matrix4 transform) { mGlobalTransform = transform; }
105
 
1751 chris 106
    public final int getParentIndex() { return mParentIndex; }
1720 chris 107
}