-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJointNode.cpp
49 lines (40 loc) · 1.31 KB
/
JointNode.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
#include "JointNode.h"
#include <assert.h>
#include "os.h"
JointNode::JointNode(const string& id, double xToJoint, double yToJoint, double zToJoint,
double xFromJoint, double yFromJoint, double zFromJoint)
: SceneNode(id) {
angle_[(int)ABOUT_X] = 0.0;
angle_[(int)ABOUT_Y] = 0.0;
angle_[(int)ABOUT_Z] = 0.0;
displacementFromParent_[0] = xToJoint;
displacementFromParent_[1] = yToJoint;
displacementFromParent_[2] = zToJoint;
displacementToChild_[0] = xFromJoint;
displacementToChild_[1] = yFromJoint;
displacementToChild_[2] = zFromJoint;
}
JointNode::~JointNode() {
}
void JointNode::bend(double a, MotionType direction) {
angle_[(int)direction] = a;
}
void JointNode::straighten() {
angle_[0] = 0;
angle_[1] = 0;
angle_[2] = 0;
}
void JointNode::render() {
glPushMatrix();
glTranslated(displacementFromParent_[0], displacementFromParent_[1], displacementFromParent_[2]);
glRotated(angle_[(int)ABOUT_X], 1.0, 0.0, 0.0);
glRotated(angle_[(int)ABOUT_Y], 0.0, 1.0, 0.0);
glRotated(angle_[(int)ABOUT_Z], 0.0, 0.0, 1.0);
glTranslated(displacementToChild_[0], displacementToChild_[1], displacementToChild_[2]);
SceneNode::render();
glPopMatrix();
}
void JointNode::addChild(SceneNode* child) {
assert(SceneNode::getNumChildren() < 2);
SceneNode::addChild(child);
}