您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

79 行
2.3 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. //
  12. // The EasyMesh class
  13. // ------------------
  14. //
  15. #if !defined __CSGBSP_CSGBSP_H__
  16. #define __CSGBSP_CSGBSP_H__
  17. namespace lol
  18. {
  19. #define LEAF_ABOVE 2
  20. #define LEAF_FRONT 1
  21. #define LEAF_BACK 0
  22. #define LEAF_CURRENT -1
  23. //Naïve bsp for the poor people
  24. class CsgBspLeaf
  25. {
  26. friend class CsgBsp;
  27. public:
  28. CsgBspLeaf(vec3 origin, vec3 normal, int above_idx)
  29. {
  30. m_origin = origin;
  31. m_normal = normal;
  32. m_leaves[LEAF_ABOVE] = above_idx;
  33. m_leaves[LEAF_FRONT] = -1;
  34. m_leaves[LEAF_BACK] = -1;
  35. }
  36. private:
  37. vec3 m_origin;
  38. vec3 m_normal;
  39. Array< int, vec3, vec3, vec3 > m_tri_list;
  40. ivec3 m_leaves;
  41. };
  42. //Naïve bsp for the poor people
  43. class CsgBsp
  44. {
  45. public:
  46. void AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2);
  47. //return 0 when no split has been done.
  48. //return 1 when split has been done.
  49. //return -1 when error.
  50. int TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2,
  51. //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha.
  52. //<Point_Loc, Src_V0, Src_V1, Alpha> as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; }
  53. Array< vec3, int, int, float > &vert_list,
  54. //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point.
  55. //<{IN|OUT}side_status, v0, v1, v2>
  56. Array< int, int, int, int > &tri_list);
  57. private:
  58. int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx);
  59. int TestPoint(int leaf_idx, vec3 point);
  60. Array<CsgBspLeaf> m_tree;
  61. };
  62. } /* namespace lol */
  63. #endif /* __CSGBSP_CSGBSP_H__ */