summaryrefslogtreecommitdiff
path: root/thirdparty/bullet/src/Bullet3Common/shared/b3Float4.h
blob: 5e4b95bcee156493792f52cdee74410a19f3b9f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef B3_FLOAT4_H
#define B3_FLOAT4_H

#include "Bullet3Common/shared/b3PlatformDefinitions.h"

#ifdef __cplusplus
	#include "Bullet3Common/b3Vector3.h"
	#define b3Float4 b3Vector3
	#define b3Float4ConstArg const b3Vector3&
	#define b3Dot3F4 b3Dot
	#define b3Cross3 b3Cross
	#define	b3MakeFloat4  b3MakeVector3
	inline b3Vector3 b3Normalized(const b3Vector3& vec)
	{
		return vec.normalized();
	}

	inline b3Float4 b3FastNormalized3(b3Float4ConstArg v)
	{
		return v.normalized();
	}

	inline b3Float4 b3MaxFloat4 (const b3Float4& a, const b3Float4& b)
	{
		b3Float4 tmp = a;
		tmp.setMax(b);
		return tmp;
	}
	inline b3Float4 b3MinFloat4 (const b3Float4& a, const b3Float4& b)
	{
		b3Float4 tmp = a;
		tmp.setMin(b);
		return tmp;
	}



#else
	typedef float4	b3Float4;
	#define b3Float4ConstArg const b3Float4
	#define b3MakeFloat4 (float4)
	float b3Dot3F4(b3Float4ConstArg v0,b3Float4ConstArg v1)
	{
		float4 a1 = b3MakeFloat4(v0.xyz,0.f);
		float4 b1 = b3MakeFloat4(v1.xyz,0.f);
		return dot(a1, b1);
	}
	b3Float4 b3Cross3(b3Float4ConstArg v0,b3Float4ConstArg v1)
	{
		float4 a1 = b3MakeFloat4(v0.xyz,0.f);
		float4 b1 = b3MakeFloat4(v1.xyz,0.f);
		return cross(a1, b1);
	}
	#define b3MinFloat4 min
	#define b3MaxFloat4 max

	#define b3Normalized(a) normalize(a)

#endif 


		
inline bool b3IsAlmostZero(b3Float4ConstArg v)
{
	if(b3Fabs(v.x)>1e-6 || b3Fabs(v.y)>1e-6 || b3Fabs(v.z)>1e-6)	
		return false;
	return true;
}


inline int    b3MaxDot( b3Float4ConstArg vec, __global const b3Float4* vecArray, int vecLen, float* dotOut )
{
    float maxDot = -B3_INFINITY;
    int i = 0;
    int ptIndex = -1;
    for( i = 0; i < vecLen; i++ )
    {
        float dot = b3Dot3F4(vecArray[i],vec);
            
        if( dot > maxDot )
        {
            maxDot = dot;
            ptIndex = i;
        }
    }
	b3Assert(ptIndex>=0);
    if (ptIndex<0)
	{
		ptIndex = 0;
	}
    *dotOut = maxDot;
    return ptIndex;
}



#endif //B3_FLOAT4_H