Create raw bone hierarchy

This commit is contained in:
hodasemi 2018-06-09 10:16:18 +02:00
parent 3b55561ce2
commit 6d2fbf0421
4 changed files with 100 additions and 46 deletions

View file

@ -53,7 +53,14 @@
"utility": "cpp",
"variant": "cpp",
"algorithm": "cpp",
"new": "cpp"
"new": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"__config": "cpp",
"__nullptr": "cpp"
},
"editor.formatOnSave": true
}

View file

@ -21,6 +21,8 @@ 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();
@ -28,6 +30,8 @@ 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();
@ -35,7 +39,52 @@ void IKViewer::base_changed(Bone* b)
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*/
// get list of bones in order of endeffector to base
std::vector<Bone *> bones;
Bone *current_bone = endeffector;
while (1)
{
bones.emplace_back(current_bone);
// break if we reached base bone
if (current_bone == base)
break;
// set next bone in hierarchy
current_bone = current_bone->get_parent();
}
for (Bone *bone : bones)
{
// TODO: calculate and add transforms to queue
std::shared_ptr<Transform> transform;
kinematic_chain.emplace_front(transform);
}
}
void IKViewer::optimize()
@ -95,15 +144,17 @@ void IKViewer::set_target_position_2d(int x, int y)
post_redraw();
}
bool IKViewer::handle(event &e)
{
if (e.get_kind() == EID_MOUSE) {
if (e.get_kind() == EID_MOUSE)
{
cgv::gui::mouse_event me = (cgv::gui::mouse_event &)e;
switch (me.get_action()) {
switch (me.get_action())
{
case MA_PRESS:
if (me.get_button() == MB_LEFT_BUTTON && me.get_modifiers() == EM_CTRL) {
if (me.get_button() == MB_LEFT_BUTTON && me.get_modifiers() == EM_CTRL)
{
modifying = true;
set_target_position_2d(me.get_x(), me.get_y());
return true;
@ -119,7 +170,8 @@ bool IKViewer::handle(event& e)
return true;
}
break;
default: break;
default:
break;
}
}
return false;

View file

@ -41,8 +41,6 @@ private:
Mat4 current_endeffector_matrix; //transform from base to endeffector
Mat4 current_base_matrix; //transform from global origin to base
unsigned int max_iterations;
std::list<std::shared_ptr<Transform>> kinematic_chain;
@ -61,4 +59,3 @@ public:
// Draw the scene
void draw(context &c);
};

View file

@ -20,13 +20,11 @@ struct Initializer
Initializer()
{
data = new DataStore();
register_object(base_ptr(new SkeletonViewer(data)), "");
/*register_object(base_ptr(new IKViewer(data)), "");*/
register_object(base_ptr(new IKViewer(data)), "");
/*register_object(base_ptr(new SkinnedMeshViewer(data)), "");*/
}