-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeletonRenderer.cpp
104 lines (91 loc) · 2.42 KB
/
skeletonRenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "skeletonRenderer.h"
#include "openGLHelper.h"
#include "FK.h"
using namespace std;
// CSCI 520 Computer Animation and Simulation
// Jernej Barbic and Yijing Li
SkeletonRenderer::SkeletonRenderer(const FK* fk, double localAxisLength)
{
renderedLocalAxisLength = localAxisLength;
this->fk = fk;
}
void SkeletonRenderer::renderSkeleton() const
{
// save attributes
glPushAttrib(GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT);
// render joint position
glColor3f(1, 0, 0);
glPointSize(20);
glBegin(GL_POINTS);
for (int jointID = 0; jointID < fk->getNumJoints(); jointID++)
Draw(fk->getJointGlobalPosition(jointID));
glEnd();
// render the connection between joints
glLineWidth(5.0);
glColor3f(1, 1, 0);
glBegin(GL_LINES);
for (int jointID = 0; jointID < fk->getNumJoints(); jointID++)
{
int parentID = fk->getJointParent(jointID);
if (parentID < 0)
continue;
Draw(fk->getJointGlobalPosition(jointID), fk->getJointGlobalPosition(parentID));
}
glEnd();
glPopAttrib();
}
void SkeletonRenderer::renderJointCoordAxes(int jointID) const
{
// save attributes
glPushAttrib(GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT);
Vec3d jointPos = fk->getJointGlobalPosition(jointID);
// render coordinate frame of the joint
glLineWidth(8.0);
glBegin(GL_LINES);
for (int d = 0; d < 3; d++)
{
Vec3d axisEndPosLocal(0.0);
axisEndPosLocal[d] = renderedLocalAxisLength;
Vec3d axisEndPosGlobal = fk->getJointGlobalTransform(jointID).transformPoint(axisEndPosLocal);
Vec3d color(0, 0, 0);
color[d] = 1.0;
glColor3f(color[0], color[1], color[2]);
Draw(jointPos);
Draw(axisEndPosGlobal);
}
glEnd();
glPopAttrib();
}
void SkeletonRenderer::renderJoint(int jointID) const
{
// save attributes
glPushAttrib(GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT);
// render joint position
Vec3d jointPos = fk->getJointGlobalPosition(jointID);
glColor3f(1, 0, 0);
glPointSize(10);
glBegin(GL_POINTS);
Draw(jointPos);
glEnd();
// render descedents joints
glLineWidth(5.0);
glColor3f(1, 0, 0);
vector<int> descedentIDs = fk->getJointDescendents(jointID);
glBegin(GL_LINES);
for (int childID : descedentIDs)
{
int parentID = fk->getJointParent(childID);
Draw(fk->getJointGlobalPosition(parentID));
Draw(fk->getJointGlobalPosition(childID));
}
glEnd();
glColor3f(0, 0, 1);
glPointSize(10);
glBegin(GL_POINTS);
for (int childID : descedentIDs)
{
Draw(fk->getJointGlobalPosition(childID));
}
glEnd();
glPopAttrib();
}