Basic skeleton rendering

This commit is contained in:
hodasemi 2018-05-18 11:25:22 +02:00
parent 880c7b0aac
commit aba42950c5
6 changed files with 64 additions and 56 deletions

11
.vscode/tasks.json vendored
View file

@ -6,8 +6,13 @@
{
"label": "Run CG-Viewer",
"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",
"problemMatcher": []
"command": "framework/bin/unix/cgv_viewer",
"problemMatcher": [],
"args": [
"plugin:cg_fltk.cgv",
"plugin:CGII.cgv",
"plugin:crg_stereo_view.cgv"
]
},
{
"label": "Build All",
@ -18,7 +23,7 @@
{
"label": "Build CGII",
"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": []
}
]

Binary file not shown.

View file

@ -12,6 +12,8 @@
Bone::Bone()
: 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()
@ -27,19 +29,6 @@ Bone::~Bone()
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()
{
orientationTransformGlobalToLocal.identity();
@ -48,6 +37,19 @@ void Bone::calculate_matrices()
});
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 4.6: Implement matrix calculation */

View file

@ -12,7 +12,7 @@
// Represents a bone in a hierarchical skeleton
class Bone
{
public:
public:
Bone();
~Bone();
@ -20,7 +20,7 @@ public:
//translation transforms and other transforms. All translation transforms go first
//in the dof list, followed by all other transforms. Every new transform is added
//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.
int dof_count() const;
@ -29,18 +29,18 @@ public:
std::shared_ptr<AtomicTransform> get_dof(int dofIndex) const;
//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
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
//(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
//(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
void set_length(float length);
@ -51,22 +51,22 @@ public:
//Modifies the orientation of the bone's local coordinate system by setting
// O <= T * O,
//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.
void add_child(Bone* child);
void add_child(Bone *child);
//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.
int childCount() const;
//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.
Bone* get_parent() const;
Bone *get_parent() const;
//Calculates all relevant matrices from the given information in the ASF file.
void calculate_matrices();
@ -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.
//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.
//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)
Vec4 get_bone_local_root_position() const;
@ -95,18 +95,22 @@ public:
//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.
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
std::deque<std::shared_ptr<AtomicTransform>> dofs; //Degrees of freedom for the bone
std::string name; //The bone's name
Vec3 direction_in_world_space; //The bone's direction in world space (unit vector)
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
Bone* parent; //parent bone
std::vector<Bone *> children; //child bones
Bone *parent; //parent bone
//Calculated attributes
//Transform directions are specified for model transforms (system transforms are in the opposite direction)
@ -117,8 +121,7 @@ private:
//for skinning:
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 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
};

View file

@ -22,22 +22,22 @@ SkeletonViewer::SkeletonViewer(DataStore *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(get_animation_trigger().shoot, this, &SkeletonViewer::timer_event);
}
//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
c.tesselate_arrow(node->start_point, node->end_point);
Mat4 transform;
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);
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);
}

View file

@ -50,7 +50,7 @@ class SkeletonViewer : public node, public drawable, public provider
void load_animation();
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 recursive_connect_signals(Bone *b);
@ -68,6 +68,4 @@ class SkeletonViewer : public node, public drawable, public provider
void draw(context &c);
std::string get_parent_type() const;
Program program;
};