• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/cannonball/header/Level.h

Go to the documentation of this file.
00001 #pragma once
00002 enum LevelObjectBodyGeom
00003 {
00004         bodyDummy,
00005         bodySphere,
00006         bodyBox,
00007         bodyMesh
00008 };
00009 
00010 enum LevelObjectBodyType
00011 {
00012         typeStatic,
00013         typeDynamic,
00014         typeExtern,
00015 };
00016 
00017 enum CannonballType : int
00018 {
00019         cannonball,
00020         cannonballFast,
00021         cannonballStrong,
00022         cannonballBomb
00023 };
00024 
00025 struct LevelObjectBody
00026 {
00027         LevelObjectBodyGeom geom;
00028         LevelObjectBodyType type;
00029         float3 position;
00030         float3 rotation;
00031         float width;
00032         float height;
00033         float depth;
00034         float density;
00035         int group;
00036         int material;
00037         int textureID;
00038         int geometryID;
00039 };
00040 
00041 struct LevelItem
00042 {
00043         float3 position;
00044         int item;
00045         int value;
00046         bool operator == (const LevelItem& other) { return this == &other; }
00047 };
00048 
00050 class Level
00051 {
00052 public:
00054         Level(IPhysic& physic, IRender& render);
00056         ~Level();
00057 
00060         bool load(const wchar* filename, const wchar* textureDir);
00061 
00062         bool loadGeometry(const wchar* filename, const char* name, pIGeometry& geometry);
00063         bool loadGeometry(const wchar* filename, const char* name, pIGeometry& geometry, MeshData& meshData);
00064 
00066         void unload(void);
00067 
00068         inline float3 getStart(void) { return start; }
00069 
00070         inline bool intersectsEnd(float3 pos, float radius = 1.f) {
00071                 return (end-pos).length2() < radius*radius;
00072         }
00073 
00074         inline int intersectsItem(float3 pos, float radius = 1.f) {
00075                 for(uint i=0; i<items.size(); i++){
00076                         const float r = radius+items[i].value;
00077                         if((items[i].position-pos).length2() < r*r)
00078                                 return i;
00079                 }
00080                 return -1;
00081         }
00082 
00083         inline LevelItem& getItem(int index) {
00084                 return items.getRef(uint(index));
00085         }
00086 
00087         inline void removeItem(int index) {
00088                 items.removeIndex(uint(index));
00089                 itemInstances.getRef(uint(index))->visible = false;
00090                 itemInstances.removeIndex(uint(index));
00091         }
00092 
00093         inline void setItemGeometry(CannonballType type, pIGeometry geometry) {
00094                 itemGeometries[type] = geometry;
00095         }
00096 
00097 protected:
00098         bool loadMeshData(FILE* file, MeshData& meshData, const char* name = 0);
00099         bool loadUnknown(const wchar* filename, int& width, int& height, Pixel** outData);
00100         bool loadTextureData(const wchar* colorFilename, const wchar* normalFilename, const wchar* heightFilename, TextureData& out);
00101         bool loadBMP(const wchar* filename, int& width, int& height, Pixel** outData);
00102         bool loadTGA(const wchar* filename, int& width, int& height, Pixel** outData);
00103 
00104 private:
00105         IPhysic& physic;
00106         IRender& render;
00107         int numGeometries;
00108         int numTextures;
00109         int numBodies;
00110         int numLights;
00111         pIGeometry* geometries;
00112         pITexture* textures;
00113         pIBody* bodies;
00114         float3 start;
00115         float3 end;
00116         Array<LevelItem> items;
00117         Array<pIBody> itemBodies;
00118         Array<pInstance> itemInstances;
00119         pIGeometry itemGeometries[4];
00120 };

Generated on Fri Jun 18 2010 17:48:39 for Cannonball by  doxygen 1.7.0