simplified global - local transformation methods

fixed position bug when posing bones
initial IK method
This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 7ed0eed7e2
commit 3ee5555652
9 changed files with 204 additions and 78 deletions
+21 -10
View File
@@ -5,13 +5,22 @@ using namespace std;
namespace vb01{
Bone::Bone(string name, float length, Vector3 pos,Quaternion rot, Vector3 scale) : Node(pos,rot,scale,name){
this->name=name;
this->length=length;
this->name = name;
this->length = length;
}
void Bone::lookAt(Vector3 newDir, Vector3 newUp, Node *par){
Node::lookAt(newDir,newUp,par);
for(int i=0;i<3;i++)
Node::lookAt(newDir, newUp, par);
for(int i = 0; i < 3; i++)
this->initAxis[i] = globalAxis[i];
restPos = pos;
restRot = orientation;
restScale = scale;
}
void Bone::lookAt(Vector3 newDir, Node *par){
Node::lookAt(newDir, par);
for(int i = 0; i < 3; i++)
this->initAxis[i] = globalAxis[i];
restPos = pos;
restRot = orientation;
@@ -21,7 +30,7 @@ namespace vb01{
Vector3 Bone::getModelSpacePos(){
Vector3 modelSpacePos = Vector3::VEC_ZERO;
Bone *rootBone = skeleton->getRootBone();
vector<Node*> boneHierarchy = getAncestors(this, rootBone);
vector<Node*> boneHierarchy = getAncestors(this, rootBone->getParent());
while(!boneHierarchy.empty()){
int id = boneHierarchy.size() - 1;
@@ -43,19 +52,21 @@ namespace vb01{
}
void Bone::setPosePos(Vector3 p){
this->posePos=p;
Vector3 parentSpacePosePos=parent->globalToLocalPosition(localToGlobalPosition(p));
//setPosition(parentSpacePosePos);
this->posePos = p;
setPosition(restPos);
Vector3 parentSpacePosePos = parent->globalToLocalPosition(localToGlobalPosition(p));
setPosition(parentSpacePosePos);
}
void Bone::setPoseRot(Quaternion r){
this->poseRot=r;
this->poseRot = r;
setOrientation(r);
Quaternion parentSpacePoseRot = parent->globalToLocalOrientation(localToGlobalOrientation(r));
setOrientation(parentSpacePoseRot);
}
void Bone::setPoseScale(Vector3 s){
this->poseScale=s;
this->poseScale = s;
//setScale(restScale+poseScale);
}
}