~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAFramework/src/COLLADAFWNode.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of COLLADAFramework.
 
5
 
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "COLLADAFWStableHeaders.h"
 
12
#include "COLLADAFWNode.h"
 
13
#include "COLLADAFWRotate.h"
 
14
#include "COLLADAFWTranslate.h"
 
15
#include "COLLADAFWScale.h"
 
16
#include "COLLADAFWMatrix.h"
 
17
 
 
18
#include "Math/COLLADABUMathMatrix4.h"
 
19
 
 
20
 
 
21
namespace COLLADAFW
 
22
{
 
23
 
 
24
        //--------------------------------------------------------------------
 
25
    Node::Node(const UniqueId& uniqueId) 
 
26
                :ObjectTemplate< COLLADA_TYPE::NODE >( uniqueId ) 
 
27
                , mType( Node::NODE )
 
28
        {
 
29
        }
 
30
 
 
31
 
 
32
        //--------------------------------------------------------------------
 
33
        Node::~Node()
 
34
        {
 
35
        }
 
36
 
 
37
        //--------------------------------------------------------------------
 
38
        void Node::getTransformationMatrix(COLLADABU::Math::Matrix4& transformationMatrix) const
 
39
        {
 
40
                transformationMatrix = COLLADABU::Math::Matrix4::IDENTITY;
 
41
 
 
42
                for ( size_t i = 0, count = mTransformations.getCount(); i < count; ++i )
 
43
                {
 
44
                        Transformation* transform = mTransformations[i];
 
45
 
 
46
                        switch ( transform->getTransformationType() )
 
47
                        {
 
48
                        case Transformation::ROTATE:
 
49
                                {
 
50
                                        Rotate* rotate = (Rotate*)transform;
 
51
                    COLLADABU::Math::Vector3 axis = rotate->getRotationAxis();
 
52
                                        axis.normalise();
 
53
                                        double angle = rotate->getRotationAngle();
 
54
                                        transformationMatrix = transformationMatrix * COLLADABU::Math::Matrix4(COLLADABU::Math::Quaternion(COLLADABU::Math::Utils::degToRad(angle), axis));
 
55
                                        break;
 
56
                                }
 
57
                        case Transformation::TRANSLATE:
 
58
                                {
 
59
                                        Translate* translate = (Translate*)transform;
 
60
                                        const COLLADABU::Math::Vector3& translation = translate->getTranslation();
 
61
                                        COLLADABU::Math::Matrix4 translationMatrix;
 
62
                                        translationMatrix.makeTrans(translation);
 
63
                                        transformationMatrix = transformationMatrix * translationMatrix;
 
64
                                        break;
 
65
                                }
 
66
                        case Transformation::SCALE:
 
67
                                {
 
68
                                        Scale* scale = (Scale*)transform;
 
69
                                        const COLLADABU::Math::Vector3& scaleVector = scale->getScale();
 
70
                                        COLLADABU::Math::Matrix4 scaleMatrix;
 
71
                                        scaleMatrix.makeScale(scaleVector);
 
72
                                        transformationMatrix = transformationMatrix * scaleMatrix;
 
73
                                        break;
 
74
                                }
 
75
                        case Transformation::MATRIX:
 
76
                                {
 
77
                                        Matrix* matrix = (Matrix*)transform;
 
78
                                        transformationMatrix = transformationMatrix * matrix->getMatrix();
 
79
                                        break;
 
80
                                }
 
81
                        case Transformation::LOOKAT:
 
82
                                break; /** @TODO unhandled case */
 
83
                        case Transformation::SKEW:
 
84
                                break; /** @TODO unhandled case */
 
85
                        }
 
86
 
 
87
                }
 
88
        }
 
89
 
 
90
    //--------------------------------------------------------------------
 
91
    COLLADABU::Math::Matrix4 Node::getTransformationMatrix() const
 
92
    {
 
93
        COLLADABU::Math::Matrix4 matrix;
 
94
        getTransformationMatrix(matrix);
 
95
        return matrix;
 
96
    }
 
97
 
 
98
} // namespace COLLADAFW