Changeset 8343 in orxonox.OLD for branches/bsp_model/src/lib/graphics/importer
- Timestamp:
- Jun 13, 2006, 4:04:33 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/Makefile.am
r8186 r8343 21 21 bsp_file.cc \ 22 22 bsp_tree_node.cc \ 23 bsp_tree_leaf.cc 23 bsp_tree_leaf.cc \ 24 \ 25 md3/md3_model.cc \ 26 md3/md3_animation.cc \ 27 md3/md3_bone_frame.cc \ 28 md3/md3_mesh.cc 24 29 25 30 … … 49 54 bsp_file.h \ 50 55 bsp_tree_node.h \ 51 bsp_tree_leaf.h 56 bsp_tree_leaf.h \ 57 \ 58 md3/md3_model.h \ 59 md3/md3_animation.h \ 60 md3/md3_bone_frame.h \ 61 md3/md3_mesh.h 62 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r8341 r8343 885 885 886 886 887 if(/*!worldEntity->isA(CL_PLAYABLE)*/ false) { 888 889 890 887 888 889 bool collision = false; 890 Vector position1 = position + Vector(0.0,0.1,0.0); 891 Vector position2 = position + Vector(0.0,0.2,0.0); 892 Vector dest1 = position1 + forwardDir; 893 Vector dest2 = position2 + forwardDir; 894 dest = position - Vector(0.0, 40.0,0.0); 895 Vector out1; 896 Vector out2; 897 898 899 float height = 40; 900 this->outputAllSolid = false; 901 902 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 903 904 PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction); 905 // position1.debug(); 906 907 if( this->outputFraction == 1.0f) 908 { 909 if(this->outputAllSolid) 910 { 911 this->collPlane = new plane; 912 this->collPlane->x = 1.0f; 913 this->collPlane->y = 0.0f; 914 this->collPlane->z = 0.0f; 915 collision = true; 916 } 917 else 918 collision = false; 919 920 921 out = dest; 891 922 } 892 923 else { 893 924 894 bool collision = false; 895 Vector position1 = position + Vector(0.0,0.1,0.0); 896 Vector position2 = position + Vector(0.0,0.2,0.0); 897 Vector dest1 = position1 + forwardDir; 898 Vector dest2 = position2 + forwardDir; 899 dest = position - Vector(0.0, 40.0,0.0); 900 Vector out1; 901 Vector out2; 902 903 904 float height = 40; 905 this->outputAllSolid = false; 906 907 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 908 909 if( this->outputFraction == 1.0f) 910 { 911 if(this->outputAllSolid) 912 { 913 this->collPlane = new plane; 914 this->collPlane->x = 1.0f; 915 this->collPlane->y = 0.0f; 916 this->collPlane->z = 0.0f; 917 collision = true; 918 } 919 else 920 collision = false; 921 922 923 out = dest; 924 } 925 else { 926 927 collision = true; 928 out.x = position.x + (dest.x -position.x) * this->outputFraction; 929 out.y = position.y + (dest.y -position.y) * this->outputFraction; 930 out.z = position.z + (dest.z -position.z) * this->outputFraction; 931 932 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 933 this->out = out; 934 //this->out1 = out1; 935 //this->out2 = out2; 936 //this->drawDebugCube(&out1); 937 //this->drawDebugCube(&out2); 938 //this->drawDebugCube(&out3); 939 } 940 // Return the normal here: Normal's stored in this->collPlane; 941 if(collision ) { 942 // PRINTF(0)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 943 worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out); 944 } 925 collision = true; 926 out.x = position.x + (dest.x -position.x) * this->outputFraction; 927 out.y = position.y + (dest.y -position.y) * this->outputFraction; 928 out.z = position.z + (dest.z -position.z) * this->outputFraction; 929 930 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 931 this->out = out; 932 } 933 934 // Return the normal here: Normal's stored in this->collPlane; 935 if( collision) { 936 PRINTF(0)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 937 worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out); 945 938 } 946 939 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_bone_frame.cc
r8342 r8343 14 14 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER 16 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_mesh.cc
r8342 r8343 14 14 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER 16 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_mesh.h
r8342 r8343 12 12 { 13 13 public: 14 14 MD3Mesh() { /* loadMesh(this, din) */ } 15 virtual ~MD3Mesh(); 15 16 16 17 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h
r8342 r8343 1 1 /*! 2 * @file md2Model.h 3 * Definition of an MD2 Model, a model format invented by ID Software. 2 * @file md3_model.h 3 * 4 * Code heavely inspired by: JAVA MD3 Model Viewer - A Java based Quake 3 model viewer 5 * Copyright (C) 1999 Erwin 'KLR8' Vervaet 6 */ 4 7 5 We are deeply thankfull for all the wunderfull things id software made for us gamers! 8 #ifndef _MD3_MODEL_H 9 #define _MD3_MODEL_H 6 10 7 The md2 file format is structured in a very simple way: it contains animations which are made out of 8 frames (so called keyframes). Each frame is a complete draweable model in a specific position. 9 A frame is a collection of vertex and its compagnions (normals, texture coordinates). 11 #include <string> 10 12 11 A typical model has about 200 frames, the maximum frame count is fixed by MD2_MAX_FRAMES to currently12 512 frames. The maximal vetices count is set to 2048 verteces, not enough?13 You just have to change the MD2_MAX_* values if it doesn't fit your purposes...14 13 15 Surface Culling is fully implemented in md2 models: quake2 uses front face culling. 16 */ 14 class MD3BoneFrame; 15 class MD3Mesh; 17 16 18 #ifndef _MD2MODEL_H19 #define _MD2MODEL_H20 17 21 #include "base_object.h" 18 class MD3Model 19 { 22 20 23 #include "model.h" 24 #include "material.h" 21 public: 22 MD3Model(); 23 ~MD3Model(); 25 24 26 //! These are the needed defines for the max values when loading .MD2 files27 #define MD2_IDENT (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md2 identifier tag in the bin file28 #define MD2_VERSION 8 //!< the md2 version in the header29 #define MD2_MAX_TRIANGLES 4096 //!< maximal triangles count30 #define MD2_MAX_VERTICES 2048 //!< maximal vertices count31 #define MD2_MAX_TEXCOORDS 2048 //!< maximal tex coordinates32 #define MD2_MAX_FRAMES 512 //!< maximal frames33 #define MD2_MAX_SKINS 32 //!< maximal skins34 #define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) //!< maximal framesize35 25 36 #define NUM_VERTEX_NORMALS 162 //!< number of vertex normals37 #define SHADEDOT_QUANT 16 //!< shade dot quantity - no idea what it is38 26 39 //! This stores the speed of the animation between each key frame - currently conflicting with the animation framework 40 #define kAnimationSpeed 12.0f //!< animation speed 27 private: 28 std::string filename; //!< the name of the file as recorded in the .md3 file 29 std::string loadFilename; //!< filename of the actual file from which data was loaded 41 30 42 //! This holds the header information that is read in at the beginning of the file: id software definition 43 struct MD2Header 44 { 45 int ident; //!< This is used to identify the file 46 int version; //!< The version number of the file (Must be 8) 31 int boneFrameNum; //!< number of anumation key fames in the models 32 int tagNum; //!< number of tags 33 int meshNum; //!< number of meshes 47 34 48 int skinWidth; //!< The skin width in pixels49 int skinHeight; //!< The skin height in pixels50 int frameSize; //!< The size in bytes the frames are35 int maxTextureNum; //!< maximum number of unique used in an md3 file 36 int boneFrameStart; //!< starting position of bone frame data structures 37 int tagStart; //!< starting position of tag-structures 51 38 52 int numSkins; //!< The number of skins associated with the model 53 int numVertices; //!< The number of vertices (constant for each frame) 54 int numTexCoords; //!< The number of texture coordinates 55 int numTriangles; //!< The number of faces (polygons) 56 int numGlCommands; //!< The number of gl commands 57 int numFrames; //!< The number of animation frames 39 int meshStart; //!< starting position of mesh structures 58 40 59 int offsetSkins; //!< The offset in the file for the skin data 60 int offsetTexCoords; //!< The offset in the file for the texture data 61 int offsetTriangles; //!< The offset in the file for the face data 62 int offsetFrames; //!< The offset in the file for the frames data 63 int offsetGlCommands; //!< The offset in the file for the gl commands data 64 int offsetEnd; //!< The end of the file offset 41 int fileSize; //!< file size 42 43 44 MD3BoneFrame* boneFrames; //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame 45 MD3Mesh* meshes; //!< array of meshes in the model. each containing the mesh for each of the animation 46 47 int parentTagIndex; //!< tag index 48 MD3Model* parent; //!< reference to the MD3Model 65 49 }; 66 50 67 51 68 //! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading 69 typedef struct 70 { 71 unsigned char v[3]; //!< the vector of the vertex 72 unsigned char lightNormalIndex; //!< the index of the light normal 73 } sVertex; 74 75 76 //! compressed texture offset data: coords scaled by the texture size. Only for loading 77 typedef struct 78 { 79 short s; //!< the s,t coordinates of a texture 80 short t; //!< the s,t coordinates of a texture 81 } sTexCoor; 82 83 84 //! holds tha informations about a md2 frame 85 typedef struct 86 { 87 sVec3D scale; //!< scales values of the model 88 sVec3D translate; //!< translates the model 89 char name[16]; //!< frame name: something like "run32" 90 sVertex pVertices[1]; //!< first vertex of thes frame 91 } sFrame; 92 93 94 //! holds the information about a triangle 95 typedef struct 96 { 97 unsigned short indexToVertices[3]; //!< index to the verteces of the triangle 98 unsigned short indexToTexCoor[3]; //!< index to the texture coordinates 99 } sTriangle; 100 101 102 103 //! the command list of the md2 model, very md2 specific 104 typedef struct 105 { 106 float s; //!< texture coordinate 1 107 float t; //!< texture coordinate 2 108 int vertexIndex; //!< index of the vertex in the vertex list 109 } glCommandVertex; 110 111 112 //! a md2 animation definition 113 typedef struct 114 { 115 int firstFrame; //!< first frame of the animation 116 int lastFrame; //!< last frame of the animation 117 int fps; //!< speed: number of frames per second 118 int bStoppable; //!< 1 if the animation is stoppable 0 else 119 } sAnim; 120 121 122 //! animation state definition 123 typedef struct 124 { 125 int startFrame; //!< the start frame of an animation 126 int endFrame; //!< last frame of the animation 127 int fps; //!< fps of the animaion (speed) 128 129 float localTime; //!< the local time 130 float lastTime; //!< last time stamp 131 float interpolationState; //!< the state of the animation [0..1] 132 133 int type; //!< animation type 134 135 int currentFrame; //!< the current frame 136 int nextFrame; //!< the next frame in the list 137 int numPlays; //!< the number of times, this has been played in series 138 139 int animPlaybackMode; //!< the playback mode 140 } sAnimState; 141 142 143 //! animation names enumeration 144 typedef enum animType 145 { 146 STAND, //0 147 RUN, //1 148 ATTACK, //2 149 PAIN_A, //3 150 PAIN_B, //4 151 PAIN_C, //5 152 JUMP, //6 153 FLIP, //7 154 SALUTE, //8 155 FALLBACK, //9 156 WAVE, //10 157 POINT, //11 158 CROUCH_STAND, 159 CROUCH_WALK, 160 CROUCH_ATTACK, 161 CROUCH_PAIN, 162 CROUCH_DEATH, 163 DEATH_FALLBACK, 164 DEATH_FALLFORWARD, 165 DEATH_FALLBACKSLOW, 166 BOOM, 167 168 MAX_ANIMATIONS 169 }; 170 171 172 typedef enum animPlayback 173 { 174 MD2_ANIM_LOOP = 0, 175 MD2_ANIM_ONCE, 176 177 MD2_ANIM_NUM 178 }; 179 180 181 182 /* forward definitions */ 183 class Material; 184 185 186 187 //! class to store the md2 data in 188 class MD2Data : public BaseObject 189 { 190 public: 191 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 192 virtual ~MD2Data(); 193 194 private: 195 bool loadModel(const std::string& fileName); 196 bool loadSkin(const std::string& fileName = ""); 197 198 public: 199 int numFrames; //!< number of frames 200 int numVertices; //!< number of vertices 201 int numTriangles; //!< number of triangles 202 int numTexCoor; //!< number of texture coordinates 203 int numGLCommands; //!< number of gl commands in the glList (tells how to draw) 204 std::string fileName; //!< file name of the model File 205 std::string skinFileName; //!< file name of the skin file 206 MD2Header* header; //!< the header file 207 208 sVec3D* pVertices; //!< pointer to the vertices data block 209 sTriangle* pTriangles; //!< pointer to the triangles data 210 sTexCoor* pTexCoor; //!< pointer to the texture coordinate data 211 int* pGLCommands; //!< pointer to the gllist data block 212 int* pLightNormals; //!< pointer to the light normals 213 214 Material material; //!< pointer to the material 215 float scaleFactor; //!< the scale factor of the model, (global) 216 }; 217 218 219 220 221 //! This is a MD2 Model class 222 class MD2Model : public Model { 223 224 public: 225 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 226 virtual ~MD2Model(); 227 228 virtual void draw() const; 229 void renderFrameTriangles() const; 230 231 232 void setAnim(int type, int animPlayback = MD2_ANIM_LOOP); 233 /** returns the current animation @returns animation type */ 234 inline int MD2Model::getAnim() { return this->animationState.type; } 235 /** scales the current model @param scaleFactor: the factor [0..1] to use for scaling */ 236 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 237 238 virtual void tick(float dtS); 239 void debug(); 240 241 242 private: 243 void animate(float time); 244 void processLighting(); 245 void interpolate(/*sVec3D* verticesList*/); 246 void renderFrame() const ; 247 248 249 public: 250 /* these variables are static, because they are all the same for every model */ 251 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals 252 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products 253 static sAnim animationList[21]; //!< the anomation list 254 //! again one of these strange id software parts 255 float* shadeDots; 256 257 MD2Data* data; //!< the md2 data pointer 258 259 private: 260 float scaleFactor; //!< the scale factor (individual) 261 sAnimState animationState; //!< animation state of the model 262 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert 263 }; 264 265 266 267 268 269 #endif /* _MD2MODEL_H */ 52 #endif /* _MD3_MODEL_H */
Note: See TracChangeset
for help on using the changeset viewer.