diff --git a/nif_math.cpp b/nif_math.cpp index 0286a129fd2dbb30d63646430b9cbd065661c196..99a177ade43c3a017cb7c38e55fd0d86e2212e0b 100644 --- a/nif_math.cpp +++ b/nif_math.cpp @@ -298,79 +298,3 @@ void QuatToEuler( Quaternion const & quat, ostream & out ) { << " Bank: " << b << endl; } - -float Length(Vector3 const & a) { - return sqrt(a.x*a.x + a.y*a.y + a.z*a.z); -} - -Vector3 Normalize(Vector3 const & a) { - float l = Length(a); - return Vector3(a.x/l, a.y/l, a.z/l); -} - -float DotProduct(Vector3 const & a, Vector3 const & b) { - return a.x*b.x + a.y*b.y + a.z*b.z; -} - -Vector3 CrossProduct(Vector3 const & a, Vector3 const & b) { - return Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); -} - -float Angle(Vector3 const & a, Vector3 const & b) { - float pi = 3.141592653589793f; - float s = Length(a) * Length(b); - float f = DotProduct(a, b) / s; - if (f >= 1.0f) return 0.0f; - if (f <= -1.0f) return pi / 2.0f; - return atan(-f / sqrt(1.0f - f * f)) + pi / 2.0f; -} - -Matrix44 RotateMatrix44( Vector3 const & axis, float angle) { - float vx = axis.x; - float vy = axis.y; - float vz = axis.z; - float vx2 = vx * vx; - float vy2 = vy * vy; - float vz2 = vz * vz; - float cs = cos(angle); - float sn = sin(angle); - float co1 = 1.0f - cs; - return Matrix44( - vx2 * co1 + cs, vx * vy * co1 + vz * sn, vz * vx * co1 - vy * sn, 0.0f, - vx * vy * co1 - vz * sn, vy2 * co1 + cs, vy * vz * co1 + vx * sn, 0.0f, - vz * vx * co1 + vy * sn, vy * vz * co1 - vx * sn, vz2 * co1 + cs, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); -} - -Matrix44 BoneToMatrix44( Vector3 const & bone_head, Vector3 const & bone_tail, float roll, float parent_len ) { - float theta; - Vector3 bone_vec; - bone_vec.x = bone_tail.x - bone_head.x; - bone_vec.y = bone_tail.y - bone_head.y; - bone_vec.z = bone_tail.z - bone_head.z; - Matrix44 bMatrix, rMatrix, result; - - Vector3 target(1.0f, 0.0f, 0.0f); // X-aligned - Vector3 nor = Normalize(bone_vec); - Vector3 axis = CrossProduct(target, nor); - if (DotProduct(axis, axis) > 0.0000000000001) { - axis = Normalize(axis); - theta = acos(DotProduct(target, nor)); - bMatrix = RotateMatrix44(axis, theta); - } else { - float updown; - if (DotProduct(target, nor) > 0.0f) updown = 1.0f; - else updown = -1.0f; - bMatrix = Matrix44( - updown, 0.0f, 0.0f, 0.0f, - 0.0f, updown, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); - }; - rMatrix = RotateMatrix44(nor, roll); - result = MultMatrix44(bMatrix, rMatrix); - result[3][0] = bone_head.x + parent_len; // X-aligned - result[3][1] = bone_head.y; - result[3][2] = bone_head.z; - return result; -} diff --git a/nif_math.h b/nif_math.h index e2753f191fb0cdc5e545b0138102bf2f73137d32..8d30a88724e90da0300bd6b5d5f448e0493a7943 100644 --- a/nif_math.h +++ b/nif_math.h @@ -58,10 +58,5 @@ void SetIdentity44( Matrix44 & m ); void PrintMatrix33( Matrix33 const & m, ostream & out ); void PrintMatrix44( Matrix44 const & m, ostream & out ); Quaternion MatrixToQuat( Matrix33 const & m ); -Vector3 Normalize(Vector3 const & a); -float DotProduct(Vector3 const & a, Vector3 const & b); -Vector3 CrossProduct(Vector3 const & a, Vector3 const & b); // = MultVector3 -float Angle(Vector3 const & a, Vector3 const & b); -Matrix44 BoneToMatrix44( Vector3 const & bone_head, Vector3 const & bone_tail, float roll, float parent_len ); #endif diff --git a/niflib.h b/niflib.h index d56518ca8c9ede3e85da48dd62657638c9f42a20..d930335ad4445c0aabfa47e609c67103694d9c7b 100644 --- a/niflib.h +++ b/niflib.h @@ -425,9 +425,6 @@ struct Matrix44 { } }; -// Bone calculation helper function from the nif_math module. -Matrix44 BoneToMatrix44( Vector3 const & bone_head, Vector3 const & bone_tail, float roll, float parent_len ); - struct Color { float r, g, b, a; Color() {}