[2226] | 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 | // |
---|

| 13 | // The EasyMesh class |
---|

| 14 | // ------------------ |
---|

| 15 | // |
---|

| 16 | |
---|

| 17 | #if !defined __CSGBSP_CSGBSP_H__ |
---|

| 18 | #define __CSGBSP_CSGBSP_H__ |
---|

| 19 | |
---|

| 20 | namespace lol |
---|

| 21 | { |
---|

| 22 | |
---|

| 23 | #define LEAF_ABOVE 2 |
---|

| 24 | #define LEAF_FRONT 1 |
---|

| 25 | #define LEAF_BACK 0 |
---|

| 26 | #define LEAF_CURRENT -1 |
---|

| 27 | |
---|

| 28 | //Naïve bsp for the poor people |
---|

| 29 | class CsgBspLeaf |
---|

| 30 | { |
---|

| 31 | friend class CsgBsp; |
---|

| 32 | |
---|

| 33 | public: |
---|

| 34 | CsgBspLeaf(vec3 origin, vec3 normal, int above_idx) |
---|

| 35 | { |
---|

| 36 | m_origin = origin; |
---|

| 37 | m_normal = normal; |
---|

| 38 | m_leaves[LEAF_ABOVE] = above_idx; |
---|

| 39 | |
---|

| 40 | m_leaves[LEAF_FRONT] = -1; |
---|

| 41 | m_leaves[LEAF_BACK] = -1; |
---|

| 42 | } |
---|

| 43 | |
---|

| 44 | private: |
---|

| 45 | vec3 m_origin; |
---|

| 46 | vec3 m_normal; |
---|

| 47 | Array< int, vec3, vec3, vec3 > m_tri_list; |
---|

| 48 | ivec3 m_leaves; |
---|

| 49 | }; |
---|

| 50 | |
---|

| 51 | //Naïve bsp for the poor people |
---|

| 52 | class CsgBsp |
---|

| 53 | { |
---|

| 54 | public: |
---|

| 55 | void AddTriangleToTree(int const &tri_idx, vec3 const &tri_v0, vec3 const &tri_v1, vec3 const &tri_v2); |
---|

| 56 | |
---|

| 57 | //return 0 when no split has been done. |
---|

| 58 | //return 1 when split has been done. |
---|

| 59 | //return -1 when error. |
---|

| 60 | int TestTriangleToTree(vec3 const &tri_v0, vec3 const &tri_v1, vec3 const &tri_v2, |
---|

| 61 | //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha. |
---|

| 62 | //<Point_Loc, Src_V0, Src_V1, Alpha> as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; } |
---|

| 63 | Array< vec3, int, int, float > &vert_list, |
---|

| 64 | //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point. |
---|

| 65 | //<{IN|OUT}side_status, v0, v1, v2> |
---|

| 66 | Array< int, int, int, int > &tri_list); |
---|

| 67 | |
---|

| 68 | private: |
---|

| 69 | int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx); |
---|

| 70 | int TestPoint(int leaf_idx, vec3 point); |
---|

| 71 | |
---|

| 72 | Array<CsgBspLeaf> m_tree; |
---|

| 73 | }; |
---|

| 74 | |
---|

| 75 | } /* namespace lol */ |
---|

| 76 | |
---|

| 77 | #endif /* __CSGBSP_CSGBSP_H__ */ |
---|

| 78 | |
---|