Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

constants.h

00001 /***************************************************************************
00002                           constants.h  -  description
00003                              -------------------
00004     begin                : Sun Oct 12 2003
00005     copyright            : (C) 2003 by Gabor Torok
00006     email                : cctorok@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef CONSTANTS_H
00019 #define CONSTANTS_H
00020 
00021 // autopackage's binary relocation lib
00022 #include "prefix.h"
00023 
00024 // from tuxracer
00025 #if defined ( __MWERKS__ ) || defined( _MSC_VER ) || defined( WIN32 )
00026 #   define NATIVE_WIN32_COMPILER 1
00027 #else
00028 /* Assume UNIX compatible by default */
00029 #   define COMPILER_IS_UNIX_COMPATIBLE 1
00030 #endif
00031 
00032 // include sdl, opengl and glut
00033 #include <SDL.h>
00034 #include <SDL_opengl.h>
00035 #include <SDL_endian.h>
00036 
00037 #ifdef HAVE_SDL_NET
00038 #include <SDL_net.h>
00039 #include <SDL_thread.h>
00040 #endif
00041 
00042 #ifdef HAVE_SDL_MIXER
00043 #include <SDL_mixer.h>
00044 #endif
00045 
00046 #if defined(__APPLE__) || defined(__MACH_O__)
00047 // *** #include <GLUT/glut.h>
00048 #else
00049 // *** #include <GL/glut.h>
00050 #ifndef WIN32
00051 // Could not get these to include on my Mandrake9 box...
00052 #ifndef APIENTRY
00053 #define APIENTRY
00054 #endif
00055 typedef void (APIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
00056 typedef void (APIENTRY * PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
00057 typedef void (APIENTRY * PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
00058 #endif
00059 #endif
00060 #include <stdlib.h>
00061 #include <math.h>
00062 #include <vector>
00063 #include <queue>
00064 #include <map>
00065 #include <iostream>
00066 
00067 
00068 #if defined( COMPILER_IS_UNIX_COMPATIBLE )
00069 #   include <unistd.h>
00070 #   include <pwd.h>
00071 #   include <dirent.h>
00072 #   include <sys/time.h>
00073 #   include <sys/types.h>
00074 #   include <dirent.h>
00075 #   include <sys/stat.h>
00076 #endif
00077 
00078 using namespace std;
00079 
00080 #ifdef WIN32
00081 #define SEPARATOR '\\'
00082 #else
00083 #define SEPARATOR '/'
00084 #endif
00085 
00086 /*
00087   Data and config dirs. Shamelessly borrowed from tuxracer.
00088  */
00089 #if defined( WIN32 )
00090 #  define CONFIG_DIR "."
00091 #  define CONFIG_FILE "options.txt"
00092 #else
00093 #  define CONFIG_DIR ".scourge"
00094 #  define CONFIG_FILE "options"
00095 #endif /* defined( WIN32 ) */
00096 
00097 #ifndef DATA_DIR
00098 #  if defined( WIN32 )
00099 #    define DATA_DIR "./data"
00100 #  else
00101 #    define DATA_DIR "/usr/local/share/scourge"
00102 #  endif /* defined( WIN32 ) */
00103 #endif
00104 
00105 
00106 
00107 // debug flags
00108 #define DEBUG_BATTLE 0
00109 
00110 
00111 #define SCOURGE_VERSION "0.10"
00112 #define MAX_PARTY_SIZE 4
00113 
00114 // Max level depth per mission
00115 #define MAX_MISSION_DEPTH 10
00116 
00117 #define toint(x) (int)(x<0 ? (x - 0.5f) : (x + 0.5f))
00118 
00119 //extern char rootDir[300];
00120 extern char *rootDir;
00121 extern char configDir[300];
00122 extern int get_config_dir_name( char *buff, int len );
00123 extern int get_config_file_name( char *buff, int len );
00124 extern int get_file_name( char *buff, int len, char *fileName );
00125 
00126 // opengl extension function ptrs for SDL (set in sdlhandler.cpp)
00127 extern PFNGLACTIVETEXTUREARBPROC glSDLActiveTextureARB;
00128 extern PFNGLMULTITEXCOORD2FARBPROC glSDLMultiTexCoord2fARB;
00129 extern PFNGLMULTITEXCOORD2IARBPROC glSDLMultiTexCoord2iARB;
00130 
00131 // some windows versions of opengl don't have this
00132 #define GL_BGR                                  0x80E0
00133 #define GL_BGRA                                 0x80E1
00134 
00135 
00136 /*
00137   Float swapping code by:
00138   Ramin Firoozye' -- rp&A Inc.
00139   1995/06/30 found on Google groups
00140  */
00141 
00142 /*
00143  * Helpful macros in swapping bytes etc...
00144  * This union lets  us map just about any common datatype onto the
00145  * specified value, so we can use direct array access to do byte, word,
00146  * or long swapping.
00147  */
00148 union NetValue
00149 {
00150   short s;  /* Straight 2-byte short */
00151   unsigned short sU; /* unsigned short */
00152   unsigned char sC[2]; /* short as bytes */
00153 
00154   long l;  /* Straight 4-byte long */
00155   unsigned long lU; /* unsigned long */
00156   unsigned char lC[4]; /* long as bytes */
00157   unsigned short lS[2]; /* long as short */
00158 
00159   float f;  /* Straight (presumed) 4-byte single */
00160   unsigned char fC[4]; /* single as bytes */
00161   unsigned short fS[2]; /* single as short */
00162 
00163   double g;  /* Straight (presumed) 8-byte double */
00164   unsigned char gC[8]; /* double as bytes */
00165   unsigned short gS[4]; /* double as short */
00166   unsigned long gL[2]; /* double as long */
00167 };
00168 typedef union NetValue NetValue;
00169 
00170 /* 
00171  * We define macros as mSWAPn where m is one of B=Byte, W=word and L=long
00172  * and n is one of B=byte, W=word, L=long, F=single float, 
00173  * and G=double float. We are swapping n in chunks of m. So WSWAPL is
00174  * a word-swap of a longword (i.e. we swap the first and second words).
00175  * and BSWAPG is a byte-swap of a double (i.e. total reversal of byte order
00176  * across all 8 bytes). For float and double values, we don't do bit
00177  * swapping of any sort (just B, W, and L). So if the network format of
00178  * the floating value is too damn obscure, something more complicated
00179  * has to be done...
00180  */
00181 
00182 #define BSWAPW(src, dst) { NetValue _t; _t.s = src; \
00183  ((char *)&dst)[0] = _t.sC[1]; ((char *)&dst)[1] = _t.sC[0]; \
00184 }
00185 #define BSWAPL(src, dst) { NetValue _t; _t.lU = src; \
00186  ((char *)&dst)[0] = _t.lC[3]; ((char *)&dst)[1] = _t.lC[2]; \
00187  ((char *)&dst)[2] = _t.lC[1]; ((char *)&dst)[3] = _t.lC[0]; \
00188 }
00189 #define WSWAPL(src, dst) { NetValue _t; _t.lU = src; \
00190  ((short *)&dst)[0] = _t.lS[1]; ((short *)&dst)[1] = _t.lS[0]; \
00191 }
00192 #define BSWAPF(src, dst) { NetValue _t; _t.f = src; \
00193  ((char *)&dst)[0] = _t.fC[3]; ((char *)&dst)[1] = _t.fC[2]; \
00194  ((char *)&dst)[2] = _t.fC[1]; ((char *)&dst)[3] = _t.fC[0]; \
00195 }
00196 #define WSWAPF(src, dst) { NetValue _t; _t.f = src; \
00197  ((short *)&dst)[0] = _t.fS[1]; ((short *)&dst)[1] = _t.fS[0]; \
00198 }
00199 #define BSWAPG(src, dst) { NetValue _t; _t.g = src; \
00200  ((char *)&dst)[0] = _t.gC[7]; ((char *)&dst)[1] = _t.gC[6]; \
00201  ((char *)&dst)[2] = _t.gC[5]; ((char *)&dst)[3] = _t.gC[4]; \
00202  ((char *)&dst)[4] = _t.gC[3]; ((char *)&dst)[5] = _t.gC[2]; \
00203  ((char *)&dst)[6] = _t.gC[1]; ((char *)&dst)[7] = _t.gC[0]; \
00204 }
00205 #define WSWAPG(src, dst) { NetValue _t; _t.g = src; \
00206  ((short *)&dst)[0] = _t.gS[3]; ((short *)&dst)[1] = _t.gS[2]; \
00207  ((short *)&dst)[2] = _t.gS[1]; ((short *)&dst)[3] = _t.gS[0]; \
00208 }
00209 #define LSWAPG(src, dst) { NetValue _t; _t.g = src; \
00210  ((long *)&dst)[0] = _t.gL[1]; ((long *)&dst)[1] = _t.gL[0]; \
00211 }
00212 
00213 // GL color in float
00214 class Color {
00215  public:
00216   float r, g, b, a;
00217 
00218   Color() {
00219   }
00220 
00221   Color( float r, float g, float b, float a=1.0f ) {
00222         this->set( r, g, b, a );
00223   }
00224 
00225   ~Color() {
00226   }
00227 
00228   inline void set( float r, float g, float b, float a=1.0f ) {
00229         this->r = r;
00230         this->g = g;
00231         this->b = b;
00232         this->a = a;
00233   }
00234 };
00235 
00240 typedef struct _ParticleStruct {
00241   GLfloat x, y, z, startZ;
00242   GLint height;
00243   int life;
00244   GLfloat moveDelta;
00245   int maxLife;
00246   int trail;
00247   float rotate;
00248   float zoom;
00249   bool tail;
00250   bool untilGround;
00251   Color tailColor;
00252 } ParticleStruct;
00253 
00254 #define SINGLE_TARGET 0
00255 #define GROUP_TARGET 1
00256 
00257 #define MAX_INVENTORY_SIZE 200
00258 #define MAX_CONTAINED_ITEMS 100
00259 
00260 #define MAX_LEVEL 100
00261 
00262 class Constants {
00263 public:
00264 
00265   // inventory locations
00266   static const int INVENTORY_HEAD = 1;
00267   static const int INVENTORY_NECK = 2;
00268   static const int INVENTORY_BACK = 4;
00269   static const int INVENTORY_CHEST = 8;
00270   static const int INVENTORY_LEFT_HAND = 16;
00271   static const int INVENTORY_RIGHT_HAND = 32;
00272   static const int INVENTORY_BELT = 64;
00273   static const int INVENTORY_LEGS = 128;
00274   static const int INVENTORY_FEET = 256;
00275   static const int INVENTORY_RING1 = 512;
00276   static const int INVENTORY_RING2 = 1024;
00277   static const int INVENTORY_RING3 = 2048;
00278   static const int INVENTORY_RING4 = 4096;
00279   static const int INVENTORY_WEAPON_RANGED = 8192;
00280   static const int INVENTORY_COUNT = 14;
00281   static char inventory_location[][80];
00282 
00283   // creature movement
00284   enum motion {
00285     MOTION_MOVE_TOWARDS=0,
00286     MOTION_MOVE_AWAY, // flee
00287     MOTION_LOITER,
00288     MOTION_STAND
00289   };
00290 
00291 // This stores the speed of the animation between each key frame for md2 models
00292 // A higher value means a *faster* animation and NOT a *smoother* animation.
00293 // The smoothing of the animation is only determined by fps. 
00294 // So this value should not be modified. Maybe later there will be an
00295 // animation_speed for each creature, to give the feeling some are faster than others ?
00296 #define ANIMATION_SPEED         5.0f  
00297 
00298 #define DEFAULT_SERVER_PORT 6543
00299 
00300 // The map's dimensions
00301 // Warning: if this ever changes, be sure to look at Map::createTripletKey().
00302 // it assumes that MAP_WIDTH >= MAP_HEIGHT and that MAP_WIDTH^3 < 2^32.
00303 #define MAP_WIDTH 600
00304 #define MAP_DEPTH 600
00305 
00306 // How big is the on-screen view. Should be calculated.
00307 #define MAP_VIEW_HEIGHT 16
00308 
00309   // How big is 1 map chunk
00310 #define MAP_UNIT 16
00311 #define MAP_UNIT_OFFSET 2
00312 #define MAP_WALL_HEIGHT 12
00313 
00314   // How far from the edge to start drawing in map
00315 #define MAP_OFFSET 80
00316   
00317 // define some active region labels
00318   enum {
00319         INV_PLAYER_0 = 0,
00320         INV_PLAYER_1,
00321         INV_PLAYER_2,
00322         INV_PLAYER_3,
00323         INV_MODE_INVENTORY,
00324         INV_MODE_PROPERTIES,
00325         INV_MODE_SPELLS,
00326         INV_MODE_LOG,
00327         MENU_0, 
00328         MENU_1,
00329         MENU_2,
00330         MENU_3,
00331         MENU_4,
00332         ESCAPE,
00333         SHOW_INVENTORY,
00334         SHOW_OPTIONS,
00335         SKILL_LIST,
00336         ITEM_LIST,
00337         DIAMOND_FORMATION,
00338         STAGGERED_FORMATION,
00339         SQUARE_FORMATION,
00340         ROW_FORMATION,
00341         SCOUT_FORMATION,
00342         CROSS_FORMATION,
00343         PLAYER_1,
00344         PLAYER_2,
00345         PLAYER_3,
00346         PLAYER_4,
00347         PLAYER_ONLY,
00348         MOVE_ITEM_TO_PLAYER_0,
00349         MOVE_ITEM_TO_PLAYER_1,
00350         MOVE_ITEM_TO_PLAYER_2,
00351         MOVE_ITEM_TO_PLAYER_3,
00352         DROP_ITEM,
00353         EQUIP_ITEM,
00354         FIX_ITEM,
00355         ENCHANT_ITEM,
00356         REMOVE_CURSE_ITEM,
00357         COMBINE_ITEM,
00358         IDENTIFY_ITEM
00359 
00360   };
00361 
00362   // Directions (a bitfield so they can be combined)
00363   static const Uint16 MOVE_UP = 1;
00364   static const Uint16 MOVE_DOWN = 2;
00365   static const Uint16 MOVE_LEFT = 4;
00366   static const Uint16 MOVE_RIGHT = 8;
00367 
00368   enum { NORTH=0, EAST, SOUTH, WEST };
00369 
00370   // messages
00371   enum {
00372         WELCOME=0,
00373         ITEM_OUT_OF_REACH,
00374         DOOR_BLOCKED,
00375         SINGLE_MODE,
00376         GROUP_MODE,
00377         TURN_MODE,
00378         REAL_TIME_MODE,
00379         CLOSE_LABEL,
00380         DROP_ITEM_LABEL,
00381         OPEN_CONTAINER_LABEL,
00382         EXPLAIN_DRAG_AND_DROP,
00383         PLAY_MISSION_LABEL,
00384         EXIT_MISSION_LABEL,
00385         TELEPORT_TO_BASE_LABEL,
00386         OK_LABEL, 
00387         CANCEL_LABEL, 
00388         YES_LABEL, 
00389         NO_LABEL,
00390         LEVEL_UP_ERROR,
00391         OUT_OF_POINTS_ERROR,
00392         NO_SKILL_ERROR,
00393         SCOURGE_DIALOG,
00394         USE_GATE_LABEL,
00395         DEAD_CHARACTER_ERROR,
00396         HP_LABEL,
00397         AC_LABEL,
00398         SPELL_FAILED_MESSAGE,
00399   ITEM_ACL_VIOLATION,
00400   JOIN_SERVER_ERROR,
00401   CLIENT_CANT_CONNECT_ERROR,
00402   DOOR_OPENED_CLOSE,
00403   DOOR_OPENED,
00404   DOOR_OPENED_FAR,
00405   DOOR_LOCKED,
00406   TELEPORTER_OFFLINE,
00407   INFO_GUI_TITLE,
00408   DELETE_OLD_SAVED_GAME,
00409   ITEM_LEVEL_VIOLATION,
00410         CHANGE_KEY,
00411         WAITING_FOR_KEY,
00412   CONVERSATION_GUI_TITLE,
00413 
00414         // last one
00415         MESSAGE_COUNT
00416   };
00417   static char *messages[][80];
00418   static int messageCount[];
00419 
00420   static const char *localhost;
00421   static const char *adminUserName;
00422 
00423   // skills
00424   enum {
00425     SPEED=0,
00426     COORDINATION,
00427     POWER,
00428     IQ,
00429     LEADERSHIP,
00430     LUCK,
00431     PIETY,
00432     LORE,
00433 
00434     SWORD_WEAPON,
00435     AXE_WEAPON,
00436     BOW_WEAPON,
00437     MACE_WEAPON,
00438     HAND_TO_HAND_COMBAT,
00439 
00440     SHIELD_DEFEND,
00441     ARMOR_DEFEND,
00442     WEAPON_DEFEND,
00443     HAND_DEFEND,
00444     
00445     NATURE_MAGIC,
00446     AWARENESS_MAGIC,
00447     LIFE_AND_DEATH_MAGIC,
00448     HISTORY_MAGIC,
00449     DECEIT_MAGIC,
00450     CONFRONTATION_MAGIC,        
00451     
00452     RESIST_NATURE_MAGIC,
00453     RESIST_AWARENESS_MAGIC,
00454     RESIST_LIFE_AND_DEATH_MAGIC,
00455     RESIST_HISTORY_MAGIC,
00456     RESIST_DECEIT_MAGIC,
00457     RESIST_CONFRONTATION_MAGIC, 
00458     
00459     OPEN_LOCK,
00460     FIND_TRAP,
00461     FIND_SECRET_DOOR,
00462     MOVE_UNDETECTED,
00463     
00464     ENCHANT_ITEM_SKILL,
00465     MEND_ITEM,
00466     IDENTIFY_ITEM_SKILL,
00467     IDENTIFY_CREATURE,
00468     
00469     SKILL_COUNT
00470   };
00471   static char *SKILL_NAMES[];
00472   static char *SKILL_DESCRIPTION[];
00473   static int getSkillByName(char *p);
00474   static int getRandomBasicSkill();
00475 
00476   // other things potions can act on:
00477   enum {
00478         HP=0,
00479         MP,
00480         AC,
00481         
00482         POTION_SKILL_COUNT
00483   };
00484   static const char *POTION_SKILL_NAMES[];
00485   // return -1 on failure, or (-2 - i) on success
00486   static int getPotionSkillByName(char *p);
00487 
00488   enum { 
00489         blessed=0, 
00490         empowered, 
00491         enraged, 
00492         ac_protected, 
00493         magic_protected, 
00494         drunk, 
00495         poisoned, 
00496         cursed, 
00497         possessed, 
00498         blinded, 
00499         paralysed, 
00500         invisible,
00501         overloaded,
00502         dead,
00503         leveled,
00504         
00505         // must be last
00506         STATE_MOD_COUNT
00507   };
00508   static const char *STATE_NAMES[];
00509   static vector<int> goodStateMod, badStateMod;
00510   static int getRandomGoodStateMod();
00511   static int getRandomBadStateMod();
00512   static bool isStateModTransitionWanted(int mod, bool setting);
00513   static void initConstants();
00514 
00515   enum {
00516     LESSER_MAGIC_ITEM=0,
00517     GREATER_MAGIC_ITEM,
00518     CHAMPION_MAGIC_ITEM,
00519     DIVINE_MAGIC_ITEM
00520   };
00521   static const char *MAGIC_ITEM_NAMES[];
00522   static const Color *MAGIC_ITEM_COLOR[];
00523 
00524   // special effect names
00525   enum {
00526     EFFECT_FLAMES=0,
00527     EFFECT_GLOW,
00528     EFFECT_TELEPORT,
00529     EFFECT_GREEN,
00530     EFFECT_EXPLOSION,
00531     EFFECT_SWIRL,
00532     EFFECT_CAST_SPELL,
00533     EFFECT_RING,
00534     EFFECT_RIPPLE,
00535     EFFECT_DUST,
00536     EFFECT_HAIL,
00537     EFFECT_TOWER,
00538     
00539     // must be last
00540     EFFECT_COUNT
00541   };    
00542   static const int DAMAGE_DURATION = 500;
00543 
00544   static const char *EFFECT_NAMES[];
00545   inline static int getEffectByName(char *s) { 
00546         for(int i = 0; i < EFFECT_COUNT; i++) 
00547           if(!strcmp(s, EFFECT_NAMES[i])) return i; 
00548         return EFFECT_FLAMES; 
00549   }
00550   
00551   // glColor for texts
00552   enum {
00553     RED_COLOR=0,
00554     BLUE_COLOR,
00555     YELLOW_COLOR,
00556     DEFAULT_COLOR // must be last for textColor[][]
00557   };  
00558   //static float textColor[][4]; 
00559   
00560   static bool multitexture;     
00561 
00562   enum {
00563     NO_SHADOWS=0,
00564     OBJECT_SHADOWS,
00565     ALL_SHADOWS
00566   };
00567 
00568   enum {
00569         ACTION_NO_ACTION=-1,
00570         ACTION_EAT_DRINK=0,
00571         ACTION_CAST_SPELL,
00572 
00573         // this must be the last one
00574         ACTION_COUNT
00575   };
00576 
00577   enum {
00578     GUI_LAYOUT_ORIGINAL=0,
00579     GUI_LAYOUT_BOTTOM,
00580     GUI_LAYOUT_SIDE,
00581     GUI_LAYOUT_INVENTORY,
00582     
00583     // must be last one
00584     GUI_LAYOUT_COUNT
00585   };
00586 
00587   // sound types
00588   enum {
00589     SOUND_TYPE_COMMAND=0,
00590     SOUND_TYPE_HIT,
00591     SOUND_TYPE_SELECT,
00592     SOUND_TYPE_ATTACK,
00593 
00594     // must be the last one
00595     SOUND_TYPE_COUNT
00596   };
00597 
00598   // the speed when hand fighting is used instead of a weapon
00599   static const int HAND_WEAPON_SPEED = 10;
00600 
00601   static const float MIN_DISTANCE = 1.0f;
00602 
00603   Constants();
00604   ~Constants();
00605 
00606   static char *getMessage(int index);
00607 
00608   // shortest distance between two rectangles
00609   static float distance(float x1, float y1, float w1, float h1, 
00610                                                 float x2, float y2, float w2, float h2);
00611 
00612   static void checkTexture(char *message, int w, int h);
00613 
00614   // read until EOL into line. Exclude EOL from LINE.
00615   // returns the next char after the EOL.
00616   static int readLine(char *line, FILE *fp);
00617 
00618   inline static float toRadians(float angle) {
00619         return 3.14159 * (angle / 180.0f);
00620   }
00621 
00622   inline static float toAngle(float rad) {
00623         return (180.0f * rad) / 3.14159;
00624   }
00625 };
00626 
00627 // This is our 3D point class.  This will be used to store the vertices of our model.
00628 class CVector3 
00629 {
00630 public:
00631     float x, y, z;
00632 };
00633 
00634 // This is our 2D point class.  This will be used to store the UV coordinates.
00635 class CVector2 
00636 {
00637 public:
00638     float x, y;
00639 };
00640 
00641 // Math functions
00642 extern CVector3 Vector(CVector3 vPoint1, CVector3 vPoint2);
00643 
00644 // This adds 2 vectors together and returns the result
00645 extern CVector3 AddVector(CVector3 vVector1, CVector3 vVector2);
00646 
00647 // This divides a vector by a single number (scalar) and returns the result
00648 extern CVector3 DivideVectorByScaler(CVector3 vVector1, float Scaler);
00649 
00650 // This returns the cross product between 2 vectors
00651 extern CVector3 Cross(CVector3 vVector1, CVector3 vVector2);
00652 extern CVector3 Normalize(CVector3 vNormal);
00653 
00654 // This file includes all of the model structures that are needed to load
00655 // in a .Md2 file.  When it comes to skeletal animation, we need to add quite
00656 // a bit more variables to these structures.  Not all of the data will be used
00657 // because Quake2 models don't have such a need.  I decided to keep the structures
00658 // the same as the rest of the model loaders on our site so that we could eventually
00659 // use a base class in the future for a library.
00660 //
00661 typedef unsigned char BYTE;
00662 #define MAX_TEXTURES 100                                                                // The maximum amount of textures to load
00663 
00664 // This is our face structure.  This is is used for indexing into the vertex
00665 // and texture coordinate arrays.  From this information we know which vertices
00666 // from our vertex array go to which face, along with the correct texture coordinates.
00667 struct tFace
00668 {
00669         int vertIndex[3];                       // indicies for the verts that make up this triangle
00670         int coordIndex[3];                      // indicies for the tex coords to texture this face
00671 };
00672 
00673 // This holds the information for a material.  It may be a texture map of a color.
00674 // Some of these are not used, but I left them because you will want to eventually
00675 // read in the UV tile ratio and the UV tile offset for some models.
00676 struct tMaterialInfo
00677 {
00678         char  strName[255];                     // The texture name
00679         char  strFile[255];                     // The texture file name (If this is set it's a texture map)
00680         BYTE  color[3];                         // The color of the object (R, G, B)
00681         int   texureId;                         // the texture ID
00682         float uTile;                            // u tiling of texture  (Currently not used)
00683         float vTile;                            // v tiling of texture  (Currently not used)
00684         float uOffset;                      // u offset of texture      (Currently not used)
00685         float vOffset;                          // v offset of texture  (Currently not used)
00686 } ;
00687 
00688 // This holds all the information for our model/scene.
00689 // You should eventually turn into a robust class that
00690 // has loading/drawing/querying functions like:
00691 // LoadModel(...); DrawObject(...); DrawModel(...); DestroyModel(...);
00692 struct t3DObject
00693 {
00694         int  numOfVerts;                        // The number of verts in the model
00695         int  numOfFaces;                        // The number of faces in the model
00696         int  numTexVertex;                      // The number of texture coordinates
00697         int  numGlCommands;         // The number of glCommands
00698         int  materialID;                        // The texture ID to use, which is the index into our texture array
00699         bool bHasTexture;                       // This is TRUE if there is a texture map for this object
00700         char strName[255];                      // The name of the object
00701         CVector3  *pVerts;                      // The object's vertices
00702         CVector3  *pNormals;            // The object's normals
00703   float *shadingColorDelta;     // 1 per normal
00704         CVector2  *pTexVerts;           // The texture's UV coordinates
00705         tFace *pFaces;                          // The faces information of the object  
00706 };
00707 
00708 
00709 // This holds our information for each animation of the Quake model.
00710 // A STL vector list of this structure is created in our t3DModel structure below.
00711 struct tAnimationInfo
00712 {
00713     char strName[255];          // This stores the name of the animation (Jump, Pain, etc..)
00714     int startFrame;             // This stores the first frame number for this animation
00715     int endFrame;               // This stores the last frame number for this animation
00716 };
00717 
00718 typedef float vect3d[3];
00719 
00720 // We added 4 new variables to our model structure.  These will help us handle
00721 // the current animation.  As of now, the current animation will continue to loop
00722 // from it's start from to it's end frame until we right click and change animations.
00723 struct t3DModel 
00724 {
00725     int numOfObjects;                   // The number of objects in the model
00726     int numOfMaterials;                 // The number of materials for the model
00727     int numOfAnimations;                // The number of animations in this model     
00728     float movex;                        // Needed to draw the model
00729     float movey;
00730     float movez;
00731     vector<tAnimationInfo> pAnimations; // The list of animations 
00732     vector<tMaterialInfo> pMaterials;   // The list of material information (Textures and colors)    
00733     vector<t3DObject> pObject;          // The object list for our model (frames)
00734     vect3d *vertices;                   // All vertices for every frame of the model
00735     int numVertices;                    // The number of vertices (constant for each frame)
00736     int *pGlCommands;                   // The glCommands used to draw the model faster
00737 };
00738 
00739 
00740 typedef unsigned char byte;
00741 
00742 extern void ComputeNormals(t3DModel *pModel);
00743 extern void CreateTexture(GLuint textureArray[],char *strFileName,int textureID);
00744 extern void swap(unsigned char & a, unsigned char & b);
00745 
00746 #endif

Generated on Thu Jun 16 21:50:42 2005 for scourge by  doxygen 1.4.0