mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
beginning of IK test
This commit is contained in:
+7
-61
@@ -1,13 +1,14 @@
|
||||
#include"skeleton.h"
|
||||
#include"animation.h"
|
||||
#include"animationController.h"
|
||||
#include"box.h"
|
||||
#include "skeleton.h"
|
||||
#include "animation.h"
|
||||
#include "animationController.h"
|
||||
#include "box.h"
|
||||
#include "ikSolver.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Skeleton::Skeleton(string name){
|
||||
this->name=name;
|
||||
this->name = name;
|
||||
controller = new AnimationController(this);
|
||||
}
|
||||
|
||||
@@ -36,66 +37,11 @@ namespace vb01{
|
||||
boneIkPos[i] = boneChain[i]->getModelSpacePos();
|
||||
}
|
||||
|
||||
calculateFabrik(chainLength, boneChain, boneIkPos, targetPos);
|
||||
IkSolver::calculateFabrik(chainLength, boneChain, boneIkPos, targetPos);
|
||||
|
||||
transformIkChain(chainLength, boneChain, boneIkPos, targetPos);
|
||||
}
|
||||
|
||||
void Skeleton::calculateFabrik(int chainLength, Bone *boneChain[], Vector3 boneIkPos[], Vector3 targetPos){
|
||||
float sumLengths = 0;
|
||||
for(int i = 0; i < chainLength; i++)
|
||||
sumLengths += boneChain[i]->getLength();
|
||||
|
||||
Vector3 startPos = boneChain[chainLength - 1]->getModelSpacePos();
|
||||
if(startPos.getDistanceFrom(targetPos) < sumLengths){
|
||||
int numIterations = 500;
|
||||
|
||||
for(int i = 0 ; i < numIterations; i++){
|
||||
bool backward = (i % 2 == 0);
|
||||
for(int j = 0; j < chainLength; j++){
|
||||
int boneId;
|
||||
float length;
|
||||
Vector3 ikPos, bonePos, fromBoneToIkPos;
|
||||
if(backward){
|
||||
boneId = j;
|
||||
length = boneChain[boneId]->getLength();
|
||||
ikPos = (j == 0 ? targetPos : boneIkPos[boneId - 1]);
|
||||
}
|
||||
else{
|
||||
boneId = chainLength - 1 - j;
|
||||
if(j == 0){
|
||||
ikPos = startPos;
|
||||
length = 0;
|
||||
}
|
||||
else{
|
||||
ikPos = boneIkPos[boneId + 1];
|
||||
length = boneChain[boneId + 0]->getLength();
|
||||
}
|
||||
}
|
||||
bonePos = boneIkPos[boneId];
|
||||
fromBoneToIkPos = (ikPos - bonePos).norm();
|
||||
boneIkPos[boneId] = ikPos - fromBoneToIkPos * length;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
Vector3 startToEndVec = (targetPos - startPos).norm();
|
||||
for(int i = chainLength - 1; i >= 0; i--){
|
||||
float length;
|
||||
Vector3 bonePos;
|
||||
if(i == chainLength - 1){
|
||||
length = 0;
|
||||
bonePos = boneIkPos[i];
|
||||
}
|
||||
else{
|
||||
length = boneChain[i]->getLength();
|
||||
bonePos = boneIkPos[i + 1];
|
||||
}
|
||||
boneIkPos[i] = bonePos + startToEndVec * length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Skeleton::transformIkChain(int chainLength, Bone *boneChain[], Vector3 boneIkPos[], Vector3 targetPos){
|
||||
Node *rootBone = getRootBone()->getParent();
|
||||
float boneAngles[chainLength];
|
||||
|
||||
Reference in New Issue
Block a user