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",
|
||||
"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": []
|
||||
}
|
||||
]
|
||||
|
|
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()
|
||||
: 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 */
|
||||
|
|
|
@ -97,6 +97,10 @@ public:
|
|||
//Available after implementing task 4.6.
|
||||
const Mat4 &get_binding_pose_matrix() const;
|
||||
|
||||
// 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
|
||||
|
@ -121,4 +125,3 @@ private:
|
|||
|
||||
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)
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue