Skip to content
Snippets Groups Projects
Commit d9ccdfed authored by Amorilia's avatar Amorilia
Browse files

Removed BoneToMatrix44 helper functions. (They will be implemented in Python...

Removed BoneToMatrix44 helper functions. (They will be implemented in Python in the Blender exporter.)
parent 1377fcb4
No related branches found
No related tags found
No related merge requests found
...@@ -298,79 +298,3 @@ void QuatToEuler( Quaternion const & quat, ostream & out ) { ...@@ -298,79 +298,3 @@ void QuatToEuler( Quaternion const & quat, ostream & out ) {
<< " Bank: " << b << endl; << " 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;
}
...@@ -58,10 +58,5 @@ void SetIdentity44( Matrix44 & m ); ...@@ -58,10 +58,5 @@ void SetIdentity44( Matrix44 & m );
void PrintMatrix33( Matrix33 const & m, ostream & out ); void PrintMatrix33( Matrix33 const & m, ostream & out );
void PrintMatrix44( Matrix44 const & m, ostream & out ); void PrintMatrix44( Matrix44 const & m, ostream & out );
Quaternion MatrixToQuat( Matrix33 const & m ); 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 #endif
...@@ -425,9 +425,6 @@ struct Matrix44 { ...@@ -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 { struct Color {
float r, g, b, a; float r, g, b, a;
Color() {} Color() {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment