/* ========================================================================== * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2006.12.04 * ³» ¿ë : ³×ºñ¸Þ½Ã * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once //#include "Shader.h" class cRay; class cBox; class cNaviMeshNode; class cNaviMeshBranchNode; class cNaviMeshLeafNode; /// ³×ºñ¸Þ½Ã »ó¼ö const unsigned int NAVIMESH_DEFAULT_RESOLUTION = 512; const unsigned int NAVIMESH_BUFF_CELL_COUNT = 128; const unsigned int NAVIMESH_BUFF_LINE_COUNT = NAVIMESH_BUFF_CELL_COUNT + 1; const unsigned int NAVIMESH_BUFF_VERT_COUNT = NAVIMESH_BUFF_LINE_COUNT * NAVIMESH_BUFF_LINE_COUNT; const unsigned int NAVIMESH_LEAF_CELL_COUNT = 8; const unsigned int NAVIMESH_LEAF_LINE_COUNT = NAVIMESH_LEAF_CELL_COUNT + 1; const unsigned int NAVIMESH_LEAF_LINE_COUNT_X2 = NAVIMESH_LEAF_LINE_COUNT * 2; const unsigned int NAVIMESH_LEAF_VERT_COUNT = NAVIMESH_LEAF_LINE_COUNT * NAVIMESH_LEAF_LINE_COUNT; /// ³×ºñ¸Þ½Ã ÆÄÀÏ Çì´õ #pragma pack( push, 1 ) class cNaviMeshFileHeader { public: /// ½Äº° ÄÚµå char mCode[13]; /// ¹öÀü unsigned int mVersion; /// ±×¸®µå Å©±â (¼¿ ¼ö) unsigned int mCellCount; /// Á¤Á¡´ç ¹ÌÅÍ ¼ö float mMetersPerVertex; /// ¹ÌÅÍ´ç ´ÜÀ§ ¼ö ( 100 ) unsigned int mUnitsPerMeter; }; #pragma pack( pop ) /// ³×ºñ¸Þ½Ã class cNaviMesh { static cNaviMesh* mSingleton; friend class cNaviMeshLeafNode; public: static const unsigned int MAX_NODES = 21845; public: cNaviMesh(); ~cNaviMesh(); /// Áö¿ò void Clear(); /// ·Îµù bool LoadHeader( unsigned int& count, const cString& pathName ); int LoadNodes( unsigned int count ); /// ÇÈÅ· bool Pick( NiPoint3* pos, int mouseX, int mouseY ); bool Pick( NiPoint3* pos, const cRay& ray ); bool Pick( NiPoint3* pos, float* dist, const cRay& ray, float maxDistance ); /// ³ôÀ̰ª bool CalcHeight( float* height, float x, float y ) const; const float* GetHeights() const; /// ±×¸®µå »çÀÌÁ ¸®ÅÏ unsigned int GetCellCount() const; /// Á¤Á¡´ç ¹ÌÅͼö¸¦ ¸®ÅÏ float GetMetersPerVertex() const; /// ¹ÌÅÍ´ç ´ÜÀ§¼ö¸¦ ¸®ÅÏ unsigned int GetUnitsPerMeter() const; /// Á¤Á¡ »çÀÌÀÇ ´ÜÀ§¸¦ ¸®ÅÏ float GetUnitsPerVertex() const; /// ¸®ÇÁ ³ëµå »çÀÌÀÇ ´ÜÀ§¸¦ ¸®ÅÏ float GetUnitsPerLeafNode() const; /// ÇØ´ç À§Ä¡ÀÇ ¸®ÇÁ ³ëµå¸¦ ¸®ÅÏ cNaviMeshLeafNode* GetLeafNode( float x, float y ) const; /// ³×ºñ¸Þ½Ã Àüü¸¦ °¨½Î´Â °æ°è »óÀÚ¸¦ ¸®ÅÏ const cBox& GetBoundBox() const; /// ÇÑ º¯ÀÇ ±æÀÌ float GetSegmentLength() const; protected: /// ±×¸®µå Å©±â¸¦ °Ë»ç bool CheckCellCount( unsigned int cellCount ); /// ÇØ´ç À§Ä¡¿¡ ¸®ÇÁ ³ëµå¸¦ ¼³Á¤ void SetLeafNode( unsigned int xi, unsigned int yi, cNaviMeshLeafNode* node ); /// ³ôÀ̰ª void SetHeight( unsigned int xi, unsigned int yi, float height ); float GetHeightFast( unsigned int xi, unsigned int yi ) const; /// ÅØ½ºÃ³ ÁÂÇ¥ ¹è¿­ NiPoint2* GetTexCoords() const; /// °øÅë ½ºÆ®¸³ ¹è¿­ unsigned short* GetStripLength(); unsigned short* GetStripIndex(); public: /// ´ÜÀÏü¸¦ ¸®ÅÏ static cNaviMesh* GetSingleton(); private: /// ±×¸®µå Å©±â unsigned int mCellCount; unsigned int mLineCount; /// ´ÜÀ§ float mMetersPerVertex; unsigned int mUnitsPerMeter; float mUnitsPerVertex; float mUnitsPerLeafNode; /// ÇÑ º¯ÀÇ ±æÀÌ float mSegmentLength; /// ·çÆ® ³ëµå cNaviMeshBranchNode* mRootNode; /// ¸®ÇÁ ³ëµå ¹è¿­ typedef tPointerArray cLeafNodeArray; cLeafNodeArray mNodeArray; /// ³ôÀÌ ¹è¿­ float* mHeights; /// ·Îµù cFileLoader mLoader; cNaviMeshNode** mLoadArray; unsigned int mLoadCount; unsigned int mLoadIndex; }; inline void cNaviMesh::SetHeight( unsigned int xi, unsigned int yi, float height ) { mHeights[yi * mLineCount + xi] = height; } inline float cNaviMesh::GetHeightFast( unsigned int xi, unsigned int yi ) const { return mHeights[yi * mLineCount + xi]; } inline const float* cNaviMesh::GetHeights() const { return mHeights; } inline unsigned int cNaviMesh::GetCellCount() const { return mCellCount; } inline float cNaviMesh::GetMetersPerVertex() const { return mMetersPerVertex; } inline unsigned int cNaviMesh::GetUnitsPerMeter() const { return mUnitsPerMeter; } inline float cNaviMesh::GetSegmentLength() const { return mSegmentLength; } inline float cNaviMesh::GetUnitsPerVertex() const { return mUnitsPerVertex; } inline float cNaviMesh::GetUnitsPerLeafNode() const { return mUnitsPerLeafNode; } inline cNaviMesh* cNaviMesh::GetSingleton() { return mSingleton; } #define NAVIMESH cNaviMesh::GetSingleton()