SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLJoint.cpp
Go to the documentation of this file.
1 /**
2  * \file SLJoint.cpp
3  * \date Autumn 2014
4  * \authors Marc Wacker, Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #include <SLJoint.h>
11 #include <SLAnimSkeleton.h>
12 
13 //-----------------------------------------------------------------------------
14 /*! Constructor
15  */
17  : SLNode("Unnamed Joint"),
18  _id(id),
19  _skeleton(creator),
20  _radius(0)
21 {
22 }
23 //-----------------------------------------------------------------------------
24 /*! Constructor
25  */
26 SLJoint::SLJoint(const SLstring& name, SLuint id, SLAnimSkeleton* creator)
27  : SLNode(name), _id(id), _skeleton(creator), _radius(0)
28 {
29 }
30 //-----------------------------------------------------------------------------
31 /*! Creation function to create a new child joint for this joint.
32  */
34 {
35  SLJoint* joint = _skeleton->createJoint(id);
36  addChild(joint);
37  return joint;
38 }
39 //-----------------------------------------------------------------------------
40 /*! Creation function to create a new child joint for this joint.
41  */
43 {
44  SLJoint* joint = _skeleton->createJoint(name, id);
45  addChild(joint);
46  return joint;
47 }
48 //-----------------------------------------------------------------------------
49 /*! Updates the current max radius with the input vertex position in joint space.
50  */
52 {
53  SLVec3f boneSpaceVec = _offsetMat * vec;
54  _radius = std::max(_radius, boneSpaceVec.length());
55 }
56 //-----------------------------------------------------------------------------
57 /*! Getter that calculates the final joint transform matrix.
58  */
60 {
61  return updateAndGetWM() * _offsetMat;
62 }
63 //-----------------------------------------------------------------------------
64 /*! Getter that calculates the final joint transform matrix.
65  */
67 {
69 
70  // a joint must always know it's creator
71  assert(_skeleton && "Joint didn't have a valid creator");
72  _skeleton->changed(true);
73 }
74 //-----------------------------------------------------------------------------
unsigned int SLuint
Definition: SL.h:171
string SLstring
Definition: SL.h:158
SLAnimSkeleton keeps track of a skeletons joints and animations.
SLbool changed() const
SLJoint * createJoint(SLuint id)
Specialized SLNode that represents a single joint (or bone) in a skeleton.
Definition: SLJoint.h:27
SLMat4f calcFinalMat()
Definition: SLJoint.cpp:59
SLJoint(SLuint handle, SLAnimSkeleton *creator)
Definition: SLJoint.cpp:16
SLMat4f _offsetMat
matrix transforming this joint from bind pose to world pose
Definition: SLJoint.h:54
SLAnimSkeleton * _skeleton
the skeleton this joint belongs to
Definition: SLJoint.h:53
void calcMaxRadius(const SLVec3f &vec)
Definition: SLJoint.cpp:51
SLJoint * createChild(SLuint id)
Definition: SLJoint.cpp:33
void needUpdate()
Definition: SLJoint.cpp:66
SLfloat _radius
info for the mesh this skeleton is bound to (should be moved to a skeleton instance class later,...
Definition: SLJoint.h:55
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
virtual void needUpdate()
Definition: SLNode.cpp:616
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
const SLstring & name() const
Definition: SLObject.h:38
T length() const
Definition: SLVec3.h:122