-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmath.fxh
149 lines (111 loc) · 2.65 KB
/
math.fxh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#define MATH_FXH
////////////////////////////////////////////////////////////////
//
// Constants
//
////////////////////////////////////////////////////////////////
#ifndef PI
#define PI 3.1415926535897
#endif
#ifndef INVPI
#define INVPI 0.31830988618
#endif
#ifndef HALFPI
#define HALFPI 1.57079632679
#endif
#ifndef TWOPI
#define TWOPI 6.28318531
#endif
#ifndef TAU
#define TAU (2*PI)
#endif
#ifndef FOURPI
#define FOUR_PI 12.56637061436
#endif
#ifndef FLOATMIN
#define FLOATMIN 1.175494351e-38
// Minimum representable positive floating-point number
#endif
#ifndef FLOATMAX
#define FLOATMAX 3.402823466e+38
// Maximum representable floating-point number
#endif
////////////////////////////////////////////////////////////////
//
// Safe pow functions
//
////////////////////////////////////////////////////////////////
float pows(float a, float b) {return pow(abs(a),b)*sign(a);}
float2 pows(float a, float2 b) {return pow(abs(a),b)*sign(a);}
float3 pows(float a, float3 b) {return pow(abs(a),b)*sign(a);}
float4 pows(float a, float4 b) {return pow(abs(a),b)*sign(a);}
float2 pows(float2 a, float b) {return pow(abs(a),b)*sign(a);}
float2 pows(float2 a, float2 b) {return pow(abs(a),b)*sign(a);}
float3 pows(float3 a, float b) {return pow(abs(a),b)*sign(a);}
float3 pows(float3 a, float3 b) {return pow(abs(a),b)*sign(a);}
float4 pows(float4 a, float b) {return pow(abs(a),b)*sign(a);}
float4 pows(float4 a, float4 b) {return pow(abs(a),b)*sign(a);}
////////////////////////////////////////////////////////////////
//
// Vector Min/Max
//
////////////////////////////////////////////////////////////////
float vmax(float2 v)
{
return max(v.x, v.y);
}
float vmax(float3 v)
{
return max(max(v.x, v.y), v.z);
}
float vmax(float4 v)
{
return max(max(v.x, v.y), max(v.z, v.w));
}
float vmin(float2 v)
{
return min(v.x, v.y);
}
float vmin(float3 v)
{
return min(min(v.x, v.y), v.z);
}
float vmin(float4 v) {
return min(min(v.x, v.y), min(v.z, v.w));
}
////////////////////////////////////////////////////////////////
//
// HELPER FUNCTIONS
//
////////////////////////////////////////////////////////////////
// Sign function that doesn't return 0
float sgn(float x)
{
return (x<0)?-1:1;
}
float2 sgn(float2 v)
{
return float2((v.x<0)?-1:1, (v.y<0)?-1:1);
}
float square (float x)
{
return x*x;
}
float2 square (float2 x)
{
return x*x;
}
float3 square (float3 x)
{
return x*x;
}
float lengthSqr(float3 x)
{
return dot(x, x);
}
// glsl style mod
#ifndef mod
#define mod(x, y) (x - y * floor((x) / y))
#endif
//EOF
/////////////////////////////////////////////////////////////////////////////////////////