1 /*
2  * Skeleton.h
3  * Copyright (C) 2007 by Bryan Duff <duff0097@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #ifndef _SKELETON_H_
21 #define _SKELETON_H_
22 
23 /**> HEADER FILES <**/
24 #include <GL/gl.h>
25 #include <AL/al.h>
26 #include <AL/alut.h>
27 #include "Quaternions.h"
28 #include "Constants.h"
29 #include "Files.h"
30 #include "Models.h"
31 #include "Camera.h"
32 #include "Globals.h"
33 
34 #define boneconnect 0
35 #define constraint 1
36 #define muscle 2
37 
38 //head, neck, left shoulder, left elbow, left wrist, left hand
39                 //right shoulder, right elbow, right wrist, right hand,
40                 //middle, left hip, right hip,groin
41                 //left knee,left ankle, left foot, right knee, right ankle, right foort
42 
43 #define head 1
44 #define neck 2
45 #define leftshoulder 3
46 #define leftelbow 4
47 #define leftwrist 5
48 #define lefthand 6
49 #define rightshoulder 7
50 #define rightelbow 8
51 #define rightwrist 9
52 #define righthand 10
53 #define abdomen 11
54 #define lefthip 12
55 #define righthip 13
56 #define groin 14
57 #define leftknee 15
58 #define leftankle 16
59 #define leftfoot 17
60 #define rightknee 18
61 #define rightankle 19
62 #define rightfoot 20
63 
64 class Joint {
65 public:
66   XYZ position;
67   XYZ oldposition;
68   XYZ realoldposition;
69   XYZ velocity;
70   XYZ offset;
71   float blurred;
72   float length;
73   float mass;
74   bool lower;
75   bool hasparent;
76   bool locked;
77   int modelnum;
78   bool visible;
79   bool existing;
80   Joint *parent;
81   int label;
82   int hasgun;
83   float rotate1, rotate2, rotate3;
84 
85   void DoConstraint();
86 };
87 
88 class Muscle {
89 public:
90   float length;
91   float targetlength;
92   Joint *parent1;
93   Joint *parent2;
94   float maxlength;
95   float minlength;
96   int type;
97   bool visible;
98   void DoConstraint(int broken);
99   float rotate1, rotate2, rotate3;
100 
101   float strength;
102 };
103 
104 class Animation {
105 public:
106   Files files;
107   int numframes;
108   bool canbeoverridden;
109   bool ismodified[max_joints][max_frames];
110   XYZ position[max_joints][max_frames];
111   float twist[max_joints][max_frames];
112   float twist2[max_joints][max_frames];
113   float speed[max_frames];
114   float gunrotation[max_frames];
115   bool onground[max_joints][max_frames];
116   XYZ forward[max_frames];
117   float rotate1[max_joints][max_frames], rotate2[max_joints][max_frames],
118       rotate3[max_joints][max_frames];
119   float mrotate1[max_joints][max_frames], mrotate2[max_joints][max_frames],
120       mrotate3[max_joints][max_frames];
121   void Load(char *fileName);
122   void Load(char *fileName, float rotate);
123 };
124 
125 
126 class Skeleton {
127 public:
128   int num_joints;
129   Joint joints[max_joints];
130   int jointlabels[max_joints];
131 
132   int num_muscles;
133   Muscle muscles[max_muscles];
134 
135   int selected;
136 
137   int forwardjoints[3];
138   XYZ forward;
139 
140   int lowforwardjoints[3];
141   XYZ lowforward;
142 
143   int broken;
144   bool offset;
145 
146   XYZ specialforward[5];
147 
148   bool free;
149 
150   Files files;
151 
152   void DoConstraints();
153   void DoConstraints(Model * collide, XYZ * move, float rotation);
154   void DoGravity();
155   void DoBalance();
156   void MusclesSet();
157   void Draw(int muscleview);
158   void AddJoint(float x, float y, float z, int which);
159   void SetJoint(float x, float y, float z, int which, int whichjoint);
160   void DeleteJoint(int whichjoint);
161   void AddMuscle(int attach1, int attach2, float maxlength, float minlength,
162                  int type);
163   void DeleteMuscle(int whichmuscle);
164   void FindRotationJoint(int which);
165   void FindRotationMuscle(int which);
166   void Load(char *fileName);
167 };
168 
169 #endif
170