2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAFramework.
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
11
#include "COLLADAFWStableHeaders.h"
12
#include "COLLADAFWNode.h"
13
#include "COLLADAFWRotate.h"
14
#include "COLLADAFWTranslate.h"
15
#include "COLLADAFWScale.h"
16
#include "COLLADAFWMatrix.h"
18
#include "Math/COLLADABUMathMatrix4.h"
24
//--------------------------------------------------------------------
25
Node::Node(const UniqueId& uniqueId)
26
:ObjectTemplate< COLLADA_TYPE::NODE >( uniqueId )
32
//--------------------------------------------------------------------
37
//--------------------------------------------------------------------
38
void Node::getTransformationMatrix(COLLADABU::Math::Matrix4& transformationMatrix) const
40
transformationMatrix = COLLADABU::Math::Matrix4::IDENTITY;
42
for ( size_t i = 0, count = mTransformations.getCount(); i < count; ++i )
44
Transformation* transform = mTransformations[i];
46
switch ( transform->getTransformationType() )
48
case Transformation::ROTATE:
50
Rotate* rotate = (Rotate*)transform;
51
COLLADABU::Math::Vector3 axis = rotate->getRotationAxis();
53
double angle = rotate->getRotationAngle();
54
transformationMatrix = transformationMatrix * COLLADABU::Math::Matrix4(COLLADABU::Math::Quaternion(COLLADABU::Math::Utils::degToRad(angle), axis));
57
case Transformation::TRANSLATE:
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;
66
case Transformation::SCALE:
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;
75
case Transformation::MATRIX:
77
Matrix* matrix = (Matrix*)transform;
78
transformationMatrix = transformationMatrix * matrix->getMatrix();
81
case Transformation::LOOKAT:
82
break; /** @TODO unhandled case */
83
case Transformation::SKEW:
84
break; /** @TODO unhandled case */
90
//--------------------------------------------------------------------
91
COLLADABU::Math::Matrix4 Node::getTransformationMatrix() const
93
COLLADABU::Math::Matrix4 matrix;
94
getTransformationMatrix(matrix);
98
} // namespace COLLADAFW