Fix orientation rendering

This commit is contained in:
hodasemi 2018-05-30 11:17:21 +02:00
parent 53869bd64a
commit d62d06ae40
4 changed files with 22 additions and 23 deletions

View file

@ -61,26 +61,12 @@ void Bone::calculate_matrices()
std::cout << name << " length " << length << std::endl;
/*Task 2.1: Implement matrix calculation */
Vec3 vector = direction_in_world_space * length;
/*
Mat4 matrix;
matrix.identity();
translationTransformCurrentJointToNext = translate(vector);
orientationTransformPrevJointToCurrent = matrix;
*/
Mat4 parent_orientation;
if (parent != NULL)
parent_orientation = parent->get_total_orientation();
else
parent_orientation.identity();
translationTransformCurrentJointToNext = translate(vector);
orientationTransformPrevJointToCurrent = orientationTransformGlobalToLocal * cgv::math::inv(parent_orientation);
/*Task 4.6: Implement matrix calculation */
}
@ -88,21 +74,21 @@ void Bone::calculate_matrices()
Mat4 Bone::calculate_transform_prev_to_current_with_dofs()
{
//Task 2.1: Implement matrix calculation
Mat4 dofs;
dofs.identity();
Mat4 dofs_matrix;
dofs_matrix.identity();
std::for_each(orientation.begin(), orientation.end(), [&](AtomicTransform *t) {
//dofs = dofs * t->calculate_matrix();
std::for_each(dofs.begin(), dofs.end(), [&](std::shared_ptr<AtomicTransform> &t) {
dofs_matrix = dofs_matrix * t->calculate_matrix();
});
Mat4 t = translationTransformCurrentJointToNext * orientationTransformPrevJointToCurrent * dofs; // * orientationTransformGlobalToLocal;
Mat4 t = translationTransformCurrentJointToNext * orientationTransformGlobalToLocal * dofs_matrix * orientationTransformPrevJointToCurrent * orientationTransformLocalToGlobal;
return t;
}
Mat4 Bone::calculate_transform_prev_to_current_without_dofs()
{
//Task 2.1: Implement matrix calculation
Mat4 t = translationTransformCurrentJointToNext * orientationTransformPrevJointToCurrent;
Mat4 t = translationTransformCurrentJointToNext * orientationTransformLocalToGlobal * orientationTransformPrevJointToCurrent * orientationTransformGlobalToLocal;
return t;
}

View file

@ -112,6 +112,8 @@ class Bone
std::vector<Bone *> children; //child bones
Bone *parent; //parent bone
Vec3 direction_in_local_space;
//Calculated attributes
//Transform directions are specified for model transforms (system transforms are in the opposite direction)
Mat4 orientationTransformPrevJointToCurrent; //Rotation matrix that transforms from the previous bone to the current bone (in the previous bone's coordinate system); Task 2.1

View file

@ -25,14 +25,19 @@ SkeletonViewer::SkeletonViewer(DataStore *data)
connect(data->skeleton_changed, this, &SkeletonViewer::skeleton_changed);
connect(get_animation_trigger().shoot, this, &SkeletonViewer::timer_event);
for (int i = 0; i < SKELETON_DEPTH; i++)
{
for (int j = 0; j < 3; j++)
{
colors[i][j] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
}
}
}
//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 depth)
{
if (depth > 4)
return;
//Task: Draw skeleton
Mat4 local_transform = node->calculate_transform_prev_to_current_with_dofs() * global_to_parent_local;
@ -46,6 +51,8 @@ void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_par
std::cout << node->get_name() << " start: " << from_Vec3(p1_v3) << ", end: " << from_Vec3(p2_v3) << std::endl;
glColor3f(colors[depth][0], colors[depth][1], colors[depth][2]);
c.tesselate_arrow(p1_v3, p2_v3);
depth++;

View file

@ -24,6 +24,8 @@ using namespace cgv::math;
using namespace cgv::render;
using namespace cgv::utils;
#define SKELETON_DEPTH 10
class SkeletonViewer : public node, public drawable, public provider
{
private:
@ -68,4 +70,6 @@ class SkeletonViewer : public node, public drawable, public provider
void draw(context &c);
std::string get_parent_type() const;
float colors[SKELETON_DEPTH][3];
};