]> git.jsancho.org Git - lugaru.git/blob - Source/Skeleton.h
beautified code
[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     void Move(XYZ how);
141
142 protected:
143     void deallocate();
144 };
145
146
147 const int max_joints = 50;
148
149 class Skeleton
150 {
151 public:
152     int num_joints;
153     //Joint joints[max_joints];
154     //Joint *joints;
155     Joint* joints;
156
157     int num_muscles;
158     //Muscle muscles[max_muscles];
159     //Muscle *muscles;
160     Muscle* muscles;
161
162     int selected;
163
164     int forwardjoints[3];
165     XYZ forward;
166
167     int id;
168
169     int lowforwardjoints[3];
170     XYZ lowforward;
171
172     XYZ specialforward[5];
173     int jointlabels[max_joints];
174
175     Model model[7];
176     Model modellow;
177     Model modelclothes;
178     int num_models;
179
180     Model drawmodel;
181     Model drawmodellow;
182     Model drawmodelclothes;
183
184     bool clothes;
185     bool spinny;
186
187     GLubyte skinText[512 * 512 * 3];
188     int skinsize;
189
190     float checkdelay;
191
192     float longdead;
193     bool broken;
194
195     int free;
196     int oldfree;
197     float freetime;
198     bool freefall;
199
200     void FindForwards();
201     void FindForwardsfirst();
202     float DoConstraints(XYZ *coords, float *scale);
203     void DoGravity(float *scale);
204     void DoBalance();
205     void MusclesSet();
206     void Draw(int muscleview);
207     void AddJoint(float x, float y, float z, int which);
208     void SetJoint(float x, float y, float z, int which, int whichjoint);
209     void DeleteJoint(int whichjoint);
210     void AddMuscle(int attach1, int attach2, float maxlength, float minlength, int type);
211     void DeleteMuscle(int whichmuscle);
212     void FindRotationJoint(int which);
213     void FindRotationJointSameTwist(int which);
214     void FindRotationMuscle(int which, int animation);
215     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);
216
217     Skeleton();
218     ~Skeleton();
219 };
220
221 #endif