6 # define INCLUDE_MATH_H
8 #ifndef INCLUDE_ALGORITHM_H
10 # define INCLUDE_ALGORITHM_H
35 return Vec3( v1.y * v2.z - v1.z * v2.y,
36 v1.z * v2.x - v1.x * v2.z,
37 v1.x * v2.y - v1.y * v2.x );
50 return (v2 - v1).Length();
63 const Vec3 sub = v2 - v1;
64 return sub.x * sub.x + sub.y * sub.y + sub.z * sub.z;
76 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
90 return Vec3( std::min( v1.x, v2.x ), std::min( v1.y, v2.y ), std::min( v1.z, v2.z ) );
103 return Vec3( std::max( v1.x, v2.x ), std::max( v1.y, v2.y ), std::max( v1.z, v2.z ) );
116 inline Vec3(
const Vec3& other ) =
default;
119 inline Vec3() : x( 0 ), y( 0 ), z( 0 ) {}
128 inline Vec3(
float ax,
float ay,
float az ) : x( ax ), y( ay ), z( az ) {}
138 const float acceptableDelta = 0.0001f;
139 if (std::fabs( x - v.x ) > acceptableDelta) {
return false; }
140 if (std::fabs( y - v.y ) > acceptableDelta) {
return false; }
141 if (std::fabs( z - v.z ) > acceptableDelta) {
return false; }
153 const float inv = 1.0f / f;
154 return Vec3( x * inv, y * inv, z * inv );
165 return Vec3( x / v.x, y / v.y, z / v.z );
175 return Vec3( -x, -y, -z );
186 return Vec3( x - v.x, y - v.y, z - v.z );
197 return Vec3( x + v.x, y + v.y, z + v.z );
208 return Vec3( x + f, y + f, z + f );
219 return x == v.x && y == v.y && z == v.z;
230 return x != v.x || y != v.y || z != v.z;
286 const float inv = 1.0f / f;
326 return Vec3( x * v.x, y * v.y, z * v.z );
337 return Vec3( x * f, y * f, z * f );
347 const float len =
Length();
349 if( std::abs( len ) < 0.0001f )
362 inline float Length()
const {
return std::sqrt( x * x + y * y + z * z ); }
365 inline void Zero() { x = y = z = 0; }
369 #if defined( _MSC_VER ) || defined( COMPILER_INTEL )
370 # define BEGIN_ALIGNED( n, a ) __declspec( align( a ) ) n
371 # define END_ALIGNED( n, a )
372 #elif defined( __GNUC__ ) || defined( __clang__ )
373 # define BEGIN_ALIGNED( n, a ) n
374 # define END_ALIGNED( n, a ) __attribute__( (aligned( a ) ) )
378 struct BEGIN_ALIGNED(
Vec4, 16 )
386 inline Vec4() : x( 0 ), y( 0 ), z( 0 ), w( 0 ) {}
396 inline Vec4(
float ax,
float ay,
float az,
float aw ) : x( ax ), y( ay ), z( az ), w( aw ) {}
399 inline explicit Vec4(
const Vec3& v ) : x( v.x ), y( v.y ), z( v.z ), w( 1 ) {}
407 inline Vec4(
const Vec3& v,
float aW ) : x( v.x ), y( v.y ), z( v.z ), w( aW ) {}
417 return Vec4( x * f, y * f, z * f, w * f );
456 return x * v.x + y * v.y + z * v.z + w * v.w;
460 inline float Length()
const {
return std::sqrt( x * x + y * y + z * z ); }
467 const float len = Length();
469 if( std::abs( len ) < 0.0001f )
477 const float iLength = 1 / len;
485 END_ALIGNED(
Vec4, 16 )