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