Finish first task
This commit is contained in:
parent
6d2fbf0421
commit
4772b41472
6 changed files with 106 additions and 50 deletions
|
@ -33,7 +33,8 @@ cgv_add_module(CGII
|
||||||
../../src/Skeleton.cpp
|
../../src/Skeleton.cpp
|
||||||
../../src/SkeletonViewer.cpp
|
../../src/SkeletonViewer.cpp
|
||||||
../../src/SkinnedMeshViewer.cpp
|
../../src/SkinnedMeshViewer.cpp
|
||||||
../../src/main.cpp)
|
../../src/main.cpp
|
||||||
|
../../src/debughelpers.cpp)
|
||||||
|
|
||||||
# Set include directories
|
# Set include directories
|
||||||
include_directories(
|
include_directories(
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "IKViewer.h"
|
#include "IKViewer.h"
|
||||||
|
|
||||||
#include "math_helper.h"
|
#include "math_helper.h"
|
||||||
|
#include "debughelpers.h"
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
@ -79,12 +80,26 @@ void IKViewer::calculate_kinematic_chain(Bone *base, Bone *endeffector)
|
||||||
current_bone = current_bone->get_parent();
|
current_bone = current_bone->get_parent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kinematic_chain.clear();
|
||||||
|
|
||||||
for (Bone *bone : bones)
|
for (Bone *bone : bones)
|
||||||
{
|
{
|
||||||
// TODO: calculate and add transforms to queue
|
// TODO: calculate and add transforms to queue
|
||||||
std::shared_ptr<Transform> transform;
|
Transform *tmp = new StaticTransform(bone->calculate_transform_prev_to_current_with_dofs());
|
||||||
|
std::shared_ptr<Transform> transform = std::shared_ptr<Transform>(tmp);
|
||||||
kinematic_chain.emplace_front(transform);
|
kinematic_chain.emplace_front(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_endeffector_matrix.identity();
|
||||||
|
|
||||||
|
for (auto &transform : kinematic_chain)
|
||||||
|
{
|
||||||
|
current_endeffector_matrix = current_endeffector_matrix * transform->calculate_matrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
target_position = current_endeffector_matrix * endeffector->get_bone_local_tip_position();
|
||||||
|
|
||||||
|
print_vec3(target_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IKViewer::optimize()
|
void IKViewer::optimize()
|
||||||
|
|
|
@ -12,15 +12,15 @@
|
||||||
#include <cgv/base/find_action.h>
|
#include <cgv/base/find_action.h>
|
||||||
|
|
||||||
#include "math_helper.h"
|
#include "math_helper.h"
|
||||||
|
#include "debughelpers.h"
|
||||||
|
|
||||||
using namespace cgv::utils;
|
using namespace cgv::utils;
|
||||||
|
|
||||||
cgv::render::shader_program Mesh::prog;
|
cgv::render::shader_program Mesh::prog;
|
||||||
|
|
||||||
// The constructor of this class
|
// The constructor of this class
|
||||||
SkeletonViewer::SkeletonViewer(DataStore* data)
|
SkeletonViewer::SkeletonViewer(DataStore *data)
|
||||||
: node("Skeleton Viewer"), data(data)
|
: node("Skeleton Viewer"), data(data), animation(nullptr), animationTime(0)
|
||||||
, animation(nullptr), animationTime(0)
|
|
||||||
{
|
{
|
||||||
connect(data->skeleton_changed, this, &SkeletonViewer::skeleton_changed);
|
connect(data->skeleton_changed, this, &SkeletonViewer::skeleton_changed);
|
||||||
|
|
||||||
|
@ -28,26 +28,31 @@ SkeletonViewer::SkeletonViewer(DataStore* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//draws a part of a skeleton, represented by the given root node
|
//draws a part of a skeleton, represented by the given root node
|
||||||
void SkeletonViewer::draw_skeleton_subtree(Bone* node, const Mat4& global_to_parent_local, context& c, int level, bool arrows, bool indicators)
|
void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_parent_local, context &c, int level, bool arrows, bool indicators)
|
||||||
{
|
{
|
||||||
auto global_to_current_local = global_to_parent_local * node->calculate_transform_prev_to_current_with_dofs();
|
auto global_to_current_local = global_to_parent_local * node->calculate_transform_prev_to_current_with_dofs();
|
||||||
auto my_root_position = global_to_current_local * node->get_bone_local_root_position();
|
auto my_root_position = global_to_current_local * node->get_bone_local_root_position();
|
||||||
auto my_tip_position = global_to_current_local * node->get_bone_local_tip_position();
|
auto my_tip_position = global_to_current_local * node->get_bone_local_tip_position();
|
||||||
|
|
||||||
|
std::cout << "bone: " << node->get_name() << std::endl;
|
||||||
|
print_vec3(my_root_position);
|
||||||
|
print_vec3(my_tip_position);
|
||||||
|
|
||||||
if (arrows)
|
if (arrows)
|
||||||
{
|
{
|
||||||
const GLubyte colors[][3] =
|
const GLubyte colors[][3] =
|
||||||
{
|
{
|
||||||
{ 27,158,119 },
|
{27, 158, 119},
|
||||||
{ 217,95,2 },
|
{217, 95, 2},
|
||||||
{ 117,112,179 },
|
{117, 112, 179},
|
||||||
{ 231,41,138 },
|
{231, 41, 138},
|
||||||
{ 102,166,30 },
|
{102, 166, 30},
|
||||||
{ 230,171,2 },
|
{230, 171, 2},
|
||||||
{ 166,118,29 },
|
{166, 118, 29},
|
||||||
};
|
};
|
||||||
glColor3ubv(colors[level % 7]);
|
glColor3ubv(colors[level % 7]);
|
||||||
c.tesselate_arrow(cgv::math::fvec<double, 3u>(my_root_position.x(), my_root_position.y(), my_root_position.z()),
|
c.tesselate_arrow(cgv::math::fvec<double, 3u>(my_root_position.x(), my_root_position.y(), my_root_position.z()),
|
||||||
cgv::math::fvec<double, 3u>(my_tip_position.x(), my_tip_position.y(), my_tip_position.z()), 0.1, 2.0, 0.5);
|
cgv::math::fvec<double, 3u>(my_tip_position.x(), my_tip_position.y(), my_tip_position.z()), 0.1, 2.0, 0.5);
|
||||||
}
|
}
|
||||||
Mat4 dof_matrix = global_to_parent_local * node->calculate_transform_prev_to_current_without_dofs();
|
Mat4 dof_matrix = global_to_parent_local * node->calculate_transform_prev_to_current_without_dofs();
|
||||||
float indicatorSize = (data->get_skeleton()->getMax() - data->get_skeleton()->getMin()).length() * 0.05f;
|
float indicatorSize = (data->get_skeleton()->getMax() - data->get_skeleton()->getMin()).length() * 0.05f;
|
||||||
|
@ -100,9 +105,10 @@ void SkeletonViewer::skeleton_changed(std::shared_ptr<Skeleton> s)
|
||||||
generate_tree_view_nodes();
|
generate_tree_view_nodes();
|
||||||
|
|
||||||
//Fit view to skeleton
|
//Fit view to skeleton
|
||||||
std::vector<cgv::render::view*> view_ptrs;
|
std::vector<cgv::render::view *> view_ptrs;
|
||||||
cgv::base::find_interface<cgv::render::view>(get_node(), view_ptrs);
|
cgv::base::find_interface<cgv::render::view>(get_node(), view_ptrs);
|
||||||
if (view_ptrs.empty()) {
|
if (view_ptrs.empty())
|
||||||
|
{
|
||||||
// If there is no view, we cannot update it
|
// If there is no view, we cannot update it
|
||||||
cgv::gui::message("could not find a view to adjust!!");
|
cgv::gui::message("could not find a view to adjust!!");
|
||||||
}
|
}
|
||||||
|
@ -120,7 +126,7 @@ void SkeletonViewer::skeleton_changed(std::shared_ptr<Skeleton> s)
|
||||||
post_redraw();
|
post_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonViewer::recursive_connect_signals(Bone* b)
|
void SkeletonViewer::recursive_connect_signals(Bone *b)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < b->dof_count(); ++i)
|
for (int i = 0; i < b->dof_count(); ++i)
|
||||||
connect(b->get_dof(i)->changed_signal, this, &SkeletonViewer::dof_changed);
|
connect(b->get_dof(i)->changed_signal, this, &SkeletonViewer::dof_changed);
|
||||||
|
@ -146,7 +152,7 @@ void SkeletonViewer::generate_tree_view_nodes()
|
||||||
generate_tree_view_nodes(tree_view, data->get_skeleton()->get_root());
|
generate_tree_view_nodes(tree_view, data->get_skeleton()->get_root());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonViewer::generate_tree_view_nodes(gui_group_ptr parent, Bone* bone)
|
void SkeletonViewer::generate_tree_view_nodes(gui_group_ptr parent, Bone *bone)
|
||||||
{
|
{
|
||||||
if (bone->childCount() == 0)
|
if (bone->childCount() == 0)
|
||||||
{
|
{
|
||||||
|
@ -166,7 +172,7 @@ void SkeletonViewer::generate_tree_view_nodes(gui_group_ptr parent, Bone* bone)
|
||||||
|
|
||||||
void SkeletonViewer::start_choose_base()
|
void SkeletonViewer::start_choose_base()
|
||||||
{
|
{
|
||||||
Bone* b = data->get_endeffector();
|
Bone *b = data->get_endeffector();
|
||||||
data->set_endeffector(nullptr);
|
data->set_endeffector(nullptr);
|
||||||
data->set_base(b);
|
data->set_base(b);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +183,7 @@ void SkeletonViewer::tree_selection_changed(base_ptr p, bool select)
|
||||||
|
|
||||||
if (select)
|
if (select)
|
||||||
{
|
{
|
||||||
Bone* bone = gui_to_bone.at(p);
|
Bone *bone = gui_to_bone.at(p);
|
||||||
generate_bone_gui(bone);
|
generate_bone_gui(bone);
|
||||||
data->set_endeffector(bone);
|
data->set_endeffector(bone);
|
||||||
}
|
}
|
||||||
|
@ -292,28 +298,28 @@ void SkeletonViewer::create_gui()
|
||||||
auto gui_group = dock_group->add_group("", "align_group", "", "f");
|
auto gui_group = dock_group->add_group("", "align_group", "", "f");
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Load ASF skeleton", "", "\n")->click,
|
connect_copy(gui_group->add_button("Load ASF skeleton", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::load_skeleton));
|
rebind(this, &SkeletonViewer::load_skeleton));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Load Animation", "", "\n")->click,
|
connect_copy(gui_group->add_button("Load Animation", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::load_animation));
|
rebind(this, &SkeletonViewer::load_animation));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Start Animation", "", "\n")->click,
|
connect_copy(gui_group->add_button("Start Animation", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::start_animation));
|
rebind(this, &SkeletonViewer::start_animation));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Stop Animation", "", "\n")->click,
|
connect_copy(gui_group->add_button("Stop Animation", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::stop_animation));
|
rebind(this, &SkeletonViewer::stop_animation));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Choose IK Base", "", "\n")->click,
|
connect_copy(gui_group->add_button("Choose IK Base", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::start_choose_base));
|
rebind(this, &SkeletonViewer::start_choose_base));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Write Pinocchio skeleton", "", "\n")->click,
|
connect_copy(gui_group->add_button("Write Pinocchio skeleton", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::write_pinocchio));
|
rebind(this, &SkeletonViewer::write_pinocchio));
|
||||||
|
|
||||||
connect_copy(gui_group->add_button("Load Pinocchio skeleton", "", "\n")->click,
|
connect_copy(gui_group->add_button("Load Pinocchio skeleton", "", "\n")->click,
|
||||||
rebind(this, &SkeletonViewer::load_pinocchio));
|
rebind(this, &SkeletonViewer::load_pinocchio));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonViewer::generate_bone_gui(Bone* bone)
|
void SkeletonViewer::generate_bone_gui(Bone *bone)
|
||||||
{
|
{
|
||||||
// Add bone-specific gui elements to bone_group.
|
// Add bone-specific gui elements to bone_group.
|
||||||
// Use the layout "\n" to specify vertical alignment
|
// Use the layout "\n" to specify vertical alignment
|
||||||
|
@ -329,7 +335,7 @@ void SkeletonViewer::generate_bone_gui(Bone* bone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonViewer::draw(context& c)
|
void SkeletonViewer::draw(context &c)
|
||||||
{
|
{
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
23
CGII/src/debughelpers.cpp
Normal file
23
CGII/src/debughelpers.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "debughelpers.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void print_vec3(const Vec3 &v)
|
||||||
|
{
|
||||||
|
std::cout << "(" << v.x() << ", " << v.y() << ", " << v.z() << ")" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_vec3(const Vec4 &v)
|
||||||
|
{
|
||||||
|
print_vec3(into_vec3(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 into_vec3(const Vec4 &v)
|
||||||
|
{
|
||||||
|
return Vec3(v.x(), v.y(), v.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4 into_vec4(const Vec3 &v)
|
||||||
|
{
|
||||||
|
return Vec4(v.x(), v.y(), v.z(), 1.0f);
|
||||||
|
}
|
11
CGII/src/debughelpers.h
Normal file
11
CGII/src/debughelpers.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "math_helper.h"
|
||||||
|
|
||||||
|
void print_vec3(const Vec3 &v);
|
||||||
|
|
||||||
|
void print_vec3(const Vec4 &v);
|
||||||
|
|
||||||
|
Vec3 into_vec3(const Vec4 &v);
|
||||||
|
|
||||||
|
Vec4 into_vec4(const Vec3 &v);
|
|
@ -21,7 +21,7 @@ const cgv::math::fmat<T, 4, 4> rotate(const cgv::math::fvec<T, 3> axis, T angle_
|
||||||
|
|
||||||
///creates a 4x4 translation matrix
|
///creates a 4x4 translation matrix
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const cgv::math::fmat<T, 4, 4> translate(const T&x, const T &y, const T&z)
|
const cgv::math::fmat<T, 4, 4> translate(const T &x, const T &y, const T &z)
|
||||||
{
|
{
|
||||||
cgv::math::fmat<T, 4, 4> m;
|
cgv::math::fmat<T, 4, 4> m;
|
||||||
m.identity();
|
m.identity();
|
||||||
|
|
Loading…
Reference in a new issue