]> git.jsancho.org Git - lugaru.git/blob - Source/Skeleton.h
License: Update GPLv2+ header to match current FSF recommendation
[lugaru.git] / Source / Skeleton.h
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 Lugaru is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _SKELETON_H_
21 #define _SKELETON_H_
22
23 #include "Models.h"
24 #include "Quaternions.h"
25
26
27 /**> HEADER FILES <**/
28 #include "gamegl.h"
29 #include "Quaternions.h"
30 #include "Objects.h"
31 #include "Sprite.h"
32 #include "binio.h"
33
34 enum bodyparts {
35     head, neck,
36     leftshoulder,  leftelbow,  leftwrist,  lefthand,
37     rightshoulder, rightelbow, rightwrist, righthand,
38     abdomen, lefthip, righthip, groin,
39     leftknee,  leftankle,  leftfoot,
40     rightknee, rightankle, rightfoot
41 };
42
43 class Joint
44 {
45 public:
46     XYZ position;
47     XYZ oldposition;
48     XYZ realoldposition;
49     XYZ velocity;
50     XYZ oldvelocity;
51     XYZ startpos;
52     float blurred;
53     float length;
54     float mass;
55     bool lower;
56     bool hasparent;
57     bool locked;
58     int modelnum;
59     bool visible;
60     Joint* parent;
61     bool sametwist;
62     int label;
63     int hasgun;
64     float delay;
65     XYZ velchange;
66
67     Joint() {
68         blurred = 0;
69         length = 0;
70         mass = 0;
71         lower = 0;
72         hasparent = 0;
73         locked = 0;
74         modelnum = 0;
75         visible = 0;
76         parent = 0;
77         sametwist = 0;
78         label = 0;
79         hasgun = 0;
80         delay = 0;
81     }
82 };
83
84 class Muscle
85 {
86 public:
87     int numvertices;
88     int* vertices;
89     int numverticeslow;
90     int* verticeslow;
91     int numverticesclothes;
92     int* verticesclothes;
93     float length;
94     float targetlength;
95     Joint* parent1;
96     Joint* parent2;
97     float maxlength;
98     float minlength;
99     int type;
100     bool visible;
101     float rotate1, rotate2, rotate3;
102     float lastrotate1, lastrotate2, lastrotate3;
103     float oldrotate1, oldrotate2, oldrotate3;
104     float newrotate1, newrotate2, newrotate3;
105
106     float strength;
107
108     Muscle();
109     ~Muscle();
110     void DoConstraint(bool spinny);
111 };
112
113 class Animation
114 {
115 public:
116     int numframes;
117     int height;
118     int attack;
119     int joints;
120     int weapontargetnum;
121
122     XYZ**  position;
123     float** twist;
124     float** twist2;
125     float* speed;
126     bool** onground;
127     XYZ* forward;
128     int* label;
129     XYZ* weapontarget;
130
131     XYZ offset;
132
133     Animation();
134     ~Animation();
135     Animation & operator = (const Animation & ani);
136
137     void Load(const char *fileName, int aheight, int aattack);
138
139 protected:
140     void deallocate();
141 };
142
143
144 const int max_joints = 50;
145
146 class Skeleton
147 {
148 public:
149     int num_joints;
150     //Joint joints[max_joints];
151     //Joint *joints;
152     Joint* joints;
153
154     int num_muscles;
155     //Muscle muscles[max_muscles];
156     //Muscle *muscles;
157     Muscle* muscles;
158
159     int selected;
160
161     int forwardjoints[3];
162     XYZ forward;
163
164     int id;
165
166     int lowforwardjoints[3];
167     XYZ lowforward;
168
169     XYZ specialforward[5];
170     int jointlabels[max_joints];
171
172     Model model[7];
173     Model modellow;
174     Model modelclothes;
175     int num_models;
176
177     Model drawmodel;
178     Model drawmodellow;
179     Model drawmodelclothes;
180
181     bool clothes;
182     bool spinny;
183
184     GLubyte skinText[512 * 512 * 3];
185     int skinsize;
186
187     float checkdelay;
188
189     float longdead;
190     bool broken;
191
192     int free;
193     int oldfree;
194     float freetime;
195     bool freefall;
196
197     void FindForwards();
198     float DoConstraints(XYZ *coords, float *scale);
199     void DoGravity(float *scale);
200     void FindRotationJoint(int which);
201     void FindRotationJointSameTwist(int which);
202     void FindRotationMuscle(int which, int animation);
203     void Load(const char *fileName, const char *lowfileName, const char *clothesfileName, const char *modelfileName, const char *model2fileName, const char *model3fileName, const char *model4fileName, const char *model5fileNamee, const char *model6fileName, const char *model7fileName, const char *modellowfileName, const char *modelclothesfileName, bool aclothes);
204
205     /*
206     // unused
207     void FindForwardsfirst();
208     void Draw(int muscleview);
209     void AddJoint(float x, float y, float z, int which);
210     void SetJoint(float x, float y, float z, int which, int whichjoint);
211     void DeleteJoint(int whichjoint);
212     void AddMuscle(int attach1, int attach2, float maxlength, float minlength, int type);
213     void DeleteMuscle(int whichmuscle);
214     void DoBalance();
215     void MusclesSet();
216     */
217
218     Skeleton();
219     ~Skeleton();
220
221 private:
222     // convenience functions
223     // only for Skeleton.cpp
224     inline Joint& joint(int bodypart) { return joints[jointlabels[bodypart]]; }
225     inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
226     inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
227
228 };
229
230 #endif