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