fixed global to local position method

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent e07f30e3f7
commit d430bc6fc0
3 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ namespace vb01{
Vector3 Bone::getModelSpacePos(){
Vector3 modelSpacePos = Vector3::VEC_ZERO;
Bone *rootBone = skeleton->getRootBone();
vector<Node*> boneHierarchy = getAncestors(this, rootBone->getParent());
vector<Node*> boneHierarchy = getAncestors(this, rootBone);
while(!boneHierarchy.empty()){
int id = boneHierarchy.size() - 1;
+3 -1
View File
@@ -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);
}
+2
View File
@@ -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;
}