From 37e4a311b0ad9da7177e50620efc3561e2dd7045 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 10 Nov 2009 20:43:45 +0000 Subject: Math Lib * Convert all code to use new functions. * Branch maintainers may want to skip this commit, and run this conversion script instead, if they use a lot of math functions in new code: http://www.pasteall.org/9052/python --- source/blender/collada/DocumentExporter.cpp | 32 +++++++-------- source/blender/collada/DocumentImporter.cpp | 62 ++++++++++++++--------------- source/blender/collada/collada_internal.h | 10 ++--- 3 files changed, 52 insertions(+), 52 deletions(-) (limited to 'source/blender/collada') diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index b626635d021..fac7b2c882a 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -37,7 +37,7 @@ extern "C" #include "BKE_image.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #include "BLI_listbase.h" @@ -87,7 +87,7 @@ extern "C" // This function assumes that quat is normalized. // The following document was used as reference: // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm -void QuatToAxisAngle(float *q, float *axis, float *angle) +void quat_to_axis_angle( float *axis, float *angle,float *q) { // quat to axis angle *angle = 2 * acos(q[0]); @@ -666,11 +666,11 @@ protected: if (parent_mat) { float invpar[4][4]; - Mat4Invert(invpar, parent_mat); - Mat4MulMat4(local, mat, invpar); + invert_m4_m4(invpar, parent_mat); + mul_m4_m4m4(local, mat, invpar); } else { - Mat4CpyMat4(local, mat); + copy_m4_m4(local, mat); } TransformBase::decompose(local, loc, rot, size); @@ -681,9 +681,9 @@ protected: float axis[3]; float angle; double angle_deg; - EulToQuat(rot, quat); - NormalQuat(quat); - QuatToAxisAngle(quat, axis, &angle); + eul_to_quat( quat,rot); + normalize_qt(quat); + quat_to_axis_angle( axis, &angle,quat); angle_deg = angle * 180.0f / M_PI; node.addRotate(axis[0], axis[1], axis[2], angle_deg); */ @@ -901,12 +901,12 @@ private: bPoseChannel *parchan = get_pose_channel(ob_arm->pose, bone->parent->name); float invpar[4][4]; - Mat4Invert(invpar, parchan->pose_mat); - Mat4MulMat4(mat, pchan->pose_mat, invpar); + invert_m4_m4(invpar, parchan->pose_mat); + mul_m4_m4m4(mat, pchan->pose_mat, invpar); } else { // get world-space from armature-space - Mat4MulMat4(mat, pchan->pose_mat, ob_arm->obmat); + mul_m4_m4m4(mat, pchan->pose_mat, ob_arm->obmat); } TransformWriter::add_node_transform(node, mat, NULL); @@ -1059,9 +1059,9 @@ private: float inv_bind_mat[4][4]; // make world-space matrix, pose_mat is armature-space - Mat4MulMat4(world, pchan->pose_mat, ob_arm->obmat); + mul_m4_m4m4(world, pchan->pose_mat, ob_arm->obmat); - Mat4Invert(mat, world); + invert_m4_m4(mat, world); converter.mat4_to_dae(inv_bind_mat, mat); source.appendValues(inv_bind_mat); @@ -1241,9 +1241,9 @@ public: if (ob->type == OB_MESH && is_skinned_mesh) // for skinned mesh we write obmat in - Mat4One(mat); + unit_m4(mat); else - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); TransformWriter::add_node_transform(node, mat, ob->parent ? ob->parent->obmat : NULL); @@ -2048,7 +2048,7 @@ public: float eul[3]; - QuatToEul(quat, eul); + quat_to_eul( eul,quat); for (int k = 0; k < 3; k++) create_bezt(eulcu[k], frame, eul[k]); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 0aa69d11949..aae1738381f 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -50,7 +50,7 @@ extern "C" #include "BKE_depsgraph.h" #include "BLI_util.h" #include "BKE_displist.h" -#include "BLI_arithb.h" +#include "BLI_math.h" } #include "BKE_armature.h" #include "BKE_mesh.h" @@ -62,7 +62,7 @@ extern "C" #include "BKE_utildefines.h" #include "BKE_action.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_string.h" @@ -186,7 +186,7 @@ public: float cur[4][4]; float copy[4][4]; - Mat4One(mat); + unit_m4(mat); for (int i = 0; i < node->getTransformations().getCount(); i++) { @@ -199,7 +199,7 @@ public: COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm; COLLADABU::Math::Vector3& t = tra->getTranslation(); - Mat4One(cur); + unit_m4(cur); cur[3][0] = (float)t[0]; cur[3][1] = (float)t[1]; cur[3][2] = (float)t[2]; @@ -214,16 +214,16 @@ public: float quat[4]; float rot_copy[3][3]; float mat[3][3]; - AxisAngleToQuat(quat, axis, angle); + axis_angle_to_quat(quat, axis, angle); - QuatToMat4(quat, cur); + quat_to_mat4( cur,quat); } break; case COLLADAFW::Transformation::SCALE: { COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale(); float size[3] = {(float)s[0], (float)s[1], (float)s[2]}; - SizeToMat4(size, cur); + size_to_mat4( cur,size); } break; case COLLADAFW::Transformation::MATRIX: @@ -237,8 +237,8 @@ public: break; } - Mat4CpyMat4(copy, mat); - Mat4MulMat4(mat, cur, copy); + copy_m4_m4(copy, mat); + mul_m4_m4m4(mat, cur, copy); if (animation_map) { // AnimationList that drives this Transformation @@ -346,7 +346,7 @@ private: ob_arm(skin.ob_arm), controller_uid(skin.controller_uid) { - Mat4CpyMat4(bind_shape_matrix, (float (*)[4])skin.bind_shape_matrix); + copy_m4_m4(bind_shape_matrix, (float (*)[4])skin.bind_shape_matrix); transfer_uint_array_data_const(skin.joints_per_vertex, joints_per_vertex); transfer_uint_array_data_const(skin.weight_indices, weight_indices); @@ -438,7 +438,7 @@ private: std::vector::iterator it; for (it = joint_data.begin(); it != joint_data.end(); it++) { if ((*it).joint_uid == uid) { - Mat4CpyMat4(inv_bind_mat, (*it).inv_bind_mat); + copy_m4_m4(inv_bind_mat, (*it).inv_bind_mat); return true; } } @@ -491,8 +491,8 @@ private: // we need armature matrix here... where do we get it from I wonder... // root node/joint? or node with ? float parmat[4][4]; - Mat4One(parmat); - Mat4Invert(ob->parentinv, parmat); + unit_m4(parmat); + invert_m4_m4(ob->parentinv, parmat); // create all vertex groups std::vector::iterator it; @@ -574,7 +574,7 @@ private: if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) { // get original world-space matrix - Mat4Invert(mat, joint_inv_bind_mat); + invert_m4_m4(mat, joint_inv_bind_mat); } // create a bone even if there's no joint data for it (i.e. it has no influence) else { @@ -585,9 +585,9 @@ private: // get world-space if (parent) - Mat4MulMat4(mat, obmat, parent_mat); + mul_m4_m4m4(mat, obmat, parent_mat); else - Mat4CpyMat4(mat, obmat); + copy_m4_m4(mat, obmat); } // TODO rename from Node "name" attrs later @@ -597,21 +597,21 @@ private: if (parent) bone->parent = parent; // set head - VecCopyf(bone->head, mat[3]); + copy_v3_v3(bone->head, mat[3]); // set tail, don't set it to head because 0-length bones are not allowed float vec[3] = {0.0f, 0.5f, 0.0f}; - VecAddf(bone->tail, bone->head, vec); + add_v3_v3v3(bone->tail, bone->head, vec); // set parent tail if (parent && totchild == 1) { - VecCopyf(parent->tail, bone->head); + copy_v3_v3(parent->tail, bone->head); // XXX increase this to prevent "very" small bones? const float epsilon = 0.000001f; // derive leaf bone length - float length = VecLenf(parent->head, parent->tail); + float length = len_v3v3(parent->head, parent->tail); if ((length < leaf_bone_length || totbone == 0) && length > epsilon) { leaf_bone_length = length; } @@ -625,20 +625,20 @@ private: #if 0 // and which row in mat is bone direction float vec[3]; - VecSubf(vec, parent->tail, parent->head); + sub_v3_v3v3(vec, parent->tail, parent->head); #ifdef COLLADA_DEBUG - printvecf("tail - head", vec); - printmatrix4("matrix", parent_mat); + print_v3("tail - head", vec); + print_m4("matrix", parent_mat); #endif for (int i = 0; i < 3; i++) { #ifdef COLLADA_DEBUG char *axis_names[] = {"X", "Y", "Z"}; - printf("%s-axis length is %f\n", axis_names[i], VecLength(parent_mat[i])); + printf("%s-axis length is %f\n", axis_names[i], len_v3(parent_mat[i])); #endif - float angle = VecAngle2(vec, parent_mat[i]); + float angle = angle_v2v2(vec, parent_mat[i]); if (angle < min_angle) { #ifdef COLLADA_DEBUG - printvecf("picking", parent_mat[i]); + print_v3("picking", parent_mat[i]); printf("^ %s axis of %s's matrix\n", axis_names[i], get_dae_name(node)); #endif bone_direction_row = i; @@ -665,7 +665,7 @@ private: LeafBone leaf; leaf.bone = bone; - Mat4CpyMat4(leaf.mat, mat); + copy_m4_m4(leaf.mat, mat); BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name)); leaf_bones.push_back(leaf); @@ -682,10 +682,10 @@ private: // pointing up float vec[3] = {0.0f, 0.0f, 1.0f}; - VecMulf(vec, leaf_bone_length); + mul_v3_fl(vec, leaf_bone_length); - VecCopyf(leaf.bone->tail, leaf.bone->head); - VecAddf(leaf.bone->tail, leaf.bone->head, vec); + copy_v3_v3(leaf.bone->tail, leaf.bone->head); + add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec); } } @@ -2200,7 +2200,7 @@ public: float quat[4]; - EulToQuat(eul, quat); + eul_to_quat( quat,eul); for (int k = 0; k < 4; k++) create_bezt(quatcu[k], frame, quat[k]); diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index c0d74505f72..32c3e7af874 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -39,8 +39,8 @@ public: void mat4_to_dae(float out[][4], float in[][4]) { - Mat4CpyMat4(out, in); - Mat4Transp(out); + copy_m4_m4(out, in); + transpose_m4(out); } void mat4_to_dae_double(double out[][4], float in[][4]) @@ -60,9 +60,9 @@ class TransformBase public: void decompose(float mat[][4], float *loc, float *rot, float *size) { - Mat4ToSize(mat, size); - Mat4ToEul(mat, rot); - VecCopyf(loc, mat[3]); + mat4_to_size( size,mat); + mat4_to_eul( rot,mat); + copy_v3_v3(loc, mat[3]); } }; -- cgit v1.2.3