diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-11-10 23:43:45 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-11-10 23:43:45 +0300 |
commit | 37e4a311b0ad9da7177e50620efc3561e2dd7045 (patch) | |
tree | 8aea2cc851ab828ee040d601ed4c776283fd639a /source/gameengine/Converter | |
parent | 4617bb68ba4b1c5ab459673fffd98bf7203bb4f2 (diff) |
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
Diffstat (limited to 'source/gameengine/Converter')
12 files changed, 67 insertions, 67 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 6f3036d8e09..1325c80a6d4 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -46,7 +46,7 @@ #include "DNA_scene_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "MT_Matrix4x4.h" #include "BKE_utildefines.h" #include "FloatValue.h" @@ -539,8 +539,8 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel, if(pchan) { VECCOPY (pchan->loc, matrix[3]); - Mat4ToSize(matrix, pchan->size); - Mat4ToQuat(matrix, pchan->quat); + mat4_to_size( pchan->size,matrix); + mat4_to_quat( pchan->quat,matrix); } } else { diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp index b70a0aa79e7..603dfc370b4 100644 --- a/source/gameengine/Converter/BL_ArmatureActuator.cpp +++ b/source/gameengine/Converter/BL_ArmatureActuator.cpp @@ -33,7 +33,7 @@ #include "BKE_constraint.h" #include "BL_ArmatureActuator.h" #include "BL_ArmatureObject.h" -#include "BLI_arithb.h" +#include "BLI_math.h" /** * This class is the conversion of the Pose channel constraint. diff --git a/source/gameengine/Converter/BL_ArmatureChannel.cpp b/source/gameengine/Converter/BL_ArmatureChannel.cpp index 71e91735b24..2444390c9f3 100644 --- a/source/gameengine/Converter/BL_ArmatureChannel.cpp +++ b/source/gameengine/Converter/BL_ArmatureChannel.cpp @@ -34,7 +34,7 @@ #include "BL_ArmatureChannel.h" #include "BL_ArmatureObject.h" #include "BL_ArmatureConstraint.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #ifndef DISABLE_PYTHON @@ -211,19 +211,19 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str float norm; double sa, ca; // get rotation in armature space - Mat3CpyMat4(pose_mat, pchan->pose_mat); - Mat3Ortho(pose_mat); + copy_m3_m4(pose_mat, pchan->pose_mat); + normalize_m3(pose_mat); if (pchan->parent) { // bone has a parent, compute the rest pose of the bone taking actual pose of parent - Mat3IsMat3MulMat4(rest_mat, pchan->bone->bone_mat, pchan->parent->pose_mat); - Mat3Ortho(rest_mat); + mul_m3_m3m4(rest_mat, pchan->bone->bone_mat, pchan->parent->pose_mat); + normalize_m3(rest_mat); } else { // otherwise, the bone matrix in armature space is the rest pose - Mat3CpyMat4(rest_mat, pchan->bone->arm_mat); + copy_m3_m4(rest_mat, pchan->bone->arm_mat); } // remove the rest pose to get the joint movement - Mat3Transp(rest_mat); - Mat3MulMat3(joint_mat, rest_mat, pose_mat); + transpose_m3(rest_mat); + mul_m3_m3m3(joint_mat, rest_mat, pose_mat); joints[0] = joints[1] = joints[2] = 0.f; // returns a 3 element list that gives corresponding joint int flag = 0; @@ -237,35 +237,35 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str case 0: // fixed joint break; case 1: // X only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[1] = joints[2] = 0.f; break; case 2: // Y only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = joints[2] = 0.f; break; case 3: // X+Y - Mat3ToEulO(joint_mat, joints, EULER_ORDER_ZYX); + mat3_to_eulO( joints, EULER_ORDER_ZYX,joint_mat); joints[2] = 0.f; break; case 4: // Z only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = joints[1] = 0.f; break; case 5: // X+Z // decompose this as an equivalent rotation vector in X/Z plane joints[0] = joint_mat[1][2]; joints[2] = -joint_mat[1][0]; - norm = Normalize(joints); + norm = normalize_v3(joints); if (norm < FLT_EPSILON) { norm = (joint_mat[1][1] < 0.f) ? M_PI : 0.f; } else { norm = acos(joint_mat[1][1]); } - VecMulf(joints, norm); + mul_v3_fl(joints, norm); break; case 6: // Y+Z - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = 0.f; break; case 7: // X+Y+Z @@ -273,14 +273,14 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str joints[0] = (joint_mat[1][2]-joint_mat[2][1])*0.5f; joints[1] = (joint_mat[2][0]-joint_mat[0][2])*0.5f; joints[2] = (joint_mat[0][1]-joint_mat[1][0])*0.5f; - sa = VecLength(joints); + sa = len_v3(joints); ca = (joint_mat[0][0]+joint_mat[1][1]+joint_mat[1][1]-1.0f)*0.5f; if (sa > FLT_EPSILON) { norm = atan2(sa,ca)/sa; } else { if (ca < 0.0) { norm = M_PI; - VecMulf(joints,0.f); + mul_v3_fl(joints,0.f); if (joint_mat[0][0] > 0.f) { joints[0] = 1.0f; } else if (joint_mat[1][1] > 0.f) { @@ -292,7 +292,7 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str norm = 0.0; } } - VecMulf(joints,norm); + mul_v3_fl(joints,norm); break; } return newVectorObject(joints, 3, Py_NEW, NULL); @@ -327,45 +327,45 @@ int BL_ArmatureChannel::py_attr_set_joint_rotation(void *self_v, const struct KX flag |= 2; if (!(pchan->ikflag & BONE_IK_NO_ZDOF)) flag |= 4; - QuatOne(quat); + unit_qt(quat); switch (flag) { case 0: // fixed joint break; case 1: // X only joints[1] = joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 2: // Y only joints[0] = joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 3: // X+Y joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_ZYX, quat); + eulO_to_quat( quat,joints, EULER_ORDER_ZYX); break; case 4: // Z only joints[0] = joints[1] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 5: // X+Z // X and Z are components of an equivalent rotation axis joints[1] = 0; - VecRotToQuat(joints, VecLength(joints), quat); + axis_angle_to_quat( quat,joints, len_v3(joints)); break; case 6: // Y+Z joints[0] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 7: // X+Y+Z // equivalent axis - VecRotToQuat(joints, VecLength(joints), quat); + axis_angle_to_quat( quat,joints, len_v3(joints)); break; } if (pchan->rotmode > 0) { - QuatToEulO(quat, joints, pchan->rotmode); - VecCopyf(pchan->eul, joints); + quat_to_eulO( joints, pchan->rotmode,quat); + copy_v3_v3(pchan->eul, joints); } else - QuatCopy(pchan->quat, quat); + copy_qt_qt(pchan->quat, quat); return PY_SET_ATTR_SUCCESS; } diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.cpp b/source/gameengine/Converter/BL_ArmatureConstraint.cpp index 42581b63ec4..c37f963b82f 100644 --- a/source/gameengine/Converter/BL_ArmatureConstraint.cpp +++ b/source/gameengine/Converter/BL_ArmatureConstraint.cpp @@ -34,7 +34,7 @@ #include "DNA_action_types.h" #include "BL_ArmatureConstraint.h" #include "BL_ArmatureObject.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #ifndef DISABLE_PYTHON @@ -82,12 +82,12 @@ BL_ArmatureConstraint::BL_ArmatureConstraint( m_blendsubtarget = (subtarget) ? subtarget->GetBlenderObject() : NULL; m_pose = m_subpose = NULL; if (m_blendtarget) { - Mat4CpyMat4(m_blendmat, m_blendtarget->obmat); + copy_m4_m4(m_blendmat, m_blendtarget->obmat); if (m_blendtarget->type == OB_ARMATURE) m_pose = m_blendtarget->pose; } if (m_blendsubtarget) { - Mat4CpyMat4(m_blendsubmat, m_blendsubtarget->obmat); + copy_m4_m4(m_blendsubmat, m_blendsubtarget->obmat); if (m_blendsubtarget->type == OB_ARMATURE) m_subpose = m_blendsubtarget->pose; } @@ -198,12 +198,12 @@ void BL_ArmatureConstraint::RestoreTarget() { if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) { if (m_blendtarget) { - Mat4CpyMat4(m_blendtarget->obmat, m_blendmat); + copy_m4_m4(m_blendtarget->obmat, m_blendmat); if (m_pose) m_blendtarget->pose = m_pose; } if (m_blendsubtarget && m_subtarget) { - Mat4CpyMat4(m_blendsubtarget->obmat, m_blendsubmat); + copy_m4_m4(m_blendsubtarget->obmat, m_blendsubmat); if (m_subpose) m_blendsubtarget->pose = m_subpose; } diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index a6066adc03e..f62a6b84fca 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -32,7 +32,7 @@ #include "KX_BlenderSceneConverter.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BIK_api.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -158,13 +158,13 @@ void game_blend_poses(bPose *dst, bPose *src, float srcweight/*, short mode*/) QUATCOPY(dquat, dchan->quat); QUATCOPY(squat, schan->quat); if (mode==ACTSTRIPMODE_BLEND) - QuatInterpol(dchan->quat, dquat, squat, srcweight); + interp_qt_qtqt(dchan->quat, dquat, squat, srcweight); else { - QuatMulFac(squat, srcweight); - QuatMul(dchan->quat, dquat, squat); + mul_fac_qt_fl(squat, srcweight); + mul_qt_qtqt(dchan->quat, dquat, squat); } - NormalQuat(dchan->quat); + normalize_qt(dchan->quat); } for (i=0; i<3; i++) { diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 881f4cc2517..6e26182a23f 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -135,7 +135,7 @@ #include "BKE_mesh.h" #include "MT_Point3.h" -#include "BLI_arithb.h" +#include "BLI_math.h" extern "C" { #include "BKE_customdata.h" @@ -805,15 +805,15 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, if(mface->flag & ME_SMOOTH) { float n0[3], n1[3], n2[3], n3[3]; - NormalShortToFloat(n0, mvert[mface->v1].no); - NormalShortToFloat(n1, mvert[mface->v2].no); - NormalShortToFloat(n2, mvert[mface->v3].no); + normal_short_to_float_v3(n0, mvert[mface->v1].no); + normal_short_to_float_v3(n1, mvert[mface->v2].no); + normal_short_to_float_v3(n2, mvert[mface->v3].no); no0 = n0; no1 = n1; no2 = n2; if(mface->v4) { - NormalShortToFloat(n3, mvert[mface->v4].no); + normal_short_to_float_v3(n3, mvert[mface->v4].no); no3 = n3; } } @@ -821,9 +821,9 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, float fno[3]; if(mface->v4) - CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co, fno); + normal_quad_v3( fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co); else - CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, fno); + normal_tri_v3( fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co); no0 = no1 = no2 = no3 = MT_Vector3(fno); } diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp index d7012abe316..0abc344a844 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.cpp +++ b/source/gameengine/Converter/BL_MeshDeformer.cpp @@ -47,7 +47,7 @@ #include "GEN_Map.h" #include "STR_HashedString.h" -#include "BLI_arithb.h" +#include "BLI_math.h" bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*) { @@ -176,7 +176,7 @@ void BL_MeshDeformer::RecalcNormals() fnor[0]= n1[1]*n2[2] - n1[2]*n2[1]; fnor[1]= n1[2]*n2[0] - n1[0]*n2[2]; fnor[2]= n1[0]*n2[1] - n1[1]*n2[0]; - Normalize(fnor); + normalize_v3(fnor); /* add to vertices for smooth normals */ float *vn1 = m_transnors[v1.getOrigIndex()]; diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp index 80165548ff2..0cdca74fea5 100644 --- a/source/gameengine/Converter/BL_ModifierDeformer.cpp +++ b/source/gameengine/Converter/BL_ModifierDeformer.cpp @@ -64,7 +64,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 0af6556f285..4171bfcc58e 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -46,7 +46,7 @@ #include "DNA_armature_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "MT_Matrix4x4.h" #include "BKE_utildefines.h" #include "FloatValue.h" diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index 125e91e0e0a..9b6d3f61705 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -58,7 +58,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index f166a7252ad..ecc45b2da1a 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -52,7 +52,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS @@ -70,7 +70,7 @@ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj, m_poseApplied(false), m_recalcNormal(true) { - Mat4CpyMat4(m_obmat, bmeshobj->obmat); + copy_m4_m4(m_obmat, bmeshobj->obmat); }; BL_SkinDeformer::BL_SkinDeformer( @@ -93,7 +93,7 @@ BL_SkinDeformer::BL_SkinDeformer( // that takes an object as parameter and not a mesh. The object matrice is used // in the calculation, so we must use the matrix of the original object to // simulate a pure replacement of the mesh. - Mat4CpyMat4(m_obmat, bmeshobj_new->obmat); + copy_m4_m4(m_obmat, bmeshobj_new->obmat); } BL_SkinDeformer::~BL_SkinDeformer() @@ -194,14 +194,14 @@ bool BL_SkinDeformer::UpdateInternal(bool shape_applied) m_armobj->ApplyPose(); // save matrix first - Mat4CpyMat4(obmat, m_objMesh->obmat); + copy_m4_m4(obmat, m_objMesh->obmat); // set reference matrix - Mat4CpyMat4(m_objMesh->obmat, m_obmat); + copy_m4_m4(m_objMesh->obmat, m_obmat); armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, ARM_DEF_VGROUP, NULL, NULL ); // restore matrix - Mat4CpyMat4(m_objMesh->obmat, obmat); + copy_m4_m4(m_objMesh->obmat, obmat); #ifdef __NLA_DEFNORMALS if (m_recalcNormal) diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 26b4514061c..8e7560cdcbd 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -66,7 +66,7 @@ #include "DNA_world_types.h" #include "BKE_main.h" -#include "BLI_arithb.h" +#include "BLI_math.h" extern "C" { @@ -617,8 +617,8 @@ extern "C" //XXX void testhandles_ipocurve(struct IpoCurve *icu); void insert_vert_icu(struct IpoCurve *, float, float, short); float eval_icu(struct IpoCurve *icu, float ipotime); - //void Mat3ToEul(float tmat[][3], float *eul); - void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot); + //void mat3_to_eul( float *eul,float tmat[][3]); + void mat3_to_compatible_eul( float *eul, float *oldrot,float mat[][3]); } IpoCurve* findIpoCurve(IpoCurve* first, const char* searchName) @@ -742,7 +742,7 @@ void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){ if (blenderobject->type==OB_ARMATURE) continue; float eu[3]; - Mat4ToEul(blenderobject->obmat,eu); + mat4_to_eul(eu,blenderobject->obmat); MT_Point3 pos = MT_Point3( blenderobject->obmat[3][0], blenderobject->obmat[3][1], @@ -847,8 +847,8 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) for (int c=0;c<3;c++) tmat[r][c] = orn[c][r]; - // Mat3ToEul(tmat, eulerAngles); // better to use Mat3ToCompatibleEul - Mat3ToCompatibleEul(tmat, eulerAngles, eulerAnglesOld); + // mat3_to_eul( eulerAngles,tmat); // better to use Mat3ToCompatibleEul + mat3_to_compatible_eul( eulerAngles, eulerAnglesOld,tmat); //eval_icu for(int x = 0; x < 3; x++) |