[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletCollision / CollisionShapes / btMiniSDF.h
1 #ifndef MINISDF_H
2 #define MINISDF_H
3
4 #include "LinearMath/btVector3.h"
5 #include "LinearMath/btAabbUtil2.h"
6 #include "LinearMath/btAlignedObjectArray.h"
7
8 struct btMultiIndex
9 {
10         unsigned int ijk[3];
11 };
12
13 struct btAlignedBox3d
14 {
15         btVector3 m_min;
16         btVector3 m_max;
17
18         const btVector3& min() const
19         {
20                 return m_min;
21         }
22
23         const btVector3& max() const
24         {
25                 return m_max;
26         }
27
28         bool contains(const btVector3& x) const
29         {
30                 return TestPointAgainstAabb2(m_min, m_max, x);
31         }
32
33         btAlignedBox3d(const btVector3& mn, const btVector3& mx)
34                 : m_min(mn),
35                   m_max(mx)
36         {
37         }
38
39         btAlignedBox3d()
40         {
41         }
42 };
43
44 struct btShapeMatrix
45 {
46         double m_vec[32];
47
48         inline double& operator[](int i)
49         {
50                 return m_vec[i];
51         }
52
53         inline const double& operator[](int i) const
54         {
55                 return m_vec[i];
56         }
57 };
58
59 struct btShapeGradients
60 {
61         btVector3 m_vec[32];
62
63         void topRowsDivide(int row, double denom)
64         {
65                 for (int i = 0; i < row; i++)
66                 {
67                         m_vec[i] /= denom;
68                 }
69         }
70
71         void bottomRowsMul(int row, double val)
72         {
73                 for (int i = 32 - row; i < 32; i++)
74                 {
75                         m_vec[i] *= val;
76                 }
77         }
78
79         inline btScalar& operator()(int i, int j)
80         {
81                 return m_vec[i][j];
82         }
83 };
84
85 struct btCell32
86 {
87         unsigned int m_cells[32];
88 };
89
90 struct btMiniSDF
91 {
92         btAlignedBox3d m_domain;
93         unsigned int m_resolution[3];
94         btVector3 m_cell_size;
95         btVector3 m_inv_cell_size;
96         std::size_t m_n_cells;
97         std::size_t m_n_fields;
98         bool m_isValid;
99
100         btAlignedObjectArray<btAlignedObjectArray<double> > m_nodes;
101         btAlignedObjectArray<btAlignedObjectArray<btCell32> > m_cells;
102         btAlignedObjectArray<btAlignedObjectArray<unsigned int> > m_cell_map;
103
104         btMiniSDF()
105                 : m_isValid(false)
106         {
107         }
108         bool load(const char* data, int size);
109         bool isValid() const
110         {
111                 return m_isValid;
112         }
113         unsigned int multiToSingleIndex(btMultiIndex const& ijk) const;
114
115         btAlignedBox3d subdomain(btMultiIndex const& ijk) const;
116
117         btMultiIndex singleToMultiIndex(unsigned int l) const;
118
119         btAlignedBox3d subdomain(unsigned int l) const;
120
121         btShapeMatrix
122         shape_function_(btVector3 const& xi, btShapeGradients* gradient = 0) const;
123
124         bool interpolate(unsigned int field_id, double& dist, btVector3 const& x, btVector3* gradient) const;
125 };
126
127 #endif  //MINISDF_H