diff --git a/go.bat b/go.bat index d7e3aa5a3bc498943bb7be2de003d0850fa70a24..a78ad592878a94df635a54351d4701affdd6f649 100644 --- a/go.bat +++ b/go.bat @@ -1,3 +1,4 @@ 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 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 diff --git a/nif_math.cpp b/nif_math.cpp index c1bf2b611eaf71d20fee9265d7e3337f9049d220..0286a129fd2dbb30d63646430b9cbd065661c196 100644 --- a/nif_math.cpp +++ b/nif_math.cpp @@ -342,11 +342,15 @@ Matrix44 RotateMatrix44( Vector3 const & axis, float angle) { 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; + 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); + 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) { @@ -355,7 +359,7 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) { bMatrix = RotateMatrix44(axis, theta); } else { float updown; - if (DotProduct(target, nor) > 0.0) updown = 1.0f; + if (DotProduct(target, nor) > 0.0f) updown = 1.0f; else updown = -1.0f; bMatrix = Matrix44( updown, 0.0f, 0.0f, 0.0f, @@ -365,8 +369,8 @@ Matrix44 BoneToMatrix44( Vector3 const & bone_vec, float roll ) { }; rMatrix = RotateMatrix44(nor, roll); result = MultMatrix44(bMatrix, rMatrix); - result[3][0] = bone_vec.x; - result[3][1] = bone_vec.y; - result[3][2] = bone_vec.z; + 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 52504446e49249e9f46ee71b9ad4be33ec9bff28..e2753f191fb0cdc5e545b0138102bf2f73137d32 100644 --- a/nif_math.h +++ b/nif_math.h @@ -62,6 +62,6 @@ 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_vec, float roll ); +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 89a16f3046c3620cef51f71d5530331b49476d1e..d56518ca8c9ede3e85da48dd62657638c9f42a20 100644 --- a/niflib.h +++ b/niflib.h @@ -426,7 +426,7 @@ struct Matrix44 { }; // 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 { float r, g, b, a;