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