| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  |  * ***** 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 ***** | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-02-27 20:30:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \file blender/collada/TransformReader.cpp
 | 
					
						
							|  |  |  |  *  \ingroup collada | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-12 06:25:04 +00:00
										 |  |  | /* COLLADABU_ASSERT, may be able to remove later */ | 
					
						
							|  |  |  | #include "COLLADABUPlatform.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "TransformReader.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-20 16:43:48 +00:00
										 |  |  | TransformReader::TransformReader(UnitConverter *conv) : unit_converter(conv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* pass */ | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void TransformReader::get_node_mat(float mat[4][4], COLLADAFW::Node *node, std::map<COLLADAFW::UniqueId, Animation> *animation_map, Object *ob) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	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(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 		switch (type) { | 
					
						
							| 
									
										
										
										
											2011-06-25 07:23:23 +00:00
										 |  |  | 			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; | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		copy_m4_m4(copy, mat); | 
					
						
							| 
									
										
										
											
												Math lib: matrix multiplication order fix for two functions that were
inconsistent with similar functions & math notation:
mul_m4_m4m4(R, B, A) => mult_m4_m4m4(R, A, B)
mul_m3_m3m4(R, B, A) => mult_m3_m3m4(R, A, B)
For branch maintainers, it should be relatively simple to fix things manually,
it's also possible run this script after merging to do automatic replacement:
http://www.pasteall.org/27459/python
											
										 
											2011-12-16 19:53:12 +00:00
										 |  |  | 		mult_m4_m4m4(mat, copy, cur); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4]) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	COLLADAFW::Rotate *ro = (COLLADAFW::Rotate *)tm; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 	COLLADABU::Math::Vector3& axis = ro->getRotationAxis(); | 
					
						
							| 
									
										
										
										
											2011-09-17 09:43:51 +00:00
										 |  |  | 	const float angle = (float)DEG2RAD(ro->getRotationAngle()); | 
					
						
							| 
									
										
										
										
											2012-12-02 13:35:33 +00:00
										 |  |  | 	const float ax[] = {(float)axis[0], (float)axis[1], (float)axis[2]}; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 	// float quat[4];
 | 
					
						
							|  |  |  | 	// axis_angle_to_quat(quat, axis, angle);
 | 
					
						
							|  |  |  | 	// quat_to_mat4(m, quat);
 | 
					
						
							|  |  |  | 	axis_angle_to_mat4(m, ax, angle); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4]) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	COLLADAFW::Translate *tra = (COLLADAFW::Translate *)tm; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 	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]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[4][4]) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale *)tm)->getScale(); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 	float size[3] = {(float)s[0], (float)s[1], (float)s[2]}; | 
					
						
							|  |  |  | 	size_to_mat4(m, size); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[4][4]) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	unit_converter->dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix *)tm)->getMatrix()); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	dae_vector3_to_v3(((COLLADAFW::Translate *)tm)->getTranslation(), v); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	dae_vector3_to_v3(((COLLADAFW::Scale *)tm)->getScale(), v); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:49:39 +00:00
										 |  |  | } |