[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3Common / shared / b3Float4.h
1 #ifndef B3_FLOAT4_H
2 #define B3_FLOAT4_H
3
4 #include "Bullet3Common/shared/b3PlatformDefinitions.h"
5
6 #ifdef __cplusplus
7 #include "Bullet3Common/b3Vector3.h"
8 #define b3Float4 b3Vector3
9 #define b3Float4ConstArg const b3Vector3&
10 #define b3Dot3F4 b3Dot
11 #define b3Cross3 b3Cross
12 #define b3MakeFloat4 b3MakeVector3
13 inline b3Vector3 b3Normalized(const b3Vector3& vec)
14 {
15         return vec.normalized();
16 }
17
18 inline b3Float4 b3FastNormalized3(b3Float4ConstArg v)
19 {
20         return v.normalized();
21 }
22
23 inline b3Float4 b3MaxFloat4(const b3Float4& a, const b3Float4& b)
24 {
25         b3Float4 tmp = a;
26         tmp.setMax(b);
27         return tmp;
28 }
29 inline b3Float4 b3MinFloat4(const b3Float4& a, const b3Float4& b)
30 {
31         b3Float4 tmp = a;
32         tmp.setMin(b);
33         return tmp;
34 }
35
36 #else
37 typedef float4 b3Float4;
38 #define b3Float4ConstArg const b3Float4
39 #define b3MakeFloat4 (float4)
40 float b3Dot3F4(b3Float4ConstArg v0, b3Float4ConstArg v1)
41 {
42         float4 a1 = b3MakeFloat4(v0.xyz, 0.f);
43         float4 b1 = b3MakeFloat4(v1.xyz, 0.f);
44         return dot(a1, b1);
45 }
46 b3Float4 b3Cross3(b3Float4ConstArg v0, b3Float4ConstArg v1)
47 {
48         float4 a1 = b3MakeFloat4(v0.xyz, 0.f);
49         float4 b1 = b3MakeFloat4(v1.xyz, 0.f);
50         return cross(a1, b1);
51 }
52 #define b3MinFloat4 min
53 #define b3MaxFloat4 max
54
55 #define b3Normalized(a) normalize(a)
56
57 #endif
58
59 inline bool b3IsAlmostZero(b3Float4ConstArg v)
60 {
61         if (b3Fabs(v.x) > 1e-6 || b3Fabs(v.y) > 1e-6 || b3Fabs(v.z) > 1e-6)
62                 return false;
63         return true;
64 }
65
66 inline int b3MaxDot(b3Float4ConstArg vec, __global const b3Float4* vecArray, int vecLen, float* dotOut)
67 {
68         float maxDot = -B3_INFINITY;
69         int i = 0;
70         int ptIndex = -1;
71         for (i = 0; i < vecLen; i++)
72         {
73                 float dot = b3Dot3F4(vecArray[i], vec);
74
75                 if (dot > maxDot)
76                 {
77                         maxDot = dot;
78                         ptIndex = i;
79                 }
80         }
81         b3Assert(ptIndex >= 0);
82         if (ptIndex < 0)
83         {
84                 ptIndex = 0;
85         }
86         *dotOut = maxDot;
87         return ptIndex;
88 }
89
90 #endif  //B3_FLOAT4_H