00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GLSKELETAL_H
00019 #define GLSKELETAL_H
00020
00021 #include <GL/gl.h>
00022 #include <list>
00023 #include <functional>
00024 #include <algorithm>
00025 #include <iostream>
00026 #include <string>
00027
00028 #include "gltrianglemesh.h"
00029 #include "glmaterial.h"
00030 #include "glimage.h"
00031
00032 #define ANIM_IDLE 1
00033
00034 using namespace std;
00039 class GLSkeletalModel;
00040 class GLSkeletalSegment;
00041 class GLSkeletalKeyFrame;
00042 class GLSkeletalAnimation;
00043
00044 class GLSkeletalKeyFrame
00045 {
00046
00047 GLfloat roll;
00048 GLfloat pitch;
00049 GLfloat yaw;
00050 GLuint duration;
00051
00052 public:
00053 static char startTag[20];
00054 static char endTag[20];
00055
00056 GLSkeletalKeyFrame();
00057 GLSkeletalKeyFrame(GLfloat r, GLfloat p, GLfloat y, GLuint d)
00058 :roll(r), pitch(p), yaw(y), duration(d) {}
00059
00060 ~GLSkeletalKeyFrame();
00061
00062 void set(GLfloat p, GLfloat y, GLfloat r, GLuint t)
00063 { setPitch(p); setYaw(y); setRoll(r); setDuration(t); };
00064
00065 void setRoll(GLfloat r);
00066 void setPitch(GLfloat p);
00067 void setYaw(GLfloat y);
00068 void setDuration(GLint t);
00069
00070 inline const GLfloat getPitch() { return pitch; };
00071 inline const GLfloat getRoll() { return roll; };
00072 inline const GLfloat getYaw() { return yaw; };
00073 inline const GLuint getDuration() { return duration; };
00074
00075 void applyToSegment(GLSkeletalSegment* gls, GLuint currentTime, GLSkeletalKeyFrame* prev);
00076 void loadFromStream(istream& in);
00077 void saveToStream(ostream& out);
00078 };
00079
00080 class GLSkeletalAnimation
00081 {
00082 list<GLSkeletalKeyFrame*> keyFrame;
00083 list<GLSkeletalKeyFrame*>::iterator currentKeyFrame;
00084 GLuint animGroup;
00085
00086
00087 public:
00088 static char startTag[20];
00089 static char endTag[20];
00090
00091 GLSkeletalAnimation(GLuint anGR);
00092 ~GLSkeletalAnimation();
00093
00094 GLuint getAnimGroup() { return animGroup; };
00095 GLuint getTotalTime();
00096
00097 void addKeyFrame(GLSkeletalKeyFrame* kf)
00098 { keyFrame.push_back(kf); currentKeyFrame = keyFrame.begin(); };
00099
00100 void removeKeyFrame(GLSkeletalKeyFrame* kf)
00101 { keyFrame.remove(kf); currentKeyFrame = keyFrame.begin(); };
00102
00103 GLSkeletalKeyFrame* getKeyFrame();
00104 GLSkeletalKeyFrame* nextKeyFrame();
00105 GLSkeletalKeyFrame* previousKeyFrame();
00106 GLuint timeToKeyFrame();
00107
00108 void animate(GLSkeletalSegment* gls, GLuint time);
00109 void loadFromStream(istream& in);
00110 void saveToStream(ostream& out);
00111 };
00112
00113 class GLSkeletalSegment
00114 {
00115 string name;
00116
00117 GLTriangleMesh* triMesh;
00118
00119 protected:
00120 bool selected;
00121
00122
00123 list<GLSkeletalSegment*> joint;
00124
00125 list<GLSkeletalAnimation*> animation;
00126
00127
00128 GLfloat roll;
00129 GLfloat pitch;
00130 GLfloat yaw;
00131
00132
00133 GLfloat length;
00134
00135 GLuint animGrp;
00136
00137 public:
00138 static char startTag[20];
00139 static char endTag[20];
00140
00141 GLSkeletalSegment();
00142 virtual ~GLSkeletalSegment();
00143
00144 void setLength(GLfloat l);
00145 void setMaterial(GLScene::GLMaterial m);
00146
00147 void addSegment(GLSkeletalSegment* gls);
00148 void addAnimation(GLSkeletalAnimation* gla);
00149 void animate(GLuint time);
00150 void animateLooped(GLuint time);
00151
00152
00153 void set(GLfloat p, GLfloat y, GLfloat r);
00154 void setRoll(GLfloat r);
00155 void setPitch(GLfloat p);
00156 void setYaw(GLfloat y);
00157
00158 void setAnimGroup(GLuint ag) { animGrp = ag; }
00159 GLuint getAnimGroup() { return animGrp; }
00160 GLSkeletalAnimation* getAnimation();
00161
00162 void selectLeftSibling();
00163 void selectRightSibling();
00164 void selectChild();
00165 void selectParent();
00166 void select();
00167 void unselect();
00168
00169 void setMesh(GLTriangleMesh* newMesh)
00170 { if(triMesh) delete triMesh; triMesh = newMesh; }
00171
00172 GLSkeletalSegment* getSelected();
00173 GLTriangleMesh* getMesh() { return triMesh; }
00174
00175 GLfloat getRoll();
00176 GLfloat getPitch();
00177 GLfloat getYaw();
00178 GLfloat getLength() { return length; }
00179
00180
00181 virtual void render(GLTenum renderMode);
00182
00183 virtual void loadFromStream(istream& in);
00184 virtual void saveToStream(ostream& out);
00185 };
00186
00187
00188 class GLSkeletalModel: public GLSkeletalSegment
00189 {
00190 string name;
00191 string fileName;
00192
00193 GLuint time;
00194
00195 public:
00196 static char startTag[20];
00197 static char endTag[20];
00198
00199 GLSkeletalModel();
00200 virtual ~GLSkeletalModel();
00201
00202 void setTime(GLuint t) { time = t; }
00203 GLuint getTime() { return time; }
00204 void setFileName(string fName) { fileName = fName; }
00205 string getFileName() { return fileName; }
00206
00207 void animate() { GLSkeletalSegment::animate(time); }
00208 void animateLooped() { GLSkeletalSegment::animateLooped(time); }
00209 virtual void texture();
00210 virtual void untexture();
00211 virtual void render(GLTenum renderMode);
00212
00213
00214 static GLSkeletalModel* loadFromFile(string fName);
00215 void saveToFile();
00216
00217 virtual void saveToStream(ostream& out);
00218 };
00219
00220 #endif