Gel2D - The free/open source game creation suite

gelArmature.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2010-2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELARMATURE_H__
00017 #define __GELARMATURE_H__
00018 
00019 #include "gelObject.h"
00020 #include "gelString.h"
00021 
00022 #define GEL2D_BONESYS_HEADER "GEL2D_BONESYS_v0.1"
00023 
00024 #define GEL_MAX_BONES 64
00025 #define GEL_MAX_BONE_CHILDREN 8
00026 
00027 
00028 // Notes on bone system design:
00029 // Meshes will be oblivious to armature's existence, except maybe for parenting.
00030 // Bones will hold pointers to vertices and extra vertex data (weights, etc.), and manipulate accordingly.
00031 // Bones should probably store their own matrices, to keep things fast and sweet.
00032 
00033 namespace gel
00034 {
00038 
00039 
00041         class GelBone
00042         {
00043                 public:
00045             GelBone();
00046 
00047             GelBone *getParent() { return parent; }
00048             void setParent(     GelBone *par ) { parent = par; }
00049 
00050             void addChild( GelBone *child );
00051             GelBone *getChild( int index );
00052 
00053             void setPos( Gel2dVec bpos ) { pos = bpos; }
00054             float getAngle() { return angle; }
00055             void setAngle( float bangle ) { angle = bangle; }
00056             float getLength() { return length; }
00057             void setLength( float blength ) { length = blength; }
00058 
00059             void setName( GelString strname ) { name = strname; }
00060 
00061             int getPosMode() { return posMode; }
00062             void setPosMode( int mode ) { posMode = mode; }
00063 
00064             int hasParent();
00065             int hasChildren();
00066 
00067             void drawBoneAbsolute();
00068             void drawBoneRelative();
00069 
00070         private:
00071                         Gel2dVec pos;
00072                         float angle;
00073                         float length;
00074 
00075                         GelBone *parent;
00076                         GelBone *child[GEL_MAX_BONE_CHILDREN];
00077                         GelString name;
00078 
00079                         int childCount;
00080                         int posMode;
00081         };
00082 
00084 
00087     class GelArmature : public GelObject
00088     {
00089         public:
00091             GelArmature();
00092 
00094 
00097             GelArmature( const char *desc_name );
00098 
00100 
00104             GelArmature( Gel2dVec obj_pos, float obj_rot, Gel2dVec obj_scl );
00105 
00107 
00109             void addBone( GelBone *parent = NULL, const char *name = "Bone");
00110 
00112 
00113             void writeDesc( const char *filename );
00114 
00116 
00119             int readDesc( const char *filename );
00120 
00122             void render();
00123 
00124         private:
00125                         int boneCount;
00126 
00127                 public:
00128                         GelBone bone[GEL_MAX_BONES];
00129     };
00130 
00132 }
00133 
00134 #endif