Basic skeleton rendering
This commit is contained in:
parent
880c7b0aac
commit
aba42950c5
6 changed files with 64 additions and 56 deletions
11
.vscode/tasks.json
vendored
11
.vscode/tasks.json
vendored
|
@ -6,8 +6,13 @@
|
||||||
{
|
{
|
||||||
"label": "Run CG-Viewer",
|
"label": "Run CG-Viewer",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:CGII/build/cmake/build/bin/unix/ framework/bin/unix/./cgv_viewer plugin:cg_fltk.cgv plugin:CGII.cgv",
|
"command": "framework/bin/unix/cgv_viewer",
|
||||||
"problemMatcher": []
|
"problemMatcher": [],
|
||||||
|
"args": [
|
||||||
|
"plugin:cg_fltk.cgv",
|
||||||
|
"plugin:CGII.cgv",
|
||||||
|
"plugin:crg_stereo_view.cgv"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Build All",
|
"label": "Build All",
|
||||||
|
@ -18,7 +23,7 @@
|
||||||
{
|
{
|
||||||
"label": "Build CGII",
|
"label": "Build CGII",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cd CGII/build/cmake && cmake . && make clean && make -j16",
|
"command": "cd CGII/build/cmake && cmake . && make clean && make -j16 && cd ../../.. && cp CGII/build/cmake/build/bin/unix/libCGII.so framework/lib/unix/",
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
BIN
CG2_SS18_02_Articulated_Objects.pdf
Normal file
BIN
CG2_SS18_02_Articulated_Objects.pdf
Normal file
Binary file not shown.
|
@ -12,6 +12,8 @@
|
||||||
Bone::Bone()
|
Bone::Bone()
|
||||||
: parent(nullptr), length(0.0f), direction_in_world_space(0.0, 0.0, 0.0), translationTransforms(0)
|
: parent(nullptr), length(0.0f), direction_in_world_space(0.0, 0.0, 0.0), translationTransforms(0)
|
||||||
{
|
{
|
||||||
|
start_point = Vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
end_point = Vec3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bone::~Bone()
|
Bone::~Bone()
|
||||||
|
@ -27,19 +29,6 @@ Bone::~Bone()
|
||||||
orientation.clear();
|
orientation.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_mat4(Mat4 &m)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < 4; x++)
|
|
||||||
{
|
|
||||||
for (int y = 0; y < 4; y++)
|
|
||||||
{
|
|
||||||
std::cout << m[x * 4 + y] << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bone::calculate_matrices()
|
void Bone::calculate_matrices()
|
||||||
{
|
{
|
||||||
orientationTransformGlobalToLocal.identity();
|
orientationTransformGlobalToLocal.identity();
|
||||||
|
@ -48,6 +37,19 @@ void Bone::calculate_matrices()
|
||||||
});
|
});
|
||||||
orientationTransformLocalToGlobal = cgv::math::inv(orientationTransformGlobalToLocal);
|
orientationTransformLocalToGlobal = cgv::math::inv(orientationTransformGlobalToLocal);
|
||||||
|
|
||||||
|
if (parent != nullptr)
|
||||||
|
start_point = parent->end_point;
|
||||||
|
|
||||||
|
end_point = start_point + length * direction_in_world_space;
|
||||||
|
|
||||||
|
std::cout << name << " start at ("
|
||||||
|
<< start_point.x() << ", "
|
||||||
|
<< start_point.y() << ", "
|
||||||
|
<< start_point.z() << "), end at ("
|
||||||
|
<< end_point.x() << ", "
|
||||||
|
<< end_point.y() << ", "
|
||||||
|
<< end_point.z() << ")" << std::endl;
|
||||||
|
|
||||||
/*Task 2.1: Implement matrix calculation */
|
/*Task 2.1: Implement matrix calculation */
|
||||||
|
|
||||||
/*Task 4.6: Implement matrix calculation */
|
/*Task 4.6: Implement matrix calculation */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// This source code is property of the Computer Graphics and Visualization
|
// This source code is property of the Computer Graphics and Visualization
|
||||||
// chair of the TU Dresden. Do not distribute!
|
// chair of the TU Dresden. Do not distribute!
|
||||||
// Copyright (C) CGV TU Dresden - All Rights Reserved
|
// Copyright (C) CGV TU Dresden - All Rights Reserved
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -11,16 +11,16 @@
|
||||||
|
|
||||||
// Represents a bone in a hierarchical skeleton
|
// Represents a bone in a hierarchical skeleton
|
||||||
class Bone
|
class Bone
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Bone();
|
Bone();
|
||||||
~Bone();
|
~Bone();
|
||||||
|
|
||||||
//Adds a new degree of freedom to the bone. The bone maintains separate groups of
|
//Adds a new degree of freedom to the bone. The bone maintains separate groups of
|
||||||
//translation transforms and other transforms. All translation transforms go first
|
//translation transforms and other transforms. All translation transforms go first
|
||||||
//in the dof list, followed by all other transforms. Every new transform is added
|
//in the dof list, followed by all other transforms. Every new transform is added
|
||||||
//to the beginning of the respective group.
|
//to the beginning of the respective group.
|
||||||
void add_dof(AtomicTransform* dof);
|
void add_dof(AtomicTransform *dof);
|
||||||
|
|
||||||
//Returns the number of degrees of freedom of this bone.
|
//Returns the number of degrees of freedom of this bone.
|
||||||
int dof_count() const;
|
int dof_count() const;
|
||||||
|
@ -29,18 +29,18 @@ public:
|
||||||
std::shared_ptr<AtomicTransform> get_dof(int dofIndex) const;
|
std::shared_ptr<AtomicTransform> get_dof(int dofIndex) const;
|
||||||
|
|
||||||
//Sets the identifying name of the bone
|
//Sets the identifying name of the bone
|
||||||
void set_name(const std::string& name);
|
void set_name(const std::string &name);
|
||||||
|
|
||||||
//Returns the identifying name of the bone
|
//Returns the identifying name of the bone
|
||||||
const std::string& get_name() const;
|
const std::string &get_name() const;
|
||||||
|
|
||||||
//Sets a unit vector that describes the bone's direction in world coordinates
|
//Sets a unit vector that describes the bone's direction in world coordinates
|
||||||
//(independent of the hierarchy)
|
//(independent of the hierarchy)
|
||||||
void set_direction_in_world_space(const Vec3& direction);
|
void set_direction_in_world_space(const Vec3 &direction);
|
||||||
|
|
||||||
//Returns a unit vector that describes the bone's direction in world coordinates
|
//Returns a unit vector that describes the bone's direction in world coordinates
|
||||||
//(independent of the hierarchy)
|
//(independent of the hierarchy)
|
||||||
const Vec3& get_direction_in_world_space() const;
|
const Vec3 &get_direction_in_world_space() const;
|
||||||
|
|
||||||
//Sets the bone's geometric length
|
//Sets the bone's geometric length
|
||||||
void set_length(float length);
|
void set_length(float length);
|
||||||
|
@ -51,27 +51,27 @@ public:
|
||||||
//Modifies the orientation of the bone's local coordinate system by setting
|
//Modifies the orientation of the bone's local coordinate system by setting
|
||||||
// O <= T * O,
|
// O <= T * O,
|
||||||
//where O is the bone's local coordinate system transform and T is the new transform.
|
//where O is the bone's local coordinate system transform and T is the new transform.
|
||||||
void add_axis_rotation(AtomicTransform* transform);
|
void add_axis_rotation(AtomicTransform *transform);
|
||||||
|
|
||||||
//Adds a new child to this bone and sets the parent of the child to the current bone.
|
//Adds a new child to this bone and sets the parent of the child to the current bone.
|
||||||
void add_child(Bone* child);
|
void add_child(Bone *child);
|
||||||
|
|
||||||
//Returns the child with index i.
|
//Returns the child with index i.
|
||||||
Bone* child_at(int i) const;
|
Bone *child_at(int i) const;
|
||||||
|
|
||||||
//Returns the number of children of this bone.
|
//Returns the number of children of this bone.
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
|
|
||||||
//Specifies the parent of this bone. The root bone has a null parent.
|
//Specifies the parent of this bone. The root bone has a null parent.
|
||||||
void set_parent(Bone* parent);
|
void set_parent(Bone *parent);
|
||||||
|
|
||||||
//Returns the parent of this bone. The root bone has a null parent.
|
//Returns the parent of this bone. The root bone has a null parent.
|
||||||
Bone* get_parent() const;
|
Bone *get_parent() const;
|
||||||
|
|
||||||
//Calculates all relevant matrices from the given information in the ASF file.
|
//Calculates all relevant matrices from the given information in the ASF file.
|
||||||
void calculate_matrices();
|
void calculate_matrices();
|
||||||
|
|
||||||
//Calculates a matrix that transforms the parent's local coordinate system to the current bone's local coordinate system (model transform).
|
//Calculates a matrix that transforms the parent's local coordinate system to the current bone's local coordinate system (model transform).
|
||||||
//It includes all dofs of the bone. Implemented in task 2.1
|
//It includes all dofs of the bone. Implemented in task 2.1
|
||||||
Mat4 calculate_transform_prev_to_current_with_dofs();
|
Mat4 calculate_transform_prev_to_current_with_dofs();
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ public:
|
||||||
|
|
||||||
//Returns a matrix that represents a translation from the current bone to the next bone in the current bone's local coordinate system.
|
//Returns a matrix that represents a translation from the current bone to the next bone in the current bone's local coordinate system.
|
||||||
//Implemented in task 2.1.
|
//Implemented in task 2.1.
|
||||||
const Mat4& get_translation_transform_current_joint_to_next() const;
|
const Mat4 &get_translation_transform_current_joint_to_next() const;
|
||||||
|
|
||||||
//Returns a matrix that represents a rotation from the previous bone to the current bone in the previous bone's local coordinate system.
|
//Returns a matrix that represents a rotation from the previous bone to the current bone in the previous bone's local coordinate system.
|
||||||
//Implemented in task 2.1.
|
//Implemented in task 2.1.
|
||||||
const Mat4& get_orientation_transform_prev_joint_to_current() const;
|
const Mat4 &get_orientation_transform_prev_joint_to_current() const;
|
||||||
|
|
||||||
//Returns the zero-vector (with w-component 1)
|
//Returns the zero-vector (with w-component 1)
|
||||||
Vec4 get_bone_local_root_position() const;
|
Vec4 get_bone_local_root_position() const;
|
||||||
|
@ -95,30 +95,33 @@ public:
|
||||||
|
|
||||||
//Returns the system transform that transforms positions from the global coordinate system to the bone's local coordinate system.
|
//Returns the system transform that transforms positions from the global coordinate system to the bone's local coordinate system.
|
||||||
//Available after implementing task 4.6.
|
//Available after implementing task 4.6.
|
||||||
const Mat4& get_binding_pose_matrix() const;
|
const Mat4 &get_binding_pose_matrix() const;
|
||||||
|
|
||||||
private:
|
// Testing area
|
||||||
|
Vec3 start_point; // same as parent end point
|
||||||
|
Vec3 end_point; // start_point + (length * direction_in_world_space)
|
||||||
|
|
||||||
|
private:
|
||||||
//The following attributes are read from the ASF file
|
//The following attributes are read from the ASF file
|
||||||
std::deque<std::shared_ptr<AtomicTransform>> dofs; //Degrees of freedom for the bone
|
std::deque<std::shared_ptr<AtomicTransform>> dofs; //Degrees of freedom for the bone
|
||||||
std::string name; //The bone's name
|
std::string name; //The bone's name
|
||||||
Vec3 direction_in_world_space; //The bone's direction in world space (unit vector)
|
Vec3 direction_in_world_space; //The bone's direction in world space (unit vector)
|
||||||
float length; //The bone's length
|
float length; //The bone's length
|
||||||
std::deque<AtomicTransform*> orientation; //The model transform from global space to bone space; multiply together from left to right
|
std::deque<AtomicTransform *> orientation; //The model transform from global space to bone space; multiply together from left to right
|
||||||
|
|
||||||
std::vector<Bone*> children; //child bones
|
std::vector<Bone *> children; //child bones
|
||||||
Bone* parent; //parent bone
|
Bone *parent; //parent bone
|
||||||
|
|
||||||
//Calculated attributes
|
//Calculated attributes
|
||||||
//Transform directions are specified for model transforms (system transforms are in the opposite direction)
|
//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
|
Mat4 orientationTransformPrevJointToCurrent; //Rotation matrix that transforms from the previous bone to the current bone (in the previous bone's coordinate system); Task 2.1
|
||||||
Mat4 translationTransformCurrentJointToNext; //Translation matrix that transforms from the current bone to the next bone (in the current bone's coordinate system); Task 2.1
|
Mat4 translationTransformCurrentJointToNext; //Translation matrix that transforms from the current bone to the next bone (in the current bone's coordinate system); Task 2.1
|
||||||
Mat4 orientationTransformGlobalToLocal; //Rotation matrix that transforms from the global coordinate system to the current bone's local system. Available from the beginning.
|
Mat4 orientationTransformGlobalToLocal; //Rotation matrix that transforms from the global coordinate system to the current bone's local system. Available from the beginning.
|
||||||
Mat4 orientationTransformLocalToGlobal; //Rotation matrix that transforms from the current bone's local system to the global coordinate system. Available from the beginning.
|
Mat4 orientationTransformLocalToGlobal; //Rotation matrix that transforms from the current bone's local system to the global coordinate system. Available from the beginning.
|
||||||
//for skinning:
|
//for skinning:
|
||||||
Mat4 translationTransformGlobalToLocal; //Translation matrix that transforms from the global coordinate system to the bone's local system. Task 4.6
|
Mat4 translationTransformGlobalToLocal; //Translation matrix that transforms from the global coordinate system to the bone's local system. Task 4.6
|
||||||
Mat4 transformGlobalToLocal; //Combined rotation and translation that transforms from the global coordinate system to the bone's local system. Task 4.6
|
Mat4 transformGlobalToLocal; //Combined rotation and translation that transforms from the global coordinate system to the bone's local system. Task 4.6
|
||||||
Mat4 transformLocalToGlobal;//Combined rotation and translation that transforms from the bone's local coordinate system to the global system. Task 4.6
|
Mat4 transformLocalToGlobal; //Combined rotation and translation that transforms from the bone's local coordinate system to the global system. Task 4.6
|
||||||
|
|
||||||
int translationTransforms; //The number of translation transforms that have been added as dof
|
int translationTransforms; //The number of translation transforms that have been added as dof
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,22 +22,22 @@ SkeletonViewer::SkeletonViewer(DataStore *data)
|
||||||
: node("Skeleton Viewer"), data(data)
|
: node("Skeleton Viewer"), data(data)
|
||||||
|
|
||||||
{
|
{
|
||||||
program.createProgram("CGII/glsl/skinning.glvs", "CGII/glsl/skinning.glgs", "CGII/glsl/skinning.glfs");
|
|
||||||
|
|
||||||
connect(data->skeleton_changed, this, &SkeletonViewer::skeleton_changed);
|
connect(data->skeleton_changed, this, &SkeletonViewer::skeleton_changed);
|
||||||
|
|
||||||
connect(get_animation_trigger().shoot, this, &SkeletonViewer::timer_event);
|
connect(get_animation_trigger().shoot, this, &SkeletonViewer::timer_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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)
|
void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_parent_local, context &c)
|
||||||
{
|
{
|
||||||
//Task: Draw skeleton
|
//Task: Draw skeleton
|
||||||
|
c.tesselate_arrow(node->start_point, node->end_point);
|
||||||
|
|
||||||
Mat4 transform;
|
Mat4 transform;
|
||||||
|
|
||||||
for (int i = 0; i < node->childCount(); i++)
|
for (int i = 0; i < node->childCount(); i++)
|
||||||
{
|
{
|
||||||
draw_skeleton_subtree(node->child_at(i), transform);
|
draw_skeleton_subtree(node->child_at(i), transform, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,5 +287,5 @@ void SkeletonViewer::draw(context &c)
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
|
||||||
if (data->get_skeleton() != nullptr)
|
if (data->get_skeleton() != nullptr)
|
||||||
draw_skeleton_subtree(data->get_skeleton()->get_root(), data->get_skeleton()->get_origin());
|
draw_skeleton_subtree(data->get_skeleton()->get_root(), data->get_skeleton()->get_origin(), c);
|
||||||
}
|
}
|
|
@ -50,7 +50,7 @@ class SkeletonViewer : public node, public drawable, public provider
|
||||||
void load_animation();
|
void load_animation();
|
||||||
void start_choose_base();
|
void start_choose_base();
|
||||||
|
|
||||||
void draw_skeleton_subtree(Bone *node, const Mat4 &global_to_parent_local);
|
void draw_skeleton_subtree(Bone *node, const Mat4 &global_to_parent_local, context &c);
|
||||||
|
|
||||||
void dof_changed(double new_value);
|
void dof_changed(double new_value);
|
||||||
void recursive_connect_signals(Bone *b);
|
void recursive_connect_signals(Bone *b);
|
||||||
|
@ -68,6 +68,4 @@ class SkeletonViewer : public node, public drawable, public provider
|
||||||
void draw(context &c);
|
void draw(context &c);
|
||||||
|
|
||||||
std::string get_parent_type() const;
|
std::string get_parent_type() const;
|
||||||
|
|
||||||
Program program;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue