-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVecUtils.h
More file actions
66 lines (53 loc) · 1.43 KB
/
VecUtils.h
File metadata and controls
66 lines (53 loc) · 1.43 KB
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
#ifndef VEC_UTILS_H
#define VEC_UTILS_H
#include <vecmath.h>
class VecUtils
{
public:
static Vector3f min( const Vector3f& b, const Vector3f& c )
{
Vector3f out;
for( int i = 0; i < 3; ++i )
{
out[ i ] = ( b[i] < c[i] ) ? b[i] : c[i];
}
return out;
}
static Vector3f max( const Vector3f& b, const Vector3f& c )
{
Vector3f out;
for( int i = 0; i < 3; ++i )
{
out[ i ] = ( b[i] > c[i] ) ? b[i] : c[i];
}
return out;
}
static Vector3f clamp( const Vector3f& data, float low = 0, float high = 1 )
{
Vector3f out = data;
for( int i = 0; i < 3; ++i )
{
if( out[ i ] < low )
{
out[ i ] = low;
}
if( out[ i ] > high )
{
out[ i ] = high;
}
}
return out;
}
// transforms a 3D point using a matrix, returning a 3D point
static Vector3f transformPoint( const Matrix4f& mat, const Vector3f& point )
{
return ( mat * Vector4f( point, 1 ) ).xyz();
}
// transform a 3D directino using a matrix, returning a direction
// This function *does not* take the inverse tranpose for you.
static Vector3f transformDirection( const Matrix4f& mat, const Vector3f& dir )
{
return ( mat * Vector4f( dir, 0 ) ).xyz();
}
};
#endif // VEC_UTILS_H