You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 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. #pragma once
  12. //
  13. // The EasyMesh class
  14. // ------------------
  15. //
  16. namespace lol
  17. {
  18. #define LEAF_ABOVE 2
  19. #define LEAF_FRONT 1
  20. #define LEAF_BACK 0
  21. #define LEAF_CURRENT -1
  22. //Naïve bsp for the poor people
  23. class CsgBspLeaf
  24. {
  25. friend class CsgBsp;
  26. public:
  27. CsgBspLeaf(vec3 origin, vec3 normal, int above_idx)
  28. {
  29. m_origin = origin;
  30. m_normal = normal;
  31. m_leaves[LEAF_ABOVE] = above_idx;
  32. m_leaves[LEAF_FRONT] = -1;
  33. m_leaves[LEAF_BACK] = -1;
  34. }
  35. private:
  36. vec3 m_origin;
  37. vec3 m_normal;
  38. array< int, vec3, vec3, vec3 > m_tri_list;
  39. ivec3 m_leaves;
  40. };
  41. //Naïve bsp for the poor people
  42. class CsgBsp
  43. {
  44. public:
  45. void AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2);
  46. //return 0 when no split has been done.
  47. //return 1 when split has been done.
  48. //return -1 when error.
  49. int TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2,
  50. //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha.
  51. //<Point_Loc, Src_V0, Src_V1, Alpha> as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; }
  52. array< vec3, int, int, float > &vert_list,
  53. //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point.
  54. //<{IN|OUT}side_status, v0, v1, v2>
  55. array< int, int, int, int > &tri_list);
  56. private:
  57. int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx);
  58. int TestPoint(int leaf_idx, vec3 point);
  59. array<CsgBspLeaf> m_tree;
  60. };
  61. } /* namespace lol */