CCNavMeshDebugDraw.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. Copyright (c) 2015-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCNAV_MESH_DEBUG_DRAW_H__
  22. #define __CCNAV_MESH_DEBUG_DRAW_H__
  23. #include "base/ccConfig.h"
  24. #if CC_USE_NAVMESH
  25. #include "renderer/CCGLProgram.h"
  26. #include "renderer/CCCustomCommand.h"
  27. #include "renderer/CCRenderState.h"
  28. #include "math/Vec3.h"
  29. #include "recast/DebugUtils/DebugDraw.h"
  30. #include <string>
  31. #include <vector>
  32. NS_CC_BEGIN
  33. /**
  34. * @addtogroup 3d
  35. * @{
  36. */
  37. class Renderer;
  38. class NavMeshDebugDraw : public duDebugDraw
  39. {
  40. public:
  41. NavMeshDebugDraw();
  42. virtual ~NavMeshDebugDraw();
  43. virtual void depthMask(bool state) override;
  44. virtual void texture(bool /*state*/) override {};
  45. virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) override;
  46. virtual void vertex(const float* pos, unsigned int color) override;
  47. virtual void vertex(const float x, const float y, const float z, unsigned int color) override;
  48. virtual void vertex(const float* pos, unsigned int color, const float* uv) override;
  49. virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) override;
  50. virtual void end() override;
  51. void draw(Renderer* renderer);
  52. void clear();
  53. private:
  54. GLenum getPrimitiveType(duDebugDrawPrimitives prim);
  55. void drawImplement(const cocos2d::Mat4& transform, uint32_t flags);
  56. static Vec4 getColor(unsigned int col);
  57. private:
  58. struct V3F_C4F
  59. {
  60. Vec3 position;
  61. Vec4 color;
  62. };
  63. struct Primitive
  64. {
  65. GLenum type;
  66. bool depthMask;
  67. unsigned short start;
  68. unsigned short end;
  69. float size;
  70. };
  71. std::vector<V3F_C4F> _vertices;
  72. std::vector<Primitive*> _primitiveList;
  73. Primitive *_currentPrimitive;
  74. GLProgram *_program;
  75. CustomCommand _customCmd;
  76. RenderState::StateBlock* _stateBlock;
  77. GLenum _primitiveType;
  78. bool _currentDepthMask;
  79. GLuint _vbo;
  80. bool _dirtyBuffer;
  81. };
  82. /** @} */
  83. NS_CC_END
  84. #endif //CC_USE_NAVMESH
  85. #endif // __CCNAV_MESH_DEBUG_DRAW_H__