-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkeletalModel.cpp
executable file
·103 lines (84 loc) · 3 KB
/
SkeletalModel.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
#include "SkeletalModel.h"
#include <FL/Fl.H>
using namespace std;
void SkeletalModel::load(const char *skeletonFile, const char *meshFile, const char *attachmentsFile)
{
loadSkeleton(skeletonFile);
m_mesh.load(meshFile);
m_mesh.loadAttachments(attachmentsFile, m_joints.size());
computeBindWorldToJointTransforms();
updateCurrentJointToWorldTransforms();
}
void SkeletalModel::draw(Matrix4f cameraMatrix, bool skeletonVisible)
{
// draw() gets called whenever a redraw is required
// (after an update() occurs, when the camera moves, the window is resized, etc)
m_matrixStack.clear();
m_matrixStack.push(cameraMatrix);
if( skeletonVisible )
{
drawJoints();
drawSkeleton();
}
else
{
// Clear out any weird matrix we may have been using for drawing the bones and revert to the camera matrix.
glLoadMatrixf(m_matrixStack.top());
// Tell the mesh to draw itself.
m_mesh.draw();
}
}
void SkeletalModel::loadSkeleton( const char* filename )
{
// Load the skeleton from file here.
}
void SkeletalModel::drawJoints( )
{
// Draw a sphere at each joint. You will need to add a recursive helper function to traverse the joint hierarchy.
//
// We recommend using glutSolidSphere( 0.025f, 12, 12 )
// to draw a sphere of reasonable size.
//
// You are *not* permitted to use the OpenGL matrix stack commands
// (glPushMatrix, glPopMatrix, glMultMatrix).
// You should use your MatrixStack class
// and use glLoadMatrix() before your drawing call.
}
void SkeletalModel::drawSkeleton( )
{
// Draw boxes between the joints. You will need to add a recursive helper function to traverse the joint hierarchy.
}
void SkeletalModel::setJointTransform(int jointIndex, float rX, float rY, float rZ)
{
// Set the rotation part of the joint's transformation matrix based on the passed in Euler angles.
}
void SkeletalModel::computeBindWorldToJointTransforms()
{
// 2.3.1. Implement this method to compute a per-joint transform from
// world-space to joint space in the BIND POSE.
//
// Note that this needs to be computed only once since there is only
// a single bind pose.
//
// This method should update each joint's bindWorldToJointTransform.
// You will need to add a recursive helper function to traverse the joint hierarchy.
}
void SkeletalModel::updateCurrentJointToWorldTransforms()
{
// 2.3.2. Implement this method to compute a per-joint transform from
// joint space to world space in the CURRENT POSE.
//
// The current pose is defined by the rotations you've applied to the
// joints and hence needs to be *updated* every time the joint angles change.
//
// This method should update each joint's bindWorldToJointTransform.
// You will need to add a recursive helper function to traverse the joint hierarchy.
}
void SkeletalModel::updateMesh()
{
// 2.3.2. This is the core of SSD.
// Implement this method to update the vertices of the mesh
// given the current state of the skeleton.
// You will need both the bind pose world --> joint transforms.
// and the current joint --> world transforms.
}