From c46a6de93187babd3df5a074fb684818fa749273 Mon Sep 17 00:00:00 2001 From: Chris Want Date: Thu, 24 Apr 2003 23:13:58 +0000 Subject: [PATCH] A fix for bug #96 (MNME's armature bug). The result of a crossproduct was not checked for a zero vector. --- source/blender/blenkernel/intern/armature.c | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 5fb87e58ecc..e05e222284b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -887,11 +887,27 @@ void make_boneMatrixvr (float outmatrix[][4],float delta[3], float roll) /* Find Axis & Amount for bone matrix*/ Crossf (axis,target,nor); - Normalise (axis); - theta=(float) acos (Inpf (target,nor)); - /* Make Bone matrix*/ - VecRotToMat3(axis, theta, bMatrix); + if (Inpf(axis,axis) > 0.0000000000001) { + /* if nor is *not* a multiple of target ... */ + Normalise (axis); + theta=(float) acos (Inpf (target,nor)); + + /* Make Bone matrix*/ + VecRotToMat3(axis, theta, bMatrix); + } + else { + /* if nor is a multiple of target ... */ + float updown; + + /* point same direction, or opposite? */ + updown = ( Inpf (target,nor) > 0 ) ? 1.0 : -1.0; + + /* I think this should work ... */ + bMatrix[0][0]=updown; bMatrix[0][1]=0.0; bMatrix[0][2]=0.0; + bMatrix[1][0]=0.0; bMatrix[1][1]=updown; bMatrix[1][2]=0.0; + bMatrix[2][0]=0.0; bMatrix[2][1]=0.0; bMatrix[2][2]=1.0; + } /* Make Roll matrix*/ VecRotToMat3(nor, roll, rMatrix);