Draw dofs
This commit is contained in:
parent
b4bec44770
commit
09acaf26cb
1 changed files with 77 additions and 3 deletions
|
@ -37,6 +37,81 @@ SkeletonViewer::SkeletonViewer(DataStore *data)
|
||||||
frame = 0;
|
frame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_dof(Bone *node, Vec4 start_point)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i < node->dof_count(); i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
Vec3 point_joint = Vec3(start_point.x(), start_point.y(), start_point.z());
|
||||||
|
|
||||||
|
auto bonelength = node->get_length();
|
||||||
|
|
||||||
|
double lower_limit = node->get_dof(i)->get_lower_limit();
|
||||||
|
double upper_limit = node->get_dof(i)->get_upper_limit();
|
||||||
|
|
||||||
|
// lowerlimit
|
||||||
|
auto abs_lower_limit = std::abs(lower_limit);
|
||||||
|
auto tan_lower_limit = std::tan(abs_lower_limit);
|
||||||
|
auto cos_lower_limit = std::cos(lower_limit);
|
||||||
|
|
||||||
|
// upperlimit
|
||||||
|
auto abs_upper_limit = std::abs(upper_limit);
|
||||||
|
auto tan_upper_limit = std::tan(abs_upper_limit);
|
||||||
|
auto cos_upper_limit = std::cos(upper_limit);
|
||||||
|
|
||||||
|
auto pt_min = bonelength * cos_lower_limit;
|
||||||
|
auto pt_max = bonelength * cos_upper_limit;
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
|
|
||||||
|
if (node->get_dof(i)->get_name() == "X-Rotation")
|
||||||
|
{
|
||||||
|
|
||||||
|
// drawing x movement (local)
|
||||||
|
glColor4f(0, 128, 0, 128);
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y(), point_joint.z());
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y() - 5, point_joint.z() + pt_max);
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y() - 5, point_joint.z() - pt_min);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if(node->get_dof(i)->get_name() == "Y-Rotation") {
|
||||||
|
// drawing y movement (local)
|
||||||
|
glColor4f(0, 128, 0, 128);
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y(), point_joint.z());
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y()+pt_max, point_joint.z());
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y()-pt_min, point_joint.z());
|
||||||
|
std::cout « "X:" « point_joint.x() « " Y:" « point_joint.y()+pt_max « " Z:" « point_joint.z() « std::endl;
|
||||||
|
std::cout « pt_max « std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(node->get_dof(i)->get_name() == "Z-Rotation") {
|
||||||
|
// drawing z movement (local)
|
||||||
|
glColor4f(0, 128, 0, 128);
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y(), point_joint.z());
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y(), point_joint.z()+pt_max);
|
||||||
|
glVertex3f(point_joint.x(), point_joint.y(), point_joint.z()-pt_min);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// drawing y movement (local)
|
||||||
|
glColor4f(128, 0, 0, 128);
|
||||||
|
glVertex3f(start_point.x(), start_point.y(), start_point.z());
|
||||||
|
glVertex3f(end_point.x(), end_point.y() - 5, end_point.z());
|
||||||
|
glVertex3f(end_point.x(), end_point.y() + 5, end_point.z());
|
||||||
|
|
||||||
|
// drawing z movement (local)
|
||||||
|
glColor4f(0, 0, 128, 128);
|
||||||
|
glVertex3f(start_point.x(), start_point.y(), start_point.z());
|
||||||
|
glVertex3f(end_point.x(), end_point.y(), end_point.z() - 5);
|
||||||
|
glVertex3f(end_point.x() + 5, end_point.y(), end_point.z() + 5);
|
||||||
|
*/
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//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, context &c, int depth)
|
void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_parent_local, context &c, int depth)
|
||||||
{
|
{
|
||||||
|
@ -71,9 +146,10 @@ void SkeletonViewer::draw_skeleton_subtree(Bone *node, const Mat4 &global_to_par
|
||||||
Vec3 p2_v3 = Vec3(p2.x(), p2.y(), p2.z());
|
Vec3 p2_v3 = Vec3(p2.x(), p2.y(), p2.z());
|
||||||
|
|
||||||
glColor3f(colors[depth][0], colors[depth][1], colors[depth][2]);
|
glColor3f(colors[depth][0], colors[depth][1], colors[depth][2]);
|
||||||
|
|
||||||
c.tesselate_arrow(p1_v3, p2_v3);
|
c.tesselate_arrow(p1_v3, p2_v3);
|
||||||
|
|
||||||
|
draw_dof(node, p1);
|
||||||
|
|
||||||
depth++;
|
depth++;
|
||||||
|
|
||||||
for (int i = 0; i < node->childCount(); i++)
|
for (int i = 0; i < node->childCount(); i++)
|
||||||
|
@ -313,8 +389,6 @@ void SkeletonViewer::load_animation()
|
||||||
current_map[bone_name] = values;
|
current_map[bone_name] = values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "successfully loaded anination " << animations.size() << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue