Fix base_matrix update
This commit is contained in:
parent
593dd3509f
commit
9be7af9e33
1 changed files with 26 additions and 45 deletions
|
@ -22,8 +22,6 @@ IKViewer::IKViewer(DataStore *data)
|
|||
|
||||
void IKViewer::endeffector_changed(Bone *b)
|
||||
{
|
||||
std::cout << "endeffector changed!" << std::endl;
|
||||
|
||||
calculate_kinematic_chain(data->get_base(), data->get_endeffector());
|
||||
|
||||
post_redraw();
|
||||
|
@ -31,8 +29,6 @@ void IKViewer::endeffector_changed(Bone *b)
|
|||
|
||||
void IKViewer::base_changed(Bone *b)
|
||||
{
|
||||
std::cout << "base changed!" << std::endl;
|
||||
|
||||
calculate_kinematic_chain(data->get_base(), data->get_endeffector());
|
||||
|
||||
post_redraw();
|
||||
|
@ -53,55 +49,19 @@ int IKViewer::find_element(std::vector<Bone *> &v, Bone *element)
|
|||
|
||||
void IKViewer::calculate_kinematic_chain(Bone *base, Bone *endeffector)
|
||||
{
|
||||
std::cout << "calculate_kinematic_chain" << std::endl;
|
||||
|
||||
if (base)
|
||||
std::cout << "Base bone: " << base->get_name() << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << "no base set" << std::endl;
|
||||
std::cout << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (endeffector)
|
||||
std::cout << "End bone: " << endeffector->get_name() << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << "no endeffector set" << std::endl;
|
||||
std::cout << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
/*Task 3.1: Calculate kinematic chain*/
|
||||
kinematic_chain.clear();
|
||||
|
||||
this->base = base;
|
||||
this->endeffector = endeffector;
|
||||
|
||||
// get list of bones in order of endeffector to base
|
||||
std::vector<Bone *> endeffector_tree;
|
||||
std::vector<Bone *> base_tree;
|
||||
|
||||
// gather all bones from endeffector to root
|
||||
Bone *current_bone = endeffector;
|
||||
|
||||
while (1)
|
||||
{
|
||||
endeffector_tree.emplace_back(current_bone);
|
||||
|
||||
// break if we reached base bone
|
||||
if (current_bone->get_parent() == nullptr)
|
||||
break;
|
||||
|
||||
// set next bone in hierarchy
|
||||
current_bone = current_bone->get_parent();
|
||||
}
|
||||
if (!base)
|
||||
return;
|
||||
|
||||
// gather all bones from base to root
|
||||
current_bone = base;
|
||||
std::vector<Bone *> base_tree;
|
||||
|
||||
Bone *current_bone = base;
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -137,6 +97,27 @@ void IKViewer::calculate_kinematic_chain(Bone *base, Bone *endeffector)
|
|||
current_base_matrix = current_base_matrix * transform->calculate_matrix();
|
||||
}
|
||||
|
||||
if (!endeffector)
|
||||
return;
|
||||
|
||||
// get list of bones in order of endeffector to base
|
||||
std::vector<Bone *> endeffector_tree;
|
||||
|
||||
// gather all bones from endeffector to root
|
||||
current_bone = endeffector;
|
||||
|
||||
while (1)
|
||||
{
|
||||
endeffector_tree.emplace_back(current_bone);
|
||||
|
||||
// break if we reached base bone
|
||||
if (current_bone->get_parent() == nullptr)
|
||||
break;
|
||||
|
||||
// set next bone in hierarchy
|
||||
current_bone = current_bone->get_parent();
|
||||
}
|
||||
|
||||
// add all transform from endeffector to common ancestor and to reverse base
|
||||
|
||||
// state == 0 means, iterating through endeffector_tree
|
||||
|
|
Loading…
Reference in a new issue