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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-10 23:43:45 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-10 23:43:45 +0300
commit37e4a311b0ad9da7177e50620efc3561e2dd7045 (patch)
tree8aea2cc851ab828ee040d601ed4c776283fd639a /source/blender/ikplugin
parent4617bb68ba4b1c5ab459673fffd98bf7203bb4f2 (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/blender/ikplugin')
-rw-r--r--source/blender/ikplugin/intern/ikplugin_api.c2
-rw-r--r--source/blender/ikplugin/intern/iksolver_plugin.c84
-rw-r--r--source/blender/ikplugin/intern/itasc_plugin.cpp74
3 files changed, 80 insertions, 80 deletions
diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c
index f106302dbaf..c6ff6377f00 100644
--- a/source/blender/ikplugin/intern/ikplugin_api.c
+++ b/source/blender/ikplugin/intern/ikplugin_api.c
@@ -31,7 +31,7 @@
#include "BIK_api.h"
#include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
#include "BKE_armature.h"
#include "BKE_utildefines.h"
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c
index 6eb1ef56094..e9378a7e12b 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.c
+++ b/source/blender/ikplugin/intern/iksolver_plugin.c
@@ -31,7 +31,7 @@
#include "BIK_api.h"
#include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
#include "BKE_armature.h"
#include "BKE_constraint.h"
@@ -179,10 +179,10 @@ static void make_dmats(bPoseChannel *pchan)
{
if (pchan->parent) {
float iR_parmat[4][4];
- Mat4Invert(iR_parmat, pchan->parent->pose_mat);
- Mat4MulMat4(pchan->chan_mat, pchan->pose_mat, iR_parmat); // delta mat
+ invert_m4_m4(iR_parmat, pchan->parent->pose_mat);
+ mul_m4_m4m4(pchan->chan_mat, pchan->pose_mat, iR_parmat); // delta mat
}
- else Mat4CpyMat4(pchan->chan_mat, pchan->pose_mat);
+ else copy_m4_m4(pchan->chan_mat, pchan->pose_mat);
}
/* applies IK matrix to pchan, IK is done separated */
@@ -192,19 +192,19 @@ static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[][3]) // nr = t
{
float vec[3], ikmat[4][4];
- Mat4CpyMat3(ikmat, ik_mat);
+ copy_m4_m3(ikmat, ik_mat);
if (pchan->parent)
- Mat4MulSerie(pchan->pose_mat, pchan->parent->pose_mat, pchan->chan_mat, ikmat, NULL, NULL, NULL, NULL, NULL);
+ mul_serie_m4(pchan->pose_mat, pchan->parent->pose_mat, pchan->chan_mat, ikmat, NULL, NULL, NULL, NULL, NULL);
else
- Mat4MulMat4(pchan->pose_mat, ikmat, pchan->chan_mat);
+ mul_m4_m4m4(pchan->pose_mat, ikmat, pchan->chan_mat);
/* calculate head */
VECCOPY(pchan->pose_head, pchan->pose_mat[3]);
/* calculate tail */
VECCOPY(vec, pchan->pose_mat[1]);
- VecMulf(vec, pchan->bone->length);
- VecAddf(pchan->pose_tail, pchan->pose_head, vec);
+ mul_v3_fl(vec, pchan->bone->length);
+ add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec);
pchan->flag |= POSE_DONE;
}
@@ -266,41 +266,41 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
IK_SetParent(seg, parent);
/* get the matrix that transforms from prevbone into this bone */
- Mat3CpyMat4(R_bonemat, pchan->pose_mat);
+ copy_m3_m4(R_bonemat, pchan->pose_mat);
/* gather transformations for this IK segment */
if (pchan->parent)
- Mat3CpyMat4(R_parmat, pchan->parent->pose_mat);
+ copy_m3_m4(R_parmat, pchan->parent->pose_mat);
else
- Mat3One(R_parmat);
+ unit_m3(R_parmat);
/* bone offset */
if (pchan->parent && (a > 0))
- VecSubf(start, pchan->pose_head, pchan->parent->pose_tail);
+ sub_v3_v3v3(start, pchan->pose_head, pchan->parent->pose_tail);
else
/* only root bone (a = 0) has no parent */
start[0]= start[1]= start[2]= 0.0f;
/* change length based on bone size */
- length= bone->length*VecLength(R_bonemat[1]);
+ length= bone->length*len_v3(R_bonemat[1]);
/* compute rest basis and its inverse */
- Mat3CpyMat3(rest_basis, bone->bone_mat);
- Mat3CpyMat3(irest_basis, bone->bone_mat);
- Mat3Transp(irest_basis);
+ copy_m3_m3(rest_basis, bone->bone_mat);
+ copy_m3_m3(irest_basis, bone->bone_mat);
+ transpose_m3(irest_basis);
/* compute basis with rest_basis removed */
- Mat3Inv(iR_parmat, R_parmat);
- Mat3MulMat3(full_basis, iR_parmat, R_bonemat);
- Mat3MulMat3(basis, irest_basis, full_basis);
+ invert_m3_m3(iR_parmat, R_parmat);
+ mul_m3_m3m3(full_basis, iR_parmat, R_bonemat);
+ mul_m3_m3m3(basis, irest_basis, full_basis);
/* basis must be pure rotation */
- Mat3Ortho(basis);
+ normalize_m3(basis);
/* transform offset into local bone space */
- Mat3Ortho(iR_parmat);
- Mat3MulVecfl(iR_parmat, start);
+ normalize_m3(iR_parmat);
+ mul_m3_v3(iR_parmat, start);
IK_SetTransform(seg, start, rest_basis, basis, length);
@@ -332,13 +332,13 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
/* transform goal by parent mat, so this rotation is not part of the
segment's basis. otherwise rotation limits do not work on the
local transform of the segment itself. */
- Mat4CpyMat4(rootmat, pchan->parent->pose_mat);
+ copy_m4_m4(rootmat, pchan->parent->pose_mat);
else
- Mat4One(rootmat);
+ unit_m4(rootmat);
VECCOPY(rootmat[3], pchan->pose_head);
- Mat4MulMat4 (imat, rootmat, ob->obmat);
- Mat4Invert (goalinv, imat);
+ mul_m4_m4m4(imat, rootmat, ob->obmat);
+ invert_m4_m4(goalinv, imat);
for (target=tree->targets.first; target; target=target->next) {
float polepos[3];
@@ -352,10 +352,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
get_constraint_target_matrix(scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
/* and set and transform goal */
- Mat4MulMat4(goal, rootmat, goalinv);
+ mul_m4_m4m4(goal, rootmat, goalinv);
VECCOPY(goalpos, goal[3]);
- Mat3CpyMat4(goalrot, goal);
+ copy_m3_m4(goalrot, goal);
/* same for pole vector target */
if(data->poletar) {
@@ -366,7 +366,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
break;
}
else {
- Mat4MulMat4(goal, rootmat, goalinv);
+ mul_m4_m4m4(goal, rootmat, goalinv);
VECCOPY(polepos, goal[3]);
poleconstrain= 1;
@@ -392,9 +392,9 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
pchan= tree->pchan[target->tip];
/* end effector in world space */
- Mat4CpyMat4(end_pose, pchan->pose_mat);
+ copy_m4_m4(end_pose, pchan->pose_mat);
VECCOPY(end_pose[3], pchan->pose_tail);
- Mat4MulSerie(world_pose, goalinv, ob->obmat, end_pose, 0, 0, 0, 0, 0);
+ mul_serie_m4(world_pose, goalinv, ob->obmat, end_pose, 0, 0, 0, 0, 0);
/* blend position */
goalpos[0]= fac*goalpos[0] + mfac*world_pose[3][0];
@@ -402,10 +402,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
goalpos[2]= fac*goalpos[2] + mfac*world_pose[3][2];
/* blend rotation */
- Mat3ToQuat(goalrot, q1);
- Mat4ToQuat(world_pose, q2);
- QuatInterpol(q, q1, q2, mfac);
- QuatToMat3(q, goalrot);
+ mat3_to_quat( q1,goalrot);
+ mat4_to_quat( q2,world_pose);
+ interp_qt_qtqt(q, q1, q2, mfac);
+ quat_to_mat3( goalrot,q);
}
iktarget= iktree[target->tip];
@@ -449,7 +449,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
float trans[3], length;
IK_GetTranslationChange(iktree[a], trans);
- length= pchan->bone->length*VecLength(pchan->pose_mat[1]);
+ length= pchan->bone->length*len_v3(pchan->pose_mat[1]);
ikstretch[a]= (length == 0.0)? 1.0: (trans[1]+length)/length;
}
@@ -458,14 +458,14 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
stretch= (parentstretch == 0.0)? 1.0: ikstretch[a]/parentstretch;
- VecMulf(tree->basis_change[a][0], stretch);
- VecMulf(tree->basis_change[a][1], stretch);
- VecMulf(tree->basis_change[a][2], stretch);
+ mul_v3_fl(tree->basis_change[a][0], stretch);
+ mul_v3_fl(tree->basis_change[a][1], stretch);
+ mul_v3_fl(tree->basis_change[a][2], stretch);
}
if(resultblend && resultinf!=1.0f) {
- Mat3One(identity);
- Mat3BlendMat3(tree->basis_change[a], identity,
+ unit_m3(identity);
+ blend_m3_m3m3(tree->basis_change[a], identity,
tree->basis_change[a], resultinf);
}
diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp
index 3dcb9e462b9..05de0a0775b 100644
--- a/source/blender/ikplugin/intern/itasc_plugin.cpp
+++ b/source/blender/ikplugin/intern/itasc_plugin.cpp
@@ -46,7 +46,7 @@
extern "C" {
#include "BIK_api.h"
#include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
#include "BKE_global.h"
#include "BKE_armature.h"
@@ -550,15 +550,15 @@ static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Fram
if (pchan->parent) {
pchan = pchan->parent;
float chanmat[4][4];
- Mat4CpyMat4(chanmat, pchan->pose_mat);
+ copy_m4_m4(chanmat, pchan->pose_mat);
VECCOPY(chanmat[3], pchan->pose_tail);
- Mat4MulSerie(restmat, target->owner->obmat, chanmat, target->eeRest, NULL, NULL, NULL, NULL, NULL);
+ mul_serie_m4(restmat, target->owner->obmat, chanmat, target->eeRest, NULL, NULL, NULL, NULL, NULL);
}
else {
- Mat4MulMat4(restmat, target->eeRest, target->owner->obmat);
+ mul_m4_m4m4(restmat, target->eeRest, target->owner->obmat);
}
// blend the target
- Mat4BlendMat4(tarmat, restmat, tarmat, constraint->enforce);
+ blend_m4_m4m4(tarmat, restmat, tarmat, constraint->enforce);
}
next.setValue(&tarmat[0][0]);
return true;
@@ -577,15 +577,15 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame&
if (pchan->parent) {
pchan = pchan->parent;
float chanmat[4][4];
- Mat4CpyMat4(chanmat, pchan->pose_mat);
+ copy_m4_m4(chanmat, pchan->pose_mat);
VECCOPY(chanmat[3], pchan->pose_tail);
// save the base as a frame too so that we can compute deformation
// after simulation
ikscene->baseFrame.setValue(&chanmat[0][0]);
- Mat4MulMat4(rootmat, chanmat, ikscene->blArmature->obmat);
+ mul_m4_m4m4(rootmat, chanmat, ikscene->blArmature->obmat);
}
else {
- Mat4CpyMat4(rootmat, ikscene->blArmature->obmat);
+ copy_m4_m4(rootmat, ikscene->blArmature->obmat);
ikscene->baseFrame = iTaSC::F_identity;
}
next.setValue(&rootmat[0][0]);
@@ -598,7 +598,7 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame&
float mat[4][4]; // temp matrix
bKinematicConstraint* poledata = (bKinematicConstraint*)ikscene->polarConstraint->data;
- Mat4Invert(imat, rootmat);
+ invert_m4_m4(imat, rootmat);
// polar constraint imply only one target
IK_Target *iktarget = ikscene->targets[0];
// root channel from which we take the bone initial orientation
@@ -607,11 +607,11 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame&
// get polar target matrix in world space
get_constraint_target_matrix(ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0);
// convert to armature space
- Mat4MulMat4(polemat, mat, imat);
+ mul_m4_m4m4(polemat, mat, imat);
// get the target in world space (was computed before as target object are defined before base object)
iktarget->target->getPose().getValue(mat[0]);
// convert to armature space
- Mat4MulMat4(goalmat, mat, imat);
+ mul_m4_m4m4(goalmat, mat, imat);
// take position of target, polar target, end effector, in armature space
KDL::Vector goalpos(goalmat[3]);
KDL::Vector polepos(polemat[3]);
@@ -787,16 +787,16 @@ static bool joint_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintV
if (chan->rotmode > 0) {
/* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */
- EulOToMat3(chan->eul, chan->rotmode, rmat);
+ eulO_to_mat3( rmat,chan->eul, chan->rotmode);
}
else if (chan->rotmode == ROT_MODE_AXISANGLE) {
/* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
- AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat);
+ axis_angle_to_mat3( rmat,&chan->quat[1], chan->quat[0]);
}
else {
/* quats are normalised before use to eliminate scaling issues */
- NormalQuat(chan->quat);
- QuatToMat3(chan->quat, rmat);
+ normalize_qt(chan->quat);
+ quat_to_mat3( rmat,chan->quat);
}
KDL::Rotation jointRot(
rmat[0][0], rmat[1][0], rmat[2][0],
@@ -977,26 +977,26 @@ static void convert_pose(IK_Scene *ikscene)
int a, joint;
// assume uniform scaling and take Y scale as general scale for the armature
- scale = VecLength(ikscene->blArmature->obmat[1]);
+ scale = len_v3(ikscene->blArmature->obmat[1]);
rot = &ikscene->jointArray(0);
for(joint=a=0, ikchan = ikscene->channels; a<ikscene->numchan && joint<ikscene->numjoint; ++a, ++ikchan) {
pchan= ikchan->pchan;
bone= pchan->bone;
if (pchan->parent) {
- Mat4One(bmat);
- Mat4MulMat43(bmat, pchan->parent->pose_mat, bone->bone_mat);
+ unit_m4(bmat);
+ mul_m4_m4m3(bmat, pchan->parent->pose_mat, bone->bone_mat);
} else {
- Mat4CpyMat4(bmat, bone->arm_mat);
+ copy_m4_m4(bmat, bone->arm_mat);
}
- Mat4Invert(rmat, bmat);
- Mat4MulMat4(bmat, pchan->pose_mat, rmat);
- Mat4Ortho(bmat);
+ invert_m4_m4(rmat, bmat);
+ mul_m4_m4m4(bmat, pchan->pose_mat, rmat);
+ normalize_m4(bmat);
boneRot.setValue(bmat[0]);
GetJointRotation(boneRot, ikchan->jointType, rot);
if (ikchan->jointType & IK_TRANSY) {
// compute actual length
- rot[ikchan->ndof-1] = VecLenf(pchan->pose_tail, pchan->pose_head) * scale;
+ rot[ikchan->ndof-1] = len_v3v3(pchan->pose_tail, pchan->pose_head) * scale;
}
rot += ikchan->ndof;
joint += ikchan->ndof;
@@ -1014,7 +1014,7 @@ static void rest_pose(IK_Scene *ikscene)
int a, joint;
// assume uniform scaling and take Y scale as general scale for the armature
- scale = VecLength(ikscene->blArmature->obmat[1]);
+ scale = len_v3(ikscene->blArmature->obmat[1]);
// rest pose is 0
KDL::SetToZero(ikscene->jointArray);
// except for transY joints
@@ -1103,7 +1103,7 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan)
std::vector<double> weights;
double weight[3];
// assume uniform scaling and take Y scale as general scale for the armature
- float scale = VecLength(ob->obmat[1]);
+ float scale = len_v3(ob->obmat[1]);
// build the array of joints corresponding to the IK chain
convert_channels(ikscene, tree);
if (ingame) {
@@ -1379,12 +1379,12 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan)
// it has a parent, get the pose matrix from it
float baseFrame[4][4];
pchan = pchan->parent;
- Mat4CpyMat4(baseFrame, pchan->bone->arm_mat);
+ copy_m4_m4(baseFrame, pchan->bone->arm_mat);
// move to the tail and scale to get rest pose of armature base
- VecCopyf(baseFrame[3], pchan->bone->arm_tail);
- Mat4Invert(invBaseFrame, baseFrame);
+ copy_v3_v3(baseFrame[3], pchan->bone->arm_tail);
+ invert_m4_m4(invBaseFrame, baseFrame);
} else {
- Mat4One(invBaseFrame);
+ unit_m4(invBaseFrame);
}
// finally add the constraint
for (t=0; t<ikscene->targets.size(); t++) {
@@ -1403,10 +1403,10 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan)
bonelen /= bonecnt;
// store the rest pose of the end effector to compute enforce target
- Mat4CpyMat4(mat, pchan->bone->arm_mat);
- VecCopyf(mat[3], pchan->bone->arm_tail);
+ copy_m4_m4(mat, pchan->bone->arm_mat);
+ copy_v3_v3(mat[3], pchan->bone->arm_tail);
// get the rest pose relative to the armature base
- Mat4MulMat4(iktarget->eeRest, mat, invBaseFrame);
+ mul_m4_m4m4(iktarget->eeRest, mat, invBaseFrame);
iktarget->eeBlend = (!ikscene->polarConstraint && condata->type==CONSTRAINT_IK_COPYPOSE) ? true : false;
// use target_callback to make sure the initPose includes enforce coefficient
target_callback(iTaSC::Timestamp(), iTaSC::F_identity, initPose, iktarget);
@@ -1660,13 +1660,13 @@ static void execute_scene(Scene* blscene, IK_Scene* ikscene, bItasc* ikparam, fl
VECCOPY(pchan->pose_tail, pchan->pose_mat[3]);
// shift to head
VECCOPY(yaxis, pchan->pose_mat[1]);
- VecMulf(yaxis, length);
- VecSubf(pchan->pose_mat[3], pchan->pose_mat[3], yaxis);
+ mul_v3_fl(yaxis, length);
+ sub_v3_v3v3(pchan->pose_mat[3], pchan->pose_mat[3], yaxis);
VECCOPY(pchan->pose_head, pchan->pose_mat[3]);
// add scale
- VecMulf(pchan->pose_mat[0], scale);
- VecMulf(pchan->pose_mat[1], scale);
- VecMulf(pchan->pose_mat[2], scale);
+ mul_v3_fl(pchan->pose_mat[0], scale);
+ mul_v3_fl(pchan->pose_mat[1], scale);
+ mul_v3_fl(pchan->pose_mat[2], scale);
}
if (i<ikscene->numchan) {
// big problem