-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjoint.hpp
144 lines (101 loc) · 3.34 KB
/
joint.hpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef JOINT_H
#define JOINT_H
#include <vector>
#include <string>
#include <cstdio>
#include <glm/glm.hpp>
#include "motion.hpp"
// Used for our spherical linear interpolation
#include "quaternion.hpp"
// Uncomment this to disable rotations ( debugging )
//#define JOINT_DISABLE_ROTATIONS
#define DISABLE_SLERP 0
class Joint {
public:
Joint(bool root = false, bool end = false, Joint *parent=0) {
is_root=root;
is_end=end;
this->o.x = this->o.y = this->o.z = 0;
this->original.x = this->original.y = this->original.z = 0;
this->parent = parent;
this->initialized = false;
this->channel_offset = 0;
}
// Reads a joint from the FILE fp.
// As joint descriptions are recursive, this is used to process the joint-to-joint connections and offsets for
// the sampled motion data.
//Starts reading after a joint keyword ( ROOT, JOINT or End)
// FILE fp must have previously opened.
// In case of failure in the parsing process, returns false.
bool process(FILE *fp);
// class setters
// Sets the name of this joint
void set_name(const char *new_name) { name = new_name; }
void set_offset(const double x, const double y, const double z) {
this->o.x = x;
this->o.y = y;
this->o.z = z;
if ( !initialized ) {
this->original.x = x;
this->original.y = y;
this->original.z = z;
this->initialized = true;
}
}
const char * get_name() { return name.c_str(); }
// Writes the joint, and its hierachy, to the file *out_fp
void print(FILE *out_fp,const char *offset = "\0" );
// Debugging print
void pretty_print(const char *offset);
const std::vector<Joint *> & get_children() { return subjoints; }
bool has_children() { return subjoints.size() > 0 ; }
const Joint * get_parent() { return parent; }
const glm::vec3 get_offset() { return o; }
int count_hierarchy_channels();
// Based on motion information, run the transformations on the hierarchy
void render_transformation( const Motion::frame_data & data , bool original_pose=false );
// Render this joint and all its subjoints using frames data and data2 ( interpolated )
void render_transformation( const Motion::frame_data & data, const Motion::frame_data & data2, const float lambda , bool original_pose=false );
// Returns all offsets to their original position
// Recursive functions, restores all the hierarchy
void restore();
void translate( double x, double y, double z ) {
o.x+=x;
o.y+=y;
o.z+=z;
}
private:
// OFFSET structure
glm::vec3 o;
glm::vec3 original;
bool initialized;
// CHANNEL TYPES
typedef enum {
X_POSITION = 0,
Y_POSITION,
Z_POSITION,
X_ROTATION,
Y_ROTATION,
Z_ROTATION
} ChannelType;
// ChannelVector
std::vector<ChannelType> channels;
int channel_offset;
// Read channels description from the file
void read_channels(FILE *fp);
Joint *parent;
std::vector<Joint *> subjoints;
// Name of this joint
std::string name;
// The root and the end elementsin the hierachy are also considered joints in this
// implementation.
bool is_root;
bool is_end;
//HELPER functions
glm::vec3 get_center();
// Render a a line between p1 and p2
void render_bone(glm::vec3 p1, glm::vec3 p2);
// Spherical interpolation, used for rotations
void slerp(Quaternion q1, Quaternion q2, Quaternion &qr , double lambda);
};
#endif