Humanilation
This commit is contained in:
parent
09acaf26cb
commit
be92b31d04
3 changed files with 50 additions and 14 deletions
|
@ -50,23 +50,47 @@ void Bone::calculate_matrices()
|
||||||
{
|
{
|
||||||
orientationTransformGlobalToLocal.identity();
|
orientationTransformGlobalToLocal.identity();
|
||||||
std::for_each(orientation.begin(), orientation.end(), [&](AtomicTransform *t) {
|
std::for_each(orientation.begin(), orientation.end(), [&](AtomicTransform *t) {
|
||||||
std::cout << name << " orientation " << t->get_name() << ": " << t->get_value() << std::endl;
|
//std::cout << name << " orientation " << t->get_name() << ": " << t->get_value() << std::endl;
|
||||||
|
|
||||||
orientationTransformGlobalToLocal = orientationTransformGlobalToLocal * t->calculate_matrix();
|
orientationTransformGlobalToLocal = orientationTransformGlobalToLocal * t->calculate_matrix();
|
||||||
});
|
});
|
||||||
|
|
||||||
orientationTransformLocalToGlobal = cgv::math::inv(orientationTransformGlobalToLocal);
|
orientationTransformLocalToGlobal = cgv::math::inv(orientationTransformGlobalToLocal);
|
||||||
|
|
||||||
std::cout << name << " direction " << from_Vec3(direction_in_world_space) << std::endl;
|
//std::cout << name << " direction " << from_Vec3(direction_in_world_space) << std::endl;
|
||||||
std::cout << name << " length " << length << std::endl;
|
//std::cout << name << " length " << length << std::endl;
|
||||||
|
|
||||||
/*Task 2.1: Implement matrix calculation */
|
/*Task 2.1: Implement matrix calculation */
|
||||||
Vec3 vector = direction_in_world_space * length;
|
Vec3 vector = direction_in_world_space * length;
|
||||||
Mat4 matrix;
|
//translationTransformCurrentJointToNext = orientationTransformLocalToGlobal * translate(vector) * orientationTransformGlobalToLocal;
|
||||||
matrix.identity();
|
|
||||||
|
|
||||||
translationTransformCurrentJointToNext = translate(vector);
|
translationTransformCurrentJointToNext = translate(vector);
|
||||||
orientationTransformPrevJointToCurrent = matrix;
|
|
||||||
|
if (parent == nullptr)
|
||||||
|
{
|
||||||
|
orientationTransformPrevJointToCurrent.identity();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vec3 prev_dir = parent->get_direction_in_world_space();
|
||||||
|
Vec3 &curr_dir = direction_in_world_space;
|
||||||
|
|
||||||
|
if (prev_dir.x() == 0.0f && prev_dir.y() == 0.0f && prev_dir.z() == 0.0f)
|
||||||
|
{
|
||||||
|
orientationTransformPrevJointToCurrent.identity();
|
||||||
|
}
|
||||||
|
else if (prev_dir == curr_dir)
|
||||||
|
{
|
||||||
|
orientationTransformPrevJointToCurrent.identity();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
float angle = calc_angle(curr_dir, prev_dir);
|
||||||
|
Vec3 axis = cross(curr_dir, prev_dir);
|
||||||
|
|
||||||
|
orientationTransformPrevJointToCurrent = rotate(axis, angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*Task 4.6: Implement matrix calculation */
|
/*Task 4.6: Implement matrix calculation */
|
||||||
}
|
}
|
||||||
|
@ -74,6 +98,13 @@ void Bone::calculate_matrices()
|
||||||
Mat4 Bone::calculate_transform_prev_to_current_with_dofs()
|
Mat4 Bone::calculate_transform_prev_to_current_with_dofs()
|
||||||
{
|
{
|
||||||
//Task 2.1: Implement matrix calculation
|
//Task 2.1: Implement matrix calculation
|
||||||
|
if (parent == NULL)
|
||||||
|
{
|
||||||
|
Mat4 t;
|
||||||
|
t.identity();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
Mat4 dofs_matrix;
|
Mat4 dofs_matrix;
|
||||||
dofs_matrix.identity();
|
dofs_matrix.identity();
|
||||||
|
|
||||||
|
@ -81,15 +112,13 @@ Mat4 Bone::calculate_transform_prev_to_current_with_dofs()
|
||||||
dofs_matrix = dofs_matrix * t->calculate_matrix();
|
dofs_matrix = dofs_matrix * t->calculate_matrix();
|
||||||
});
|
});
|
||||||
|
|
||||||
Mat4 t = translationTransformCurrentJointToNext * orientationTransformGlobalToLocal * dofs_matrix * orientationTransformPrevJointToCurrent * orientationTransformLocalToGlobal;
|
return parent->get_translation_transform_current_joint_to_next() * orientationTransformPrevJointToCurrent * dofs_matrix;
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 Bone::calculate_transform_prev_to_current_without_dofs()
|
Mat4 Bone::calculate_transform_prev_to_current_without_dofs()
|
||||||
{
|
{
|
||||||
//Task 2.1: Implement matrix calculation
|
//Task 2.1: Implement matrix calculation
|
||||||
Mat4 t = translationTransformCurrentJointToNext * orientationTransformLocalToGlobal * orientationTransformPrevJointToCurrent * orientationTransformGlobalToLocal;
|
return parent->get_translation_transform_current_joint_to_next() * orientationTransformPrevJointToCurrent;
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 Bone::get_total_orientation()
|
Mat4 Bone::get_total_orientation()
|
||||||
|
|
|
@ -35,6 +35,7 @@ SkeletonViewer::SkeletonViewer(DataStore *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = 0;
|
frame = 0;
|
||||||
|
inc_frame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_dof(Bone *node, Vec4 start_point)
|
void draw_dof(Bone *node, Vec4 start_point)
|
||||||
|
@ -135,7 +136,7 @@ void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_par
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 local_transform = node->calculate_transform_prev_to_current_with_dofs() * global_to_parent_local;
|
Mat4 local_transform = global_to_parent_local * node->calculate_transform_prev_to_current_with_dofs();
|
||||||
|
|
||||||
Vec4 zero = Vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
Vec4 zero = Vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
@ -165,11 +166,14 @@ void SkeletonViewer::timer_event(double, double dt)
|
||||||
|
|
||||||
void SkeletonViewer::start_animation()
|
void SkeletonViewer::start_animation()
|
||||||
{
|
{
|
||||||
//Task: Implement animation
|
frame = 0;
|
||||||
|
inc_frame = true;
|
||||||
|
post_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonViewer::stop_animation()
|
void SkeletonViewer::stop_animation()
|
||||||
{
|
{
|
||||||
|
inc_frame = false;
|
||||||
//Task: Implement animation
|
//Task: Implement animation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +462,9 @@ void SkeletonViewer::draw(context &c)
|
||||||
if (data->get_skeleton() != nullptr)
|
if (data->get_skeleton() != nullptr)
|
||||||
draw_skeleton_subtree(data->get_skeleton()->get_root(), data->get_skeleton()->get_origin(), c, 0);
|
draw_skeleton_subtree(data->get_skeleton()->get_root(), data->get_skeleton()->get_origin(), c, 0);
|
||||||
|
|
||||||
|
if (inc_frame)
|
||||||
frame++;
|
frame++;
|
||||||
|
|
||||||
if (frame >= animations.size())
|
if (frame >= animations.size())
|
||||||
frame = 0;
|
frame = 0;
|
||||||
}
|
}
|
|
@ -39,6 +39,7 @@ class SkeletonViewer : public node, public drawable, public provider
|
||||||
// Maps gui elements in the tree view to a specific bone
|
// Maps gui elements in the tree view to a specific bone
|
||||||
std::map<base_ptr, Bone *> gui_to_bone;
|
std::map<base_ptr, Bone *> gui_to_bone;
|
||||||
|
|
||||||
|
bool inc_frame;
|
||||||
int frame;
|
int frame;
|
||||||
|
|
||||||
// slot for the signal
|
// slot for the signal
|
||||||
|
|
Loading…
Reference in a new issue