diff --git a/bone.cpp b/bone.cpp index 504ba7c..a144170 100644 --- a/bone.cpp +++ b/bone.cpp @@ -30,7 +30,7 @@ namespace vb01{ Vector3 Bone::getModelSpacePos(){ Vector3 modelSpacePos = Vector3::VEC_ZERO; Bone *rootBone = skeleton->getRootBone(); - vector boneHierarchy = getAncestors(this, rootBone->getParent()); + vector boneHierarchy = getAncestors(this, rootBone); while(!boneHierarchy.empty()){ int id = boneHierarchy.size() - 1; diff --git a/node.cpp b/node.cpp index b1aded9..16c41e3 100755 --- a/node.cpp +++ b/node.cpp @@ -220,6 +220,8 @@ namespace vb01{ } Vector3 Node::globalToLocalPosition(Vector3 globalPos){ + Vector3 currentGlobalPos = localToGlobalPosition(Vector3::VEC_ZERO); + mat3 mat; mat[0][0]=globalAxis[0].x; mat[1][0]=globalAxis[0].y; @@ -232,7 +234,7 @@ namespace vb01{ mat[2][2]=globalAxis[2].z; mat=inverse(mat); - vec3 local = vec3(globalPos.x, globalPos.y, globalPos.z) * mat; + vec3 local = vec3(globalPos.x - currentGlobalPos.x, globalPos.y - currentGlobalPos.y, globalPos.z - currentGlobalPos.z) * mat; return Vector3(local.x, local.y, local.z); } diff --git a/skeleton.cpp b/skeleton.cpp index 2f60abc..ef840bd 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -108,6 +108,8 @@ namespace vb01{ rotAxis = Vector3::VEC_I; } + //rotAxis = (boneChain[i]->getInitAxis(0) * rotAxis.x + boneChain[i]->getInitAxis(1) * rotAxis.y + boneChain[i]->getInitAxis(2) * rotAxis.z).norm(); + boneAngles[i] = angle; axis[i] = rotAxis; }