Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TransformReader.cpp « collada « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04711775f14fbb51d8054dbd8574c0f593fc8217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
 *
 * ***** END GPL LICENSE BLOCK *****
 */
/* COLLADABU_ASSERT, may be able to remove later */
#include "COLLADABUPlatform.h"

#include "TransformReader.h"

TransformReader::TransformReader(UnitConverter* conv) : unit_converter(conv) {}

void TransformReader::get_node_mat(float mat[][4], COLLADAFW::Node *node, std::map<COLLADAFW::UniqueId, Animation> *animation_map, Object *ob)
{
	float cur[4][4];
	float copy[4][4];

	unit_m4(mat);
	
	for (unsigned int i = 0; i < node->getTransformations().getCount(); i++) {

		COLLADAFW::Transformation *tm = node->getTransformations()[i];
		COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();

		switch(type) {
		case COLLADAFW::Transformation::TRANSLATE:
			dae_translate_to_mat4(tm, cur);
			break;
		case COLLADAFW::Transformation::ROTATE:
			dae_rotate_to_mat4(tm, cur);
			break;
		case COLLADAFW::Transformation::SCALE:
			dae_scale_to_mat4(tm, cur);
			break;
		case COLLADAFW::Transformation::MATRIX:
			dae_matrix_to_mat4(tm, cur);
			break;
		case COLLADAFW::Transformation::LOOKAT:
		case COLLADAFW::Transformation::SKEW:
			fprintf(stderr, "LOOKAT and SKEW transformations are not supported yet.\n");
			break;
		}

		copy_m4_m4(copy, mat);
		mul_m4_m4m4(mat, cur, copy);

		if (animation_map) {
			// AnimationList that drives this Transformation
			const COLLADAFW::UniqueId& anim_list_id = tm->getAnimationList();
		
			// store this so later we can link animation data with ob
			Animation anim = {ob, node, tm};
			(*animation_map)[anim_list_id] = anim;
		}
	}
}

void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
	COLLADAFW::Rotate *ro = (COLLADAFW::Rotate*)tm;
	COLLADABU::Math::Vector3& axis = ro->getRotationAxis();
	float angle = (float)(ro->getRotationAngle() * M_PI / 180.0f);
	float ax[] = {axis[0], axis[1], axis[2]};
	// float quat[4];
	// axis_angle_to_quat(quat, axis, angle);
	// quat_to_mat4(m, quat);
	axis_angle_to_mat4(m, ax, angle);
}

void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
	COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm;
	COLLADABU::Math::Vector3& t = tra->getTranslation();

	unit_m4(m);

	m[3][0] = (float)t[0];
	m[3][1] = (float)t[1];
	m[3][2] = (float)t[2];
}

void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
	COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale();
	float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
	size_to_mat4(m, size);
}

void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
	unit_converter->dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix*)tm)->getMatrix());
}

void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
{
	dae_vector3_to_v3(((COLLADAFW::Translate*)tm)->getTranslation(), v);
}

void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
{
	dae_vector3_to_v3(((COLLADAFW::Scale*)tm)->getScale(), v);
}

void TransformReader::dae_vector3_to_v3(const COLLADABU::Math::Vector3 &v3, float v[3])
{
	v[0] = v3.x;
	v[1] = v3.y;
	v[2] = v3.z;
}