Planeshift
|
00001 // 00002 // Copyright (c) 2009-2010 Mikko Mononen [email protected] 00003 // 00004 // This software is provided 'as-is', without any express or implied 00005 // warranty. In no event will the authors be held liable for any damages 00006 // arising from the use of this software. 00007 // Permission is granted to anyone to use this software for any purpose, 00008 // including commercial applications, and to alter it and redistribute it 00009 // freely, subject to the following restrictions: 00010 // 1. The origin of this software must not be misrepresented; you must not 00011 // claim that you wrote the original software. If you use this software 00012 // in a product, an acknowledgment in the product documentation would be 00013 // appreciated but is not required. 00014 // 2. Altered source versions must be plainly marked as such, and must not be 00015 // misrepresented as being the original software. 00016 // 3. This notice may not be removed or altered from any source distribution. 00017 // 00018 00019 #ifndef INPUTGEOM_H 00020 #define INPUTGEOM_H 00021 00022 #include "ChunkyTriMesh.h" 00023 #include "MeshLoaderObj.h" 00024 00025 static const int MAX_CONVEXVOL_PTS = 12; 00026 struct ConvexVolume 00027 { 00028 float verts[MAX_CONVEXVOL_PTS*3]; 00029 float hmin, hmax; 00030 int nverts; 00031 int area; 00032 }; 00033 00034 class InputGeom 00035 { 00036 rcChunkyTriMesh* m_chunkyMesh; 00037 rcMeshLoaderObj* m_mesh; 00038 float m_meshBMin[3], m_meshBMax[3]; 00039 00042 static const int MAX_OFFMESH_CONNECTIONS = 256; 00043 float m_offMeshConVerts[MAX_OFFMESH_CONNECTIONS*3*2]; 00044 float m_offMeshConRads[MAX_OFFMESH_CONNECTIONS]; 00045 unsigned char m_offMeshConDirs[MAX_OFFMESH_CONNECTIONS]; 00046 unsigned char m_offMeshConAreas[MAX_OFFMESH_CONNECTIONS]; 00047 unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS]; 00048 unsigned int m_offMeshConId[MAX_OFFMESH_CONNECTIONS]; 00049 int m_offMeshConCount; 00051 00054 static const int MAX_VOLUMES = 256; 00055 ConvexVolume m_volumes[MAX_VOLUMES]; 00056 int m_volumeCount; 00058 00059 public: 00060 InputGeom(); 00061 ~InputGeom(); 00062 00063 bool loadMesh(class rcContext* ctx, const char* filepath); 00064 00065 bool load(class rcContext* ctx, const char* filepath); 00066 bool save(const char* filepath); 00067 00069 inline const rcMeshLoaderObj* getMesh() const { return m_mesh; } 00070 inline const float* getMeshBoundsMin() const { return m_meshBMin; } 00071 inline const float* getMeshBoundsMax() const { return m_meshBMax; } 00072 inline const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; } 00073 bool raycastMesh(float* src, float* dst, float& tmin); 00074 00077 int getOffMeshConnectionCount() const { return m_offMeshConCount; } 00078 const float* getOffMeshConnectionVerts() const { return m_offMeshConVerts; } 00079 const float* getOffMeshConnectionRads() const { return m_offMeshConRads; } 00080 const unsigned char* getOffMeshConnectionDirs() const { return m_offMeshConDirs; } 00081 const unsigned char* getOffMeshConnectionAreas() const { return m_offMeshConAreas; } 00082 const unsigned short* getOffMeshConnectionFlags() const { return m_offMeshConFlags; } 00083 const unsigned int* getOffMeshConnectionId() const { return m_offMeshConId; } 00084 void addOffMeshConnection(const float* spos, const float* epos, const float rad, 00085 unsigned char bidir, unsigned char area, unsigned short flags); 00086 void deleteOffMeshConnection(int i); 00087 void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false); 00089 00092 int getConvexVolumeCount() const { return m_volumeCount; } 00093 const ConvexVolume* getConvexVolumes() const { return m_volumes; } 00094 void addConvexVolume(const float* verts, const int nverts, 00095 const float minh, const float maxh, unsigned char area); 00096 void deleteConvexVolume(int i); 00097 void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false); 00099 }; 00100 00101 #endif // INPUTGEOM_H