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

Bone matrix calculation function (Blender helper function) fixed.

parent 786ae3ac
No related branches found
No related tags found
No related merge requests found
rem Windows Niflib Python wrapper compilation script (using the Visual C++ Toolkit & SWIG 1.3.27) rem Windows Niflib Python wrapper compilation script (using the Visual C++ Toolkit & SWIG 1.3.27)
"\Program Files\swigwin-1.3.27\swig.exe" -c++ -python -o py_wrap.cpp pyniflib.i "\Program Files\swigwin-1.3.27\swig.exe" -c++ -python -o py_wrap.cpp pyniflib.i
cl /LD /EHsc /I"\Program Files\Python24\include" /I. /Fe"_niflib.dll" niflib.cpp docsys_extract.cpp NIF_Blocks.cpp NIF_IO.cpp nif_math.cpp py_wrap.cpp "\Program Files\Python24\libs\python24.lib" cl /LD /EHsc /I"\Program Files\Python24\include" /I. /Fe"_niflib.dll" niflib.cpp docsys_extract.cpp NIF_Blocks.cpp NIF_IO.cpp nif_math.cpp py_wrap.cpp "\Program Files\Python24\libs\python24.lib"
rem cl /EHsc /I. /Fe"test.exe" test.cpp niflib.cpp docsys_extract.cpp NIF_Blocks.cpp NIF_IO.cpp nif_math.cpp
...@@ -342,11 +342,15 @@ Matrix44 RotateMatrix44( Vector3 const & axis, float angle) { ...@@ -342,11 +342,15 @@ Matrix44 RotateMatrix44( Vector3 const & axis, float angle) {
0.0f, 0.0f, 0.0f, 1.0f); 0.0f, 0.0f, 0.0f, 1.0f);
} }
Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) { Matrix44 BoneToMatrix44( Vector3 const & bone_head, Vector3 const & bone_tail, float roll, float parent_len ) {
float theta; 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; Matrix44 bMatrix, rMatrix, result;
Vector3 target(1.0f, 0.0f, 0.0f); Vector3 target(1.0f, 0.0f, 0.0f); // X-aligned
Vector3 nor = Normalize(bone_vec); Vector3 nor = Normalize(bone_vec);
Vector3 axis = CrossProduct(target, nor); Vector3 axis = CrossProduct(target, nor);
if (DotProduct(axis, axis) > 0.0000000000001) { if (DotProduct(axis, axis) > 0.0000000000001) {
...@@ -355,7 +359,7 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) { ...@@ -355,7 +359,7 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) {
bMatrix = RotateMatrix44(axis, theta); bMatrix = RotateMatrix44(axis, theta);
} else { } else {
float updown; float updown;
if (DotProduct(target, nor) > 0.0) updown = 1.0f; if (DotProduct(target, nor) > 0.0f) updown = 1.0f;
else updown = -1.0f; else updown = -1.0f;
bMatrix = Matrix44( bMatrix = Matrix44(
updown, 0.0f, 0.0f, 0.0f, updown, 0.0f, 0.0f, 0.0f,
...@@ -365,8 +369,8 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) { ...@@ -365,8 +369,8 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) {
}; };
rMatrix = RotateMatrix44(nor, roll); rMatrix = RotateMatrix44(nor, roll);
result = MultMatrix44(bMatrix, rMatrix); result = MultMatrix44(bMatrix, rMatrix);
result[3][0] = bone_vec.x; result[3][0] = bone_head.x + parent_len; // X-aligned
result[3][1] = bone_vec.y; result[3][1] = bone_head.y;
result[3][2] = bone_vec.z; result[3][2] = bone_head.z;
return result; return result;
} }
...@@ -62,6 +62,6 @@ Vector3 Normalize(Vector3 const & a); ...@@ -62,6 +62,6 @@ Vector3 Normalize(Vector3 const & a);
float DotProduct(Vector3 const & a, Vector3 const & b); float DotProduct(Vector3 const & a, Vector3 const & b);
Vector3 CrossProduct(Vector3 const & a, Vector3 const & b); // = MultVector3 Vector3 CrossProduct(Vector3 const & a, Vector3 const & b); // = MultVector3
float Angle(Vector3 const & a, Vector3 const & b); float Angle(Vector3 const & a, Vector3 const & b);
Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ); Matrix44 BoneToMatrix44( Vector3 const & bone_head, Vector3 const & bone_tail, float roll, float parent_len );
#endif #endif
...@@ -426,7 +426,7 @@ struct Matrix44 { ...@@ -426,7 +426,7 @@ struct Matrix44 {
}; };
// Bone calculation helper function from the nif_math module. // Bone calculation helper function from the nif_math module.
Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ); 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;
......
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