Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
MathVectors.h
Go to the documentation of this file.
1/***************************************************************************
2 * Mathlib
3 *
4 * Copyright (C) 2003-2004, Alexander Zaprjagaev <frustum@frustum.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 ***************************************************************************
21 * Author: Scott Lee
22*/
23
24/* Copyright (c) 2018 DIVIDE-Studio
25 Copyright (c) 2009 Ionut Cava
26
27 This file is part of DIVIDE Framework.
28
29 Permission is hereby granted, free of charge, to any person obtaining a copy
30 of this software
31 and associated documentation files (the "Software"), to deal in the Software
32 without restriction,
33 including without limitation the rights to use, copy, modify, merge, publish,
34 distribute, sublicense,
35 and/or sell copies of the Software, and to permit persons to whom the
36 Software is furnished to do so,
37 subject to the following conditions:
38
39 The above copyright notice and this permission notice shall be included in
40 all copies or substantial portions of the Software.
41
42 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 IMPLIED,
44 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
45 PARTICULAR PURPOSE AND NONINFRINGEMENT.
46 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
47 DAMAGES OR OTHER LIABILITY,
48 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
49 IN CONNECTION WITH THE SOFTWARE
50 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
52 */
53
54#pragma once
55#ifndef DVD_MATH_VECTORS_H_
56#define DVD_MATH_VECTORS_H_
57
58#include "MathHelper.h"
59
60namespace Divide
61{
62 namespace AVX
63 {
64 bool Fneq128( __m128 const& a, __m128 const& b ) noexcept;
65 bool Fneq128( __m128 const& a, __m128 const& b, const F32 epsilon ) noexcept;
66 __m128 DotSimd( const __m128& a, const __m128& b ) noexcept;
67 __m128 SimpleDot( __m128 a, __m128 b ) noexcept;
68 }; // namespace AVX
69
70 template<typename T>
72 {
73 public:
74 SimdVector() noexcept : SimdVector( 0 )
75 {
76 }
77 explicit SimdVector( T reg0, T reg1, T reg2, T reg3 ) noexcept : _reg{ reg0, reg1, reg2, reg3 }
78 {
79 }
80 explicit SimdVector( T val ) noexcept : _reg{ val, val, val, val }
81 {
82 }
83 explicit SimdVector( T reg[4] ) noexcept : _reg( reg )
84 {
85 }
86
87 T _reg[4];
88
89 bool operator==( const SimdVector& ) const = default;
90 };
91
92 template<>
94 {
95 public:
96 SimdVector() noexcept : SimdVector( 0.f )
97 {
98 }
99 explicit SimdVector( F32 reg0, F32 reg1, F32 reg2, F32 reg3 ) noexcept : _reg( _mm_set_ps( reg3, reg2, reg1, reg0 ) )
100 {
101 }
102 explicit SimdVector( F32 reg ) noexcept : _reg( _mm_set_ps( reg, reg, reg, reg ) )
103 {
104 }
105 explicit SimdVector( F32 reg[4] ) noexcept : _reg( _mm_set_ps( reg[3], reg[2], reg[1], reg[0] ) )
106 {
107 }
108 explicit SimdVector( const __m128 reg ) noexcept : _reg( reg )
109 {
110 }
111
112 bool operator==( const SimdVector& other ) const noexcept
113 {
114 return !AVX::Fneq128( _reg, other._reg, EPSILON_F32 );
115 }
116
117 bool operator!=( const SimdVector& other ) const noexcept
118 {
119 return AVX::Fneq128( _reg, other._reg, EPSILON_F32 );
120 }
121 __m128 _reg;
122 };
123
124 /***********************************************************************
125 * vec2 - A 2-tuple used to represent things like a vector in 2D space,
126 * a point in 2D space or just 2 values linked together
127 ***********************************************************************/
128 template <typename T>
129 class vec2
130 {
131 static_assert(ValidMathType<T>, "Invalid base type!");
132
133 public:
134 vec2() noexcept : vec2( T{0} ) {}
135
136 vec2( T value ) noexcept : vec2( value, value )
137 {
138 }
139 template<typename U> requires std::is_pod_v<U>
140 vec2( U value ) noexcept : vec2( value, value )
141 {
142 }
143 vec2( T xIn, T yIn ) noexcept : x( xIn ), y( yIn )
144 {
145 }
146 template <typename U> requires std::is_pod_v<U>
147 vec2( U xIn, U yIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) )
148 {
149 }
150 template <typename U, typename V> requires std::is_pod_v<U> && std::is_pod_v<U>
151 vec2( U xIn, V yIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) )
152 {
153 }
154 vec2( const T* _v ) noexcept : vec2( _v[0], _v[1] )
155 {
156 }
157 vec2( const vec3<T>& _v ) noexcept : vec2( _v.xy() )
158 {
159 }
160 vec2( const vec4<T>& _v ) noexcept : vec2( _v.xy() )
161 {
162 }
163 template<typename U> requires std::is_pod_v<U>
164 vec2( const vec2<U>& v ) noexcept : vec2( v.x, v.y )
165 {
166 }
167 template<typename U> requires std::is_pod_v<U>
168 vec2( const vec3<U>& v ) noexcept : vec2( v.x, v.y )
169 {
170 }
171 template<typename U> requires std::is_pod_v<U>
172 vec2( const vec4<U>& v ) noexcept : vec2( v.x, v.y )
173 {
174 }
175
176 bool operator> ( const vec2& v ) const noexcept
177 {
178 return x > v.x && y > v.y;
179 }
180 bool operator< ( const vec2& v ) const noexcept
181 {
182 return x < v.x&& y < v.y;
183 }
184 bool operator<=( const vec2& v ) const noexcept
185 {
186 return *this < v || *this == v;
187 }
188 bool operator>=( const vec2& v ) const noexcept
189 {
190 return *this > v || *this == v;
191 }
192 bool operator==( const vec2& v ) const noexcept
193 {
194 return this->compare( v );
195 }
196 bool operator!=( const vec2& v ) const noexcept
197 {
198 return !this->compare( v );
199 }
200 template<typename U> requires std::is_pod_v<U>
201 bool operator!=( const vec2<U>& v ) const noexcept
202 {
203 return !this->compare( v );
204 }
205 template<typename U> requires std::is_pod_v<U>
206 bool operator==( const vec2<U>& v ) const noexcept
207 {
208 return this->compare( v );
209 }
210
211 template<typename U> requires std::is_pod_v<U>
212 [[nodiscard]] vec2 operator-( U _f ) const noexcept
213 {
214 return vec2( this->x - _f, this->y - _f );
215 }
216 template<typename U> requires std::is_pod_v<U>
217 [[nodiscard]] vec2 operator+( U _f ) const noexcept
218 {
219 return vec2( this->x + _f, this->y + _f );
220 }
221 template<typename U> requires std::is_pod_v<U>
222 [[nodiscard]] vec2 operator*( U _f ) const noexcept
223 {
224 return vec2( this->x * _f, this->y * _f );
225 }
226 template<typename U> requires std::is_pod_v<U>
227 [[nodiscard]] vec2 operator/( U _i ) const noexcept
228 {
229 if ( !IS_ZERO( _i ) )
230 {
231 return vec2( this->x / _i, this->y / _i );
232 } return *this;
233 }
234
235 template<typename U> requires std::is_pod_v<U>
236 [[nodiscard]] vec2 operator+( const vec2<U> v ) const noexcept
237 {
238 return vec2( this->x + v.x, this->y + v.y );
239 }
240 template<typename U> requires std::is_pod_v<U>
241 [[nodiscard]] vec2 operator-( const vec2<U> v ) const noexcept
242 {
243 return vec2( this->x - v.x, this->y - v.y );
244 }
245 template<typename U> requires std::is_pod_v<U>
246 [[nodiscard]] vec2 operator*( const vec2<U> v ) const noexcept
247 {
248 return vec2( this->x * v.x, this->y * v.y );
249 }
250
251 [[nodiscard]] vec2 operator-() const noexcept
252 {
253 return vec2( -this->x, -this->y );
254 }
255
256 template<typename U> requires std::is_pod_v<U>
257 vec2& operator+=( U _f ) noexcept
258 {
259 this->set( *this + _f ); return *this;
260 }
261 template<typename U> requires std::is_pod_v<U>
262 vec2& operator-=( U _f ) noexcept
263 {
264 this->set( *this - _f ); return *this;
265 }
266 template<typename U> requires std::is_pod_v<U>
267 vec2& operator*=( U _f ) noexcept
268 {
269 this->set( *this * _f ); return *this;
270 }
271 template<typename U> requires std::is_pod_v<U>
272 vec2& operator/=( U _f ) noexcept
273 {
274 this->set( *this / _f ); return *this;
275 }
276
277 template<typename U> requires std::is_pod_v<U>
278 vec2& operator*=( const vec2<U> v ) noexcept
279 {
280 this->set( *this * v ); return *this;
281 }
282 template<typename U> requires std::is_pod_v<U>
283 vec2& operator+=( const vec2<U> v ) noexcept
284 {
285 this->set( *this + v ); return *this;
286 }
287 template<typename U> requires std::is_pod_v<U>
288 vec2& operator-=( const vec2<U> v ) noexcept
289 {
290 this->set( *this - v ); return *this;
291 }
292 template<typename U> requires std::is_pod_v<U>
293 vec2& operator/=( const vec2<U> v ) noexcept
294 {
295 this->set( *this / v ); return *this;
296 }
297
298 template<typename U> requires std::is_unsigned_v<U>
299 [[nodiscard]] T& operator[]( U i ) noexcept
300 {
301 return this->_v[i];
302 }
303 template<typename U> requires std::is_unsigned_v<U>
304 [[nodiscard]] const T& operator[]( U i ) const noexcept
305 {
306 return this->_v[i];
307 }
308
309 [[nodiscard]] vec2 operator/( const vec2& v ) const noexcept
310 {
311 return vec2( IS_ZERO( v.x ) ? this->x : this->x / v.x,
312 IS_ZERO( v.y ) ? this->y : this->y / v.y );
313 }
314
315 [[nodiscard]] operator T* () noexcept
316 {
317 return this->_v;
318 }
319 [[nodiscard]] operator const T* () const noexcept
320 {
321 return this->_v;
322 }
323
325 void swap( vec2* iv ) noexcept
326 {
327 std::swap( this->x, iv->x ); std::swap( this->x, iv->x );
328 }
330 void swap( vec2& iv ) noexcept
331 {
332 std::swap( this->x, iv.x ); std::swap( this->x, iv.x );
333 }
335 void set( const T* v ) noexcept
336 {
337 std::memcpy( &_v[0], &v[0], sizeof( T ) * 2 );
338 }
340 void set( T value ) noexcept
341 {
342 this->set( value, value );
343 }
345 void set( T xIn, T yIn ) noexcept
346 {
347 this->x = xIn; this->y = yIn;
348 }
349 template <typename U> requires std::is_pod_v<U>
350 void set( U xIn, U yIn ) noexcept
351 {
352 this->x = static_cast<T>(xIn); this->y = static_cast<T>(yIn);
353 }
355 void set( const vec2& v ) noexcept
356 {
357 this->set( &v._v[0] );
358 }
360 void set( const vec3<T>& v ) noexcept
361 {
362 this->set( v.x, v.y );
363 }
365 void set( const vec4<T>& v ) noexcept
366 {
367 this->set( v.x, v.y );
368 }
370 void reset()
371 {
372 this->set( T{0} );
373 }
375 [[nodiscard]] T length() const noexcept
376 {
377 return Divide::Sqrt( lengthSquared() );
378 }
379 [[nodiscard]] T lengthSquared() const noexcept;
381 [[nodiscard]] T angle() const
382 {
383 return static_cast<T>(std::atan2( this->y, this->x ));
384 }
386 [[nodiscard]] T angle( const vec2& v ) const
387 {
388 return static_cast<T>(std::atan2( v.y - this->y, v.x - this->x ));
389 }
391 [[nodiscard]] T distance( const vec2& v ) const;
393 [[nodiscard]] T distanceSquared( const vec2& v ) const noexcept;
395 [[nodiscard]] vec2& normalize() noexcept;
397 [[nodiscard]] T minComponent() const noexcept;
399 [[nodiscard]] T maxComponent() const noexcept;
401 void round();
403 void lerp( const vec2& v, T factor ) noexcept;
405 void lerp( const vec2& v, const vec2& factor ) noexcept;
407 [[nodiscard]] T dot( const vec2& v ) const noexcept;
409 [[nodiscard]] T projectionOnLine( const vec2& vA, const vec2& vB ) const;
411 [[nodiscard]] vec2 closestPointOnLine( const vec2& vA, const vec2& vB );
413 [[nodiscard]] vec2 closestPointOnSegment( const vec2& vA, const vec2& vB );
415 template<typename U> requires std::is_pod_v<U>
416 [[nodiscard]] bool compare( vec2<U> v ) const noexcept;
418 template<typename U> requires std::is_pod_v<U>
419 [[nodiscard]] bool compare( vec2<U> v, U epsi ) const noexcept;
421 [[nodiscard]] void get( T* v ) const;
422
423 union
424 {
425 struct
426 {
427 T x, y;
428 };
429 struct
430 {
431 T s, t;
432 };
433 struct
434 {
436 };
437 struct
438 {
440 };
441 struct
442 {
444 };
445
446 T _v[2] = {T{0}, T{0} };
447 };
448 };
449
451 template <typename T, typename U> requires std::is_pod_v<U>
452 [[nodiscard]] vec2<T> Lerp( vec2<T> u, vec2<T> v, U factor ) noexcept;
454 template <typename T>
455 [[nodiscard]] vec2<T> Lerp( vec2<T> u, vec2<T> v, vec2<T> factor ) noexcept;
456 template <typename T>
457 [[nodiscard]] vec2<T> Cross( vec2<T> v1, vec2<T> v2 ) noexcept;
458 template <typename T>
459 [[nodiscard]] vec2<T> Inverse( vec2<T> v ) noexcept;
460 template <typename T>
461 [[nodiscard]] vec2<T> Normalize( vec2<T>& vector ) noexcept;
462 template <typename T>
463 [[nodiscard]] vec2<T> Normalized( vec2<T> vector ) noexcept;
464 template <typename T>
465 [[nodiscard]] T Dot( vec2<T> a, vec2<T> b ) noexcept;
466 template <typename T>
467 [[nodiscard]] void OrthoNormalize( vec2<T>& n, vec2<T>& u ) noexcept;
469 template <typename T>
470 [[nodiscard]] vec2<T> operator*( T fl, vec2<T> v ) noexcept;
471 template <typename T>
472 [[nodiscard]] vec2<T> Clamped( vec2<T> v, vec2<T> min, vec2<T> max ) noexcept;
473
474 /***********************************************************************
475 * vec3 - A 3-tuple used to represent things like a vector in 3D space,
476 * a point in 3D space or just 3 values linked together
477 ***********************************************************************/
478 template <typename T>
479 class vec3
480 {
481 static_assert(ValidMathType<T>, "Invalid base type!");
482
483 public:
484 vec3() noexcept : vec3( T{0} ) {}
485
486 vec3( T value ) noexcept : vec3( value, value, value )
487 {
488 }
489 template<typename U> requires std::is_pod_v<U>
490 vec3( U value ) noexcept : vec3( value, value, value )
491 {
492 }
493 vec3( T xIn, T yIn, T zIn ) noexcept : x( xIn ), y( yIn ), z( zIn )
494 {
495 }
496 template <typename U> requires std::is_pod_v<U>
497 vec3( U xIn, U yIn, U zIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) ), z( static_cast<T>(zIn) )
498 {
499 }
500 template <typename U, typename V>
501 vec3( U xIn, U yIn, V zIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) ), z( static_cast<T>(zIn) )
502 {
503 }
504 template <typename U, typename V>
505 vec3( U xIn, V yIn, V zIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) ), z( static_cast<T>(zIn) )
506 {
507 }
508 template <typename U, typename V, typename W>
509 vec3( U xIn, V yIn, W zIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) ), z( static_cast<T>(zIn) )
510 {
511 }
512 vec3( const T* v ) noexcept : vec3( v[0], v[1], v[2] )
513 {
514 }
515 vec3( const vec2<T> v ) noexcept : vec3( v, T{0} )
516 {
517 }
518 vec3( const vec2<T> v, T zIn ) noexcept : vec3( v.x, v.y, zIn )
519 {
520 }
521 vec3( const vec4<T>& v ) noexcept : vec3( v.x, v.y, v.z )
522 {
523 }
524 template<typename U> requires std::is_pod_v<U>
525 vec3( const vec2<U> v ) noexcept : vec3( v.x, v.y, U{0} )
526 {
527 }
528 template<typename U> requires std::is_pod_v<U>
529 vec3( const vec3<U>& v ) noexcept : vec3( v.x, v.y, v.z )
530 {
531 }
532 template<typename U> requires std::is_pod_v<U>
533 vec3( const vec4<U>& v ) noexcept : vec3( v.x, v.y, v.z )
534 {
535 }
536
537 [[nodiscard]] bool operator> ( const vec3& v ) const noexcept
538 {
539 return x > v.x && y > v.y && z > v.z;
540 }
541 [[nodiscard]] bool operator< ( const vec3& v ) const noexcept
542 {
543 return x < v.x&& y < v.y&& z < v.z;
544 }
545 [[nodiscard]] bool operator<=( const vec3& v ) const noexcept
546 {
547 return *this < v || *this == v;
548 }
549 [[nodiscard]] bool operator>=( const vec3& v ) const noexcept
550 {
551 return *this > v || *this == v;
552 }
553 [[nodiscard]] bool operator!=( const vec3& v ) const noexcept
554 {
555 return !this->compare( v );
556 }
557 [[nodiscard]] bool operator==( const vec3& v ) const noexcept
558 {
559 return this->compare( v );
560 }
561 template<typename U> requires std::is_pod_v<U>
562 [[nodiscard]] bool operator!=( const vec3<U>& v ) const noexcept
563 {
564 return !this->compare( v );
565 }
566 template<typename U> requires std::is_pod_v<U>
567 [[nodiscard]] bool operator==( const vec3<U>& v ) const noexcept
568 {
569 return this->compare( v );
570 }
571
572 template <typename U> requires std::is_pod_v<U>
573 [[nodiscard]] vec3 operator+( U _f ) const noexcept
574 {
575 return vec3( this->x + _f, this->y + _f, this->z + _f );
576 }
577 template <typename U> requires std::is_pod_v<U>
578 [[nodiscard]] vec3 operator-( U _f ) const noexcept
579 {
580 return vec3( this->x - _f, this->y - _f, this->z - _f );
581 }
582 template <typename U> requires std::is_pod_v<U>
583 [[nodiscard]] vec3 operator*( U _f ) const noexcept
584 {
585 return vec3( this->x * _f, this->y * _f, this->z * _f );
586 }
587 template <typename U> requires std::is_pod_v<U>
588 [[nodiscard]] vec3 operator/( U _f ) const noexcept
589 {
590 if ( IS_ZERO( _f ) )
591 {
592 return *this;
593 } return vec3( this->x / _f, this->y / _f, this->z / _f );
594 }
595
596 [[nodiscard]] vec3 operator-() const noexcept
597 {
598 return vec3( -this->x, -this->y, -this->z );
599 }
600
601 template <typename U> requires std::is_pod_v<U>
602 [[nodiscard]] vec3 operator+( const vec3<U>& v ) const noexcept
603 {
604 return vec3( this->x + v.x, this->y + v.y, this->z + v.z );
605 }
606 template <typename U> requires std::is_pod_v<U>
607 [[nodiscard]] vec3 operator-( const vec3<U>& v ) const noexcept
608 {
609 return vec3( this->x - v.x, this->y - v.y, this->z - v.z );
610 }
611 template<typename U> requires std::is_pod_v<U>
612 [[nodiscard]] vec3 operator*( const vec3<U>& v ) const noexcept
613 {
614 return vec3( this->x * v.x, this->y * v.y, this->z * v.z );
615 }
616
617 template<typename U> requires std::is_pod_v<U>
618 vec3& operator+=( U _f ) noexcept
619 {
620 this->set( *this + _f ); return *this;
621 }
622 template<typename U> requires std::is_pod_v<U>
623 vec3& operator-=( U _f ) noexcept
624 {
625 this->set( *this - _f ); return *this;
626 }
627 template<typename U> requires std::is_pod_v<U>
628 vec3& operator*=( U _f ) noexcept
629 {
630 this->set( *this * _f ); return *this;
631 }
632 template<typename U> requires std::is_pod_v<U>
633 vec3& operator/=( U _f ) noexcept
634 {
635 this->set( *this / _f ); return *this;
636 }
637
638 template<typename U> requires std::is_pod_v<U>
639 vec3& operator*=( const vec3<U>& v ) noexcept
640 {
641 this->set( *this * v ); return *this;
642 }
643 template<typename U> requires std::is_pod_v<U>
644 vec3& operator+=( const vec3<U>& v ) noexcept
645 {
646 this->set( *this + v ); return *this;
647 }
648 template<typename U> requires std::is_pod_v<U>
649 vec3& operator-=( const vec3<U>& v ) noexcept
650 {
651 this->set( *this - v ); return *this;
652 }
653 template<typename U> requires std::is_pod_v<U>
654 vec3& operator/=( const vec3<U>& v ) noexcept
655 {
656 this->set( *this / v ); return *this;
657 }
658
659 template<typename U> requires std::is_unsigned_v<U>
660 [[nodiscard]] T& operator[]( const U i ) noexcept
661 {
662 return this->_v[i];
663 }
664 template<typename U> requires std::is_unsigned_v<U>
665 [[nodiscard]] const T& operator[]( const U i ) const noexcept
666 {
667 return this->_v[i];
668 }
669
670 template<typename U> requires std::is_pod_v<U>
671 [[nodiscard]] vec3 operator/( const vec3<U>& v ) const noexcept
672 {
673 return vec3( IS_ZERO( v.x ) ? this->x : this->x / v.x,
674 IS_ZERO( v.y ) ? this->y : this->y / v.y,
675 IS_ZERO( v.z ) ? this->z : this->z / v.z );
676 }
677
678 [[nodiscard]] operator T* () noexcept
679 {
680 return this->_v;
681 }
682 [[nodiscard]] operator const T* () const noexcept
683 {
684 return this->_v;
685 }
686
688 [[nodiscard]] vec2<T> rb() const noexcept
689 {
690 return vec2<T>( this->r, this->b );
691 }
692 [[nodiscard]] vec2<T> xz() const noexcept
693 {
694 return this->rb();
695 }
696
697 void rb( const vec2<T> rb ) noexcept
698 {
699 this->r = rb.x; this->b = rb.y;
700 }
701 void xz( const vec2<T> xz ) noexcept
702 {
703 this->x = xz.x; this->z = xz.y;
704 }
705
707 void set( const T* v ) noexcept
708 {
709 std::memcpy( &_v[0], &v[0], 3 * sizeof( T ) );
710 }
712 void set( T value ) noexcept
713 {
714 x = value; y = value; z = value;
715 }
717 void set( T xIn, T yIn, T zIn ) noexcept
718 {
719 this->x = xIn; this->y = yIn; this->z = zIn;
720 }
721 template <typename U> requires std::is_pod_v<U>
722 void set( U xIn, U yIn, U zIn ) noexcept
723 {
724 this->x = static_cast<T>(xIn); this->y = static_cast<T>(yIn); this->z = static_cast<T>(zIn);
725 }
727 void set( const vec2<T> v ) noexcept
728 {
729 std::memcpy( _v, v._v, 2 * sizeof( T ) );
730 }
732 void set( const vec3& v ) noexcept
733 {
734 std::memcpy( _v, v._v, 3 * sizeof( T ) );
735 }
737 void set( const vec4<T>& v ) noexcept
738 {
739 std::memcpy( _v, v._v, 3 * sizeof( T ) );
740 }
742 void reset() noexcept
743 {
744 std::memset( _v, 0, 3 * sizeof( T ) );
745 }
747 [[nodiscard]] T length() const noexcept
748 {
749 return Divide::Sqrt( lengthSquared() );
750 }
752 [[nodiscard]] bool isZeroLength() const noexcept
753 {
754 return lengthSquared() < EPSILON_F32;
755 }
757 template<typename U> requires std::is_pod_v<U>
758 [[nodiscard]] bool compare( const vec3<U>& v ) const noexcept;
760 template<typename U> requires std::is_pod_v<U>
761 [[nodiscard]] bool compare( const vec3<U>& v, U epsi ) const noexcept;
763 [[nodiscard]] bool isUniform( F32 tolerance = 0.0001f ) const noexcept;
765 template<typename U> requires std::is_pod_v<U>
766 [[nodiscard]] bool isPerpendicular( const vec3<U>& other, F32 epsilon = EPSILON_F32 ) const noexcept;
768 [[nodiscard]] T lengthSquared() const noexcept;
770 [[nodiscard]] T dot( const vec3& v ) const noexcept;
772 [[nodiscard]] T angle( vec3& v ) const;
774 [[nodiscard]] T distance( const vec3& v ) const noexcept;
776 [[nodiscard]] T distanceSquared( const vec3& v ) const noexcept;
778 vec3& normalize() noexcept;
780 [[nodiscard]] T minComponent() const noexcept;
782 [[nodiscard]] T maxComponent() const noexcept;
784 void round();
786 [[nodiscard]] T projectionOnLine( const vec3& vA, const vec3& vB ) const;
789 [[nodiscard]] vec3 closestPointOnLine( const vec3& vA, const vec3& vB );
792 [[nodiscard]] vec3 closestPointOnSegment( const vec3& vA, const vec3& vB );
794 [[nodiscard]] vec3 direction( const vec3& u ) const noexcept;
796 [[nodiscard]] vec3 projectToNorm( const vec3<T>& direction ) noexcept;
798 void lerp( const vec3& v, T factor ) noexcept;
801 void lerp( const vec3& v, const vec3& factor ) noexcept;
804 [[nodiscard]] vec3 vector( const vec3& vp1, const vec3& vp2 ) const noexcept;
806 void cross( const vec3& v1, const vec3& v2 ) noexcept;
809 void cross( const vec3& v2 ) noexcept;
811 void rotateX( D64 radians );
813 void rotateY( D64 radians );
815 void rotateZ( D64 radians );
817 void swap( vec3& iv ) noexcept;
819 void swap( vec3* iv ) noexcept;
822 void get( T* v ) const noexcept;
823
824 union
825 {
826 struct
827 {
828 T x, y, z;
829 };
830 struct
831 {
832 T s, t, p;
833 };
834 struct
835 {
836 T r, g, b;
837 };
838 struct
839 {
841 };
842 struct
843 {
845 };
846 struct
847 {
849 };
850 struct
851 {
853 };
854 struct
855 {
857 };
858 struct
859 {
861 };
862
863 T _v[3] = {T{0}, T{0}, T{0}};
864 };
865 };
866
868 template <typename T, typename U> requires std::is_pod_v<U>
869 [[nodiscard]] vec3<T> Lerp( const vec3<T>& u, const vec3<T>& v, U factor ) noexcept;
871 template <typename T>
872 [[nodiscard]] vec3<T> Lerp( const vec3<T>& u, const vec3<T>& v, const vec3<T>& factor ) noexcept;
873 template <typename T>
874 [[nodiscard]] vec3<T> Abs( const vec3<T>& vector ) noexcept;
875 template <typename T>
876 [[nodiscard]] vec3<T> Min( const vec3<T>& v1, const vec3<T>& v2 ) noexcept;
877 template <typename T>
878 [[nodiscard]] vec3<T> Max( const vec3<T>& v1, const vec3<T>& v2 ) noexcept;
879 template <typename T>
880 [[nodiscard]] vec3<T> Normalize( vec3<T>& vector ) noexcept;
881 template <typename T>
882 [[nodiscard]] vec3<T> Normalized( const vec3<T>& vector ) noexcept;
884 template <typename T>
885 [[nodiscard]] T Dot( const vec3<T>& a, const vec3<T>& b ) noexcept;
887 template <typename T>
888 [[nodiscard]] vec3<T> Cross( const vec3<T>& v1, const vec3<T>& v2 ) noexcept;
889 template <typename T>
890 [[nodiscard]] vec3<T> AreOrthogonal( const vec3<T>& v1, const vec3<T>& v2 ) noexcept;
891 template <typename T>
892 [[nodiscard]] vec3<T> Inverse( const vec3<T>& v ) noexcept;
893 template <typename T>
894 [[nodiscard]] vec3<T> operator*( T fl, const vec3<T>& v ) noexcept;
895 // project 'in' onto the given direction
896 template<typename T>
897 [[nodiscard]] vec3<T> ProjectToNorm( const vec3<T>& in, const vec3<T>& direction );
898 template <typename T>
899 void OrthoNormalize( vec3<T>& n, vec3<T>& u ) noexcept;
900 template <typename T>
901 void OrthoNormalize( vec3<T>& v1, vec3<T>& v2, vec3<T>& v3 ) noexcept;
902 template<typename T>
903 [[nodiscard]] vec3<T> Perpendicular( const vec3<T>& v ) noexcept;
904 template <typename T>
905 [[nodiscard]] vec3<T> Clamped( const vec3<T>& v, const vec3<T>& min, const vec3<T>& max ) noexcept;
906
907 /**********************************************************************************************************************
908 * vec4 - A 4-tuple used to represent things like a vector in 4D space (w-component) or just 4 values linked together
909 *********************************************************************************************************************/
910#pragma pack(push)
911#pragma pack(1)
912 //__declspec(align(alignment))
913 template <typename T>
914 class vec4
915 {
916 static_assert(ValidMathType<T>, "Invalid base type!");
917
918 public:
919 vec4() noexcept : vec4( T{0} ) {}
920
921 vec4( T xIn, T yIn, T zIn, T wIn ) noexcept : x( xIn ), y( yIn ), z( zIn ), w( wIn )
922 {
923 }
924 vec4( T xIn, T yIn, T zIn ) noexcept : x( xIn ), y( yIn ), z( zIn ), w( T{1} )
925 {
926 }
927 template<typename U> requires std::is_pod_v<U>
928 vec4( U xIn, U yIn, U zIn, U wIn ) noexcept : x( static_cast<T>(xIn) ), y( static_cast<T>(yIn) ), z( static_cast<T>(zIn) ), w( static_cast<T>(wIn) )
929 {
930 }
931 template<typename U> requires std::is_pod_v<U>
932 vec4( U xIn, U yIn, U zIn ) noexcept : vec4( xIn, yIn, zIn, T{1} )
933 {
934 }
935 vec4( __m128 reg ) noexcept : _reg( reg )
936 {
937 }
938 vec4( const SimdVector<T>& reg ) noexcept : _reg( reg )
939 {
940 }
941 vec4( T value ) noexcept : vec4( value, value, value, value )
942 {
943 }
944 template<typename U> requires std::is_pod_v<U>
945 vec4( U value ) noexcept : vec4( value, value, value, value )
946 {
947 }
948 vec4( const T* v ) noexcept : vec4( v[0], v[1], v[2], v[3] )
949 {
950 }
951 vec4( const vec2<T> v ) noexcept : vec4( v, T{0} )
952 {
953 }
954 vec4( const vec2<T> v, T zIn ) noexcept : vec4( v, zIn, T{1} )
955 {
956 }
957 vec4( const vec2<T> v, T zIn, T wIn ) noexcept : vec4( v.x, v.y, zIn, wIn )
958 {
959 }
960 vec4( const vec3<T>& v ) noexcept : vec4( v, T{1} )
961 {
962 }
963 vec4( const vec3<T>& v, T wIn ) noexcept : vec4( v.x, v.y, v.z, wIn )
964 {
965 }
966 template<typename U> requires std::is_pod_v<U>
967 vec4( const vec2<U> v ) noexcept : vec4( v.x, v.y, U{0}, U{0} )
968 {
969 }
970 template<typename U> requires std::is_pod_v<U>
971 vec4( const vec3<U>& v ) noexcept : vec4( v.x, v.y, v.z, U{0} )
972 {
973 }
974 template<typename U> requires std::is_pod_v<U>
975 vec4( const vec4<U>& v ) noexcept : vec4( v.x, v.y, v.z, v.w )
976 {
977 }
978
979 [[nodiscard]] bool operator> ( const vec4& v ) const noexcept
980 {
981 return x > v.x && y > v.y && z > v.z && w > v.w;
982 }
983 [[nodiscard]] bool operator< ( const vec4& v ) const noexcept
984 {
985 return x < v.x&& y < v.y&& z < v.z&& w < v.w;
986 }
987 [[nodiscard]] bool operator<=( const vec4& v ) const noexcept
988 {
989 return *this < v || *this == v;
990 }
991 [[nodiscard]] bool operator>=( const vec4& v ) const noexcept
992 {
993 return *this > v || *this == v;
994 }
995 [[nodiscard]] bool operator==( const vec4& v ) const noexcept
996 {
997 return this->compare( v );
998 }
999 [[nodiscard]] bool operator!=( const vec4& v ) const noexcept
1000 {
1001 return !this->compare( v );
1002 }
1003 template<typename U> requires std::is_pod_v<U>
1004 [[nodiscard]] bool operator!=( const vec4<U>& v ) const noexcept
1005 {
1006 return !this->compare( v );
1007 }
1008 template<typename U> requires std::is_pod_v<U>
1009 [[nodiscard]] bool operator==( const vec4<U>& v ) const noexcept
1010 {
1011 return this->compare( v );
1012 }
1013
1014 template<typename U> requires std::is_pod_v<U>
1015 [[nodiscard]] vec4 operator-( U _f ) const noexcept
1016 {
1017 return vec4( this->x - _f, this->y - _f, this->z - _f, this->w - _f );
1018 }
1019 template<typename U> requires std::is_pod_v<U>
1020 [[nodiscard]] vec4 operator+( U _f ) const noexcept
1021 {
1022 return vec4( this->x + _f, this->y + _f, this->z + _f, this->w + _f );
1023 }
1024 template<typename U> requires std::is_pod_v<U>
1025 [[nodiscard]] vec4 operator*( U _f ) const noexcept
1026 {
1027 return vec4( this->x * _f, this->y * _f, this->z * _f, this->w * _f );
1028 }
1029 template<typename U> requires std::is_pod_v<U>
1030 [[nodiscard]] vec4 operator/( U _f ) const noexcept
1031 {
1032 if ( !IS_ZERO( _f ) )
1033 {
1034 return vec4( static_cast<T>(this->x / _f),
1035 static_cast<T>(this->y / _f),
1036 static_cast<T>(this->z / _f),
1037 static_cast<T>(this->w / _f) );
1038 }
1039
1040 return *this;
1041 }
1042
1043 [[nodiscard]] vec4 operator-() const noexcept
1044 {
1045 return vec4( -x, -y, -z, -w );
1046 }
1047
1048 template<typename U> requires std::is_pod_v<U>
1049 [[nodiscard]] vec4 operator+( const vec4<U>& v ) const noexcept
1050 {
1051 return vec4( this->x + v.x, this->y + v.y, this->z + v.z, this->w + v.w );
1052 }
1053 template<typename U> requires std::is_pod_v<U>
1054 [[nodiscard]] vec4 operator-( const vec4<U>& v ) const noexcept
1055 {
1056 return vec4( this->x - v.x, this->y - v.y, this->z - v.z, this->w - v.w );
1057 }
1058 template<typename U> requires std::is_pod_v<U>
1059 [[nodiscard]] vec4 operator*( const vec4<U>& v ) const noexcept
1060 {
1061 return vec4( this->x * v.x, this->y * v.y, this->z * v.z, this->w * v.w );
1062 }
1063 template<typename U> requires std::is_pod_v<U>
1064 [[nodiscard]] vec4 operator/( const vec4<U>& v ) const noexcept
1065 {
1066 return vec4( IS_ZERO( v.x ) ? this->x : this->x / v.x,
1067 IS_ZERO( v.y ) ? this->y : this->y / v.y,
1068 IS_ZERO( v.z ) ? this->z : this->z / v.z,
1069 IS_ZERO( v.w ) ? this->w : this->w / v.w );
1070 }
1071
1072 template<typename U> requires std::is_pod_v<U>
1073 vec4& operator+=( U _f ) noexcept
1074 {
1075 this->set( *this + _f ); return *this;
1076 }
1077 template<typename U> requires std::is_pod_v<U>
1078 vec4& operator-=( U _f ) noexcept
1079 {
1080 this->set( *this - _f ); return *this;
1081 }
1082 template<typename U> requires std::is_pod_v<U>
1083 vec4& operator*=( U _f ) noexcept
1084 {
1085 this->set( *this * _f ); return *this;
1086 }
1087 template<typename U> requires std::is_pod_v<U>
1088 vec4& operator/=( U _f ) noexcept
1089 {
1090 if ( !IS_ZERO( _f ) )
1091 {
1092 this->set( *this / _f );
1093 } return *this;
1094 }
1095
1096 template<typename U> requires std::is_pod_v<U>
1097 vec4& operator*=( const vec4<U>& v ) noexcept
1098 {
1099 this->set( *this * v ); return *this;
1100 }
1101 template<typename U> requires std::is_pod_v<U>
1102 vec4& operator/=( const vec4<U>& v ) noexcept
1103 {
1104 this->set( *this / v ); return *this;
1105 }
1106 template<typename U> requires std::is_pod_v<U>
1107 vec4& operator+=( const vec4<U>& v ) noexcept
1108 {
1109 this->set( *this + v ); return *this;
1110 }
1111 template<typename U> requires std::is_pod_v<U>
1112 vec4& operator-=( const vec4<U>& v ) noexcept
1113 {
1114 this->set( *this - v ); return *this;
1115 }
1116
1117 [[nodiscard]] operator T* () noexcept
1118 {
1119 return this->_v;
1120 }
1121 [[nodiscard]] operator const T* () const noexcept
1122 {
1123 return this->_v;
1124 }
1125
1126 template<typename U> requires std::is_unsigned_v<U>
1127 [[nodiscard]] T& operator[]( U i ) noexcept
1128 {
1129 return this->_v[i];
1130 }
1131 template<typename U> requires std::is_unsigned_v<U>
1132 [[nodiscard]] const T& operator[]( U _i ) const noexcept
1133 {
1134 return this->_v[_i];
1135 }
1136
1138 [[nodiscard]] vec2<T> rb() const noexcept
1139 {
1140 return vec2<T>( this->r, this->b );
1141 }
1142 [[nodiscard]] vec2<T> xz() const noexcept
1143 {
1144 return this->rb();
1145 }
1146 [[nodiscard]] vec2<T> ra() const noexcept
1147 {
1148 return vec2<T>( this->r, this->a );
1149 }
1150 [[nodiscard]] vec2<T> xw() const noexcept
1151 {
1152 return this->ra();
1153 }
1154 [[nodiscard]] vec2<T> ga() const noexcept
1155 {
1156 return vec2<T>( this->g, this->a );
1157 }
1158 [[nodiscard]] vec2<T> yw() const noexcept
1159 {
1160 return this->ga();
1161 }
1162 [[nodiscard]] vec3<T> bgr() const noexcept
1163 {
1164 return vec3<T>( this->b, this->g, this->r );
1165 }
1166 [[nodiscard]] vec3<T> zyx() const noexcept
1167 {
1168 return this->bgr();
1169 }
1170 [[nodiscard]] vec3<T> rga() const noexcept
1171 {
1172 return vec3<T>( this->r, this->g, this->a );
1173 }
1174 [[nodiscard]] vec3<T> xyw() const noexcept
1175 {
1176 return this->rga();
1177 }
1178
1179 void rb( const vec2<T> rb ) noexcept
1180 {
1181 this->xz( rb );
1182 }
1183 void xz( const vec2<T> xz ) noexcept
1184 {
1185 this->xz( xz.x, xz.y );
1186 }
1187 void xz( T xIn, T zIn ) noexcept
1188 {
1189 this->x = xIn; this->z = zIn;
1190 }
1191 void ra( const vec2<T> ra ) noexcept
1192 {
1193 this->xw( ra );
1194 }
1195 void xw( const vec2<T> xw ) noexcept
1196 {
1197 this->xw( xw.x, xw.y );
1198 }
1199 void xw( T xIn, T wIn ) noexcept
1200 {
1201 this->x = xIn; this->w = wIn;
1202 }
1203 void ga( const vec2<T> ga ) noexcept
1204 {
1205 this->yw( ga );
1206 }
1207 void yw( const vec2<T> yw ) noexcept
1208 {
1209 this->yw( yw.x, yw.y );
1210 }
1211 void yw( T yIn, T wIn ) noexcept
1212 {
1213 this->y = yIn; this->w = wIn;
1214 }
1215 void bgr( const vec3<T>& bgr ) noexcept
1216 {
1217 this->zyx( bgr );
1218 }
1219 void zyx( const vec3<T>& zyx ) noexcept
1220 {
1221 this->z = zyx.x; this->y = zyx.y; this->x = zyx.z;
1222 }
1223 void rga( const vec3<T>& rga ) noexcept
1224 {
1225 this->xyw( rga );
1226 }
1227 void xyw( const vec3<T>& xyw ) noexcept
1228 {
1229 this->xyw( xyw.x, xyw.y, xyw.z );
1230 }
1231 void xyw( T xIn, T yIn, T wIn ) noexcept
1232 {
1233 xy( xIn, yIn ); this->w = wIn;
1234 }
1235 void xzw( T xIn, T zIn, T wIn ) noexcept
1236 {
1237 xz( xIn, zIn ); this->w = wIn;
1238 }
1239
1241 void set( const T* v ) noexcept
1242 {
1243 std::memcpy( _v, v, 4 * sizeof( T ) );
1244 }
1246 void set( T value ) noexcept
1247 {
1248 _reg = SimdVector<T>( value );
1249 }
1251 void set( T xIn, T yIn, T zIn, T wIn ) noexcept
1252 {
1253 _reg = SimdVector<T>( xIn, yIn, zIn, wIn );
1254 }
1255 template <typename U> requires std::is_pod_v<U>
1256 void set( U xIn, U yIn, U zIn, U wIn ) noexcept
1257 {
1258 set( static_cast<T>(xIn), static_cast<T>(yIn), static_cast<T>(zIn), static_cast<T>(wIn) );
1259 }
1261 void set( const vec4& v ) noexcept
1262 {
1263 _reg = v._reg;
1264 }
1266 void set( const vec3<T>& v ) noexcept
1267 {
1268 std::memcpy( &_v[0], &v._v[0], 3 * sizeof( T ) );
1269 }
1271 void set( const vec3<T>& v, T wIn ) noexcept
1272 {
1273 std::memcpy( &_v[0], &v._v[0], 3 * sizeof( T ) ); w = wIn;
1274 }
1276 void set( const vec2<T> v ) noexcept
1277 {
1278 std::memcpy( &_v[0], &v._v[0], 2 * sizeof( T ) );
1279 }
1281 void set( const vec2<T> v1, const vec2<T> v2 ) noexcept
1282 {
1283 this->set( v1.x, v1.y, v2.x, v2.y );
1284 }
1286 void reset() noexcept
1287 {
1288 this->set( T{0} );
1289 }
1291 template<typename U> requires std::is_pod_v<U>
1292 [[nodiscard]] bool compare( const vec4<U>& v ) const noexcept;
1294 template<typename U> requires std::is_pod_v<U>
1295 [[nodiscard]] bool compare( const vec4<U>& v, U epsi ) const noexcept;
1297 void swap( vec4* iv ) noexcept;
1299 void swap( vec4& iv ) noexcept;
1301 vec4& normalize() noexcept;
1303 template<typename U> requires std::is_pod_v<U>
1304 [[nodiscard]] bool isPerpendicular( const vec4<U>& other, F32 epsilon = EPSILON_F32 ) const noexcept;
1306 [[nodiscard]] T minComponent() const noexcept;
1308 [[nodiscard]] T maxComponent() const noexcept;
1310 [[nodiscard]] T dot( const vec4& v ) const noexcept;
1312 [[nodiscard]] T length() const noexcept
1313 {
1314 return Divide::Sqrt( lengthSquared() );
1315 }
1317 [[nodiscard]] T lengthSquared() const noexcept;
1319 [[nodiscard]] vec4 projectToNorm( const vec4<T>& direction );
1321 void round() noexcept;
1323 void lerp( const vec4& v, T factor ) noexcept;
1325 void lerp( const vec4& v, const vec4& factor ) noexcept;
1326 union
1327 {
1328 struct
1329 {
1330 T x, y, z, w;
1331 };
1332 struct
1333 {
1334 T s, t, p, q;
1335 };
1336 struct
1337 {
1338 T r, g, b, a;
1339 };
1340 struct
1341 {
1343 };
1344 struct
1345 {
1347 };
1348 struct
1349 {
1351 };
1352 struct
1353 {
1355 };
1356 struct
1357 {
1359 };
1360 struct
1361 {
1363 };
1364 struct
1365 {
1367 };
1368 struct
1369 {
1371 };
1372 struct
1373 {
1375 };
1376 struct
1377 {
1379 };
1380 struct
1381 {
1383 };
1384 struct
1385 {
1387 };
1388 struct
1389 {
1391 };
1392 struct
1393 {
1395 };
1396
1397 T _v[4] = {T{0}, T{0}, T{0}, T{1}};
1399 };
1400 };
1401#pragma pack(pop)
1402
1404 template <typename T>
1405 [[nodiscard]] vec4<T> Lerp( const vec4<T>& u, const vec4<T>& v, T factor ) noexcept;
1407 template <typename T>
1408 [[nodiscard]] vec4<T> Lerp( const vec4<T>& u, const vec4<T>& v, const vec4<T>& factor ) noexcept;
1409 template <typename T>
1410 [[nodiscard]] vec4<T> Abs( const vec4<T>& vector ) noexcept;
1412 template <typename T>
1413 [[nodiscard]] vec4<T> Min( const vec4<T>& v1, const vec4<T>& v2 ) noexcept;
1414 template <typename T>
1415 [[nodiscard]] vec4<T> Max( const vec4<T>& v1, const vec4<T>& v2 ) noexcept;
1416 template <typename T>
1417 [[nodiscard]] vec4<T> Normalize( vec4<T>& vector ) noexcept;
1418 template <typename T>
1419 [[nodiscard]] vec4<T> Normalized( const vec4<T>& vector ) noexcept;
1421 template <typename T>
1422 [[nodiscard]] vec4<T> operator*( T fl, const vec4<T>& v ) noexcept;
1423 template <typename T>
1424 void OrthoNormalize( vec4<T>& n, vec4<T>& u );
1425 template <typename T>
1426 void OrthoNormalize( vec4<T>& v1, vec4<T>& v2, vec4<T>& v3 );
1427 template<typename T>
1428 [[nodiscard]] vec4<T> Perpendicular( const vec4<T>& vec, const vec4<T>& hint1, const vec4<T>& hint2 ) noexcept;
1429 template <typename T>
1430 [[nodiscard]] vec4<T> Clamped( const vec4<T>& v, const vec4<T>& min, const vec4<T>& max ) noexcept;
1431
1433 static const vec2<F32> VECTOR2_ZERO{ 0.0f };
1434 static const vec3<F32> VECTOR3_ZERO{ 0.0f };
1435 static const vec4<F32> VECTOR4_ZERO{ 0.0f };
1436 static const vec2<F32> VECTOR2_UNIT{ 1.0f };
1437 static const vec3<F32> VECTOR3_UNIT{ 1.0f };
1438 static const vec4<F32> VECTOR4_UNIT{ 1.0f };
1439 static const vec3<F32> WORLD_X_AXIS{ 1.0f, 0.0f, 0.0f };
1440 static const vec3<F32> WORLD_Y_AXIS{ 0.0f, 1.0f, 0.0f };
1441 static const vec3<F32> WORLD_Z_AXIS{ 0.0f, 0.0f, 1.0f };
1442 static const vec3<F32> WORLD_X_NEG_AXIS{ -1.0f, 0.0f, 0.0f };
1443 static const vec3<F32> WORLD_Y_NEG_AXIS{ 0.0f, -1.0f, 0.0f };
1444 static const vec3<F32> WORLD_Z_NEG_AXIS{ 0.0f, 0.0f, -1.0f };
1445 static const vec3<F32> DEFAULT_GRAVITY{ 0.0f, -9.81f, 0.0f };
1446
1447 static const vec2<I32> iVECTOR2_ZERO{ 0 };
1448 static const vec3<I32> iVECTOR3_ZERO{ 0 };
1449 static const vec4<I32> iVECTOR4_ZERO{ 0 };
1450 static const vec3<I32> iWORLD_X_AXIS{ 1, 0, 0 };
1451 static const vec3<I32> iWORLD_Y_AXIS{ 0, 1, 0 };
1452 static const vec3<I32> iWORLD_Z_AXIS{ 0, 0, 1 };
1453 static const vec3<I32> iWORLD_X_NEG_AXIS{ -1, 0, 0 };
1454 static const vec3<I32> iWORLD_Y_NEG_AXIS{ 0, -1, 0 };
1455 static const vec3<I32> iWORLD_Z_NEG_AXIS{ 0, 0, -1 };
1456
1457 //ToDo: Move this to its own file
1458 template<typename T>
1459 class Rect : public vec4<T>
1460 {
1461 public:
1462 using vec4<T>::vec4;
1463
1464 template<typename U> requires std::is_pod_v<U>
1465 [[nodiscard]] bool contains( U xIn, U yIn ) const noexcept
1466 {
1467 return COORDS_IN_RECT( static_cast<T>(xIn), static_cast<T>(yIn), *this );
1468 }
1469 [[nodiscard]] bool contains( const vec2<T> coords ) const noexcept
1470 {
1471 return contains( coords.x, coords.y );
1472 }
1473 [[nodiscard]] bool contains( T xIn, T yIn ) const noexcept
1474 {
1475 return COORDS_IN_RECT( xIn, yIn, *this );
1476 }
1477 [[nodiscard]] vec2<T> clamp( T xIn, T yIn ) const noexcept
1478 {
1479 CLAMP_IN_RECT( xIn, yIn, *this ); return vec2<T>( xIn, yIn );
1480 }
1481 [[nodiscard]] vec2<T> clamp( const vec2<T> coords ) const noexcept
1482 {
1483 return clamp( coords.x, coords.y );
1484 }
1485 };
1486
1487 static const Rect<I32> UNIT_VIEWPORT{ 0, 0, 1, 1 };
1488 static const Rect<I32> UNIT_RECT{ -1, 1, -1, 1 };
1489
1490} // namespace Divide
1491
1492// Inline definitions
1493#include "MathVectors.inl"
1494
1495#endif //DVD_MATH_VECTORS_H_
bool contains(U xIn, U yIn) const noexcept
Definition: MathVectors.h:1465
bool contains(const vec2< T > coords) const noexcept
Definition: MathVectors.h:1469
vec2< T > clamp(const vec2< T > coords) const noexcept
Definition: MathVectors.h:1481
bool contains(T xIn, T yIn) const noexcept
Definition: MathVectors.h:1473
vec2< T > clamp(T xIn, T yIn) const noexcept
Definition: MathVectors.h:1477
SimdVector(F32 reg[4]) noexcept
Definition: MathVectors.h:105
SimdVector(F32 reg) noexcept
Definition: MathVectors.h:102
SimdVector(const __m128 reg) noexcept
Definition: MathVectors.h:108
bool operator!=(const SimdVector &other) const noexcept
Definition: MathVectors.h:117
SimdVector(F32 reg0, F32 reg1, F32 reg2, F32 reg3) noexcept
Definition: MathVectors.h:99
bool operator==(const SimdVector &other) const noexcept
Definition: MathVectors.h:112
SimdVector(T val) noexcept
Definition: MathVectors.h:80
bool operator==(const SimdVector &) const =default
SimdVector(T reg[4]) noexcept
Definition: MathVectors.h:83
SimdVector() noexcept
Definition: MathVectors.h:74
SimdVector(T reg0, T reg1, T reg2, T reg3) noexcept
Definition: MathVectors.h:77
void set(const vec2 &v) noexcept
set the 2 components of the vector using a source vector
Definition: MathVectors.h:355
vec2 & operator+=(const vec2< U > v) noexcept
Definition: MathVectors.h:283
bool compare(vec2< U > v) const noexcept
compare 2 vectors
void lerp(const vec2 &v, T factor) noexcept
lerp between this and the specified vector by the specified amount
vec2 operator+(const vec2< U > v) const noexcept
Definition: MathVectors.h:236
T minComponent() const noexcept
get the smallest value of X or Y
void set(const vec4< T > &v) noexcept
set the 2 components of the vector using the first 2 components of the source vector
Definition: MathVectors.h:365
void swap(vec2 *iv) noexcept
swap the components of this vector with that of the specified one
Definition: MathVectors.h:325
vec2 closestPointOnSegment(const vec2 &vA, const vec2 &vB)
return the closest point on the line segment defined between the 2 points (A, B) and this vector
bool operator<=(const vec2 &v) const noexcept
Definition: MathVectors.h:184
vec2 operator+(U _f) const noexcept
Definition: MathVectors.h:217
vec2 & normalize() noexcept
convert the vector to unit length
T distance(const vec2 &v) const
compute the vector's distance to another specified vector
T angle() const
return the angle defined by the 2 components
Definition: MathVectors.h:381
vec2(const vec4< T > &_v) noexcept
Definition: MathVectors.h:160
vec2 & operator-=(const vec2< U > v) noexcept
Definition: MathVectors.h:288
void set(T value) noexcept
set the 2 components of the vector manually
Definition: MathVectors.h:340
vec2 & operator/=(U _f) noexcept
Definition: MathVectors.h:272
vec2 & operator+=(U _f) noexcept
Definition: MathVectors.h:257
vec2(const T *_v) noexcept
Definition: MathVectors.h:154
T & operator[](U i) noexcept
Definition: MathVectors.h:299
bool operator==(const vec2< U > &v) const noexcept
Definition: MathVectors.h:206
vec2 operator*(const vec2< U > v) const noexcept
Definition: MathVectors.h:246
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:335
vec2(const vec2< U > &v) noexcept
Definition: MathVectors.h:164
bool operator>(const vec2 &v) const noexcept
Definition: MathVectors.h:176
vec2 & operator*=(U _f) noexcept
Definition: MathVectors.h:267
vec2 & operator/=(const vec2< U > v) noexcept
Definition: MathVectors.h:293
void set(U xIn, U yIn) noexcept
Definition: MathVectors.h:350
void reset()
set the 2 components of the vector back to 0
Definition: MathVectors.h:370
vec2(T value) noexcept
Definition: MathVectors.h:136
vec2(const vec3< T > &_v) noexcept
Definition: MathVectors.h:157
vec2 & operator-=(U _f) noexcept
Definition: MathVectors.h:262
vec2 operator/(U _i) const noexcept
Definition: MathVectors.h:227
T maxComponent() const noexcept
get the largest value of X or Y
T distanceSquared(const vec2 &v) const noexcept
compute the vector's squared distance to another specified vector
bool operator<(const vec2 &v) const noexcept
Definition: MathVectors.h:180
vec2 closestPointOnLine(const vec2 &vA, const vec2 &vB)
return the closest point on the line defined by the 2 points (A, B) and this vector
void set(T xIn, T yIn) noexcept
set the 2 components of the vector manually
Definition: MathVectors.h:345
vec2(U value) noexcept
Definition: MathVectors.h:140
vec2 operator*(U _f) const noexcept
Definition: MathVectors.h:222
vec2 operator-() const noexcept
Definition: MathVectors.h:251
vec2 operator-(const vec2< U > v) const noexcept
Definition: MathVectors.h:241
vec2(const vec3< U > &v) noexcept
Definition: MathVectors.h:168
const T & operator[](U i) const noexcept
Definition: MathVectors.h:304
T lengthSquared() const noexcept
return the squared distance of the vector
void round()
round both values
bool operator!=(const vec2 &v) const noexcept
Definition: MathVectors.h:196
vec2 operator-(U _f) const noexcept
Definition: MathVectors.h:212
void get(T *v) const
export the vector's components in the first 2 positions of the specified array
vec2(const vec4< U > &v) noexcept
Definition: MathVectors.h:172
vec2(U xIn, U yIn) noexcept
Definition: MathVectors.h:147
T length() const noexcept
return the vector's length
Definition: MathVectors.h:375
void set(const vec3< T > &v) noexcept
set the 2 components of the vector using the first 2 components of the source vector
Definition: MathVectors.h:360
vec2() noexcept
Definition: MathVectors.h:134
vec2(T xIn, T yIn) noexcept
Definition: MathVectors.h:143
T projectionOnLine(const vec2 &vA, const vec2 &vB) const
project this vector on the line defined by the 2 points(A, B)
void swap(vec2 &iv) noexcept
swap the components of this vector with that of the specified one
Definition: MathVectors.h:330
bool operator==(const vec2 &v) const noexcept
Definition: MathVectors.h:192
T dot(const vec2 &v) const noexcept
calculate the dot product between this vector and the specified one
bool operator!=(const vec2< U > &v) const noexcept
Definition: MathVectors.h:201
T angle(const vec2 &v) const
return the angle defined by the 2 components
Definition: MathVectors.h:386
vec2 & operator*=(const vec2< U > v) noexcept
Definition: MathVectors.h:278
vec2 operator/(const vec2 &v) const noexcept
Definition: MathVectors.h:309
bool operator>=(const vec2 &v) const noexcept
Definition: MathVectors.h:188
vec2(U xIn, V yIn) noexcept
Definition: MathVectors.h:151
bool operator==(const vec3< U > &v) const noexcept
Definition: MathVectors.h:567
T angle(vec3 &v) const
returns the angle in radians between '*this' and 'v'
vec2< T > xz() const noexcept
Definition: MathVectors.h:692
T dot(const vec3 &v) const noexcept
calculate the dot product between this vector and the specified one
vec3 & operator-=(U _f) noexcept
Definition: MathVectors.h:623
void set(const vec4< T > &v) noexcept
set the 3 components of the vector using the first 3 components of the source vector
Definition: MathVectors.h:737
vec3 & normalize() noexcept
transform the vector to unit length
bool operator>(const vec3 &v) const noexcept
Definition: MathVectors.h:537
vec3(U xIn, U yIn, U zIn) noexcept
Definition: MathVectors.h:497
void lerp(const vec3 &v, T factor) noexcept
lerp between this and the specified vector by the specified amount
vec3(U xIn, V yIn, V zIn) noexcept
Definition: MathVectors.h:505
T length() const noexcept
return the vector's length
Definition: MathVectors.h:747
vec3(const vec2< T > v, T zIn) noexcept
Definition: MathVectors.h:518
T maxComponent() const noexcept
get the largest value of X,Y or Z
bool operator!=(const vec3< U > &v) const noexcept
Definition: MathVectors.h:562
vec3 & operator/=(const vec3< U > &v) noexcept
Definition: MathVectors.h:654
const T & operator[](const U i) const noexcept
Definition: MathVectors.h:665
vec3 & operator-=(const vec3< U > &v) noexcept
Definition: MathVectors.h:649
bool operator==(const vec3 &v) const noexcept
Definition: MathVectors.h:557
bool operator<(const vec3 &v) const noexcept
Definition: MathVectors.h:541
bool isZeroLength() const noexcept
return true if length is zero
Definition: MathVectors.h:752
void reset() noexcept
set all the components back to 0
Definition: MathVectors.h:742
T projectionOnLine(const vec3 &vA, const vec3 &vB) const
project this vector on the line defined by the 2 points(A, B)
vec3 closestPointOnLine(const vec3 &vA, const vec3 &vB)
void swap(vec3 &iv) noexcept
swap the components of this vector with that of the specified one
bool compare(const vec3< U > &v, U epsi) const noexcept
compare 2 vectors within the specified tolerance
vec3 operator+(const vec3< U > &v) const noexcept
Definition: MathVectors.h:602
vec3(U xIn, V yIn, W zIn) noexcept
Definition: MathVectors.h:509
T minComponent() const noexcept
get the smallest value of X,Y or Z
vec3(const vec2< T > v) noexcept
Definition: MathVectors.h:515
void rotateX(D64 radians)
rotate this vector on the X axis
T lengthSquared() const noexcept
return the squared distance of the vector
vec3 operator/(U _f) const noexcept
Definition: MathVectors.h:588
vec3 operator-(const vec3< U > &v) const noexcept
Definition: MathVectors.h:607
vec3(U value) noexcept
Definition: MathVectors.h:490
vec3 operator/(const vec3< U > &v) const noexcept
Definition: MathVectors.h:671
T & operator[](const U i) noexcept
Definition: MathVectors.h:660
vec2< T > xy
Definition: MathVectors.h:852
vec3(const vec4< T > &v) noexcept
Definition: MathVectors.h:521
vec3 direction(const vec3 &u) const noexcept
get the direction vector to the specified point
void cross(const vec3 &v1, const vec3 &v2) noexcept
set this vector to be equal to the cross of the 2 specified vectors
vec2< T > rg
Definition: MathVectors.h:856
vec3 closestPointOnSegment(const vec3 &vA, const vec3 &vB)
bool operator<=(const vec3 &v) const noexcept
Definition: MathVectors.h:545
vec3 operator-(U _f) const noexcept
Definition: MathVectors.h:578
void rotateZ(D64 radians)
rotate this vector on the Z axis
void get(T *v) const noexcept
vec3(U xIn, U yIn, V zIn) noexcept
Definition: MathVectors.h:501
bool isUniform(F32 tolerance=0.0001f) const noexcept
uniform vector: x = y = z
void xz(const vec2< T > xz) noexcept
Definition: MathVectors.h:701
vec3(const vec2< U > v) noexcept
Definition: MathVectors.h:525
void set(T value) noexcept
set the 3 components of the vector manually
Definition: MathVectors.h:712
void set(U xIn, U yIn, U zIn) noexcept
Definition: MathVectors.h:722
vec3(const T *v) noexcept
Definition: MathVectors.h:512
bool operator!=(const vec3 &v) const noexcept
Definition: MathVectors.h:553
void rotateY(D64 radians)
rotate this vector on the Y axis
vec3 & operator+=(const vec3< U > &v) noexcept
Definition: MathVectors.h:644
vec3 operator+(U _f) const noexcept
Definition: MathVectors.h:573
vec3 & operator/=(U _f) noexcept
Definition: MathVectors.h:633
vec3 & operator*=(U _f) noexcept
Definition: MathVectors.h:628
void rb(const vec2< T > rb) noexcept
Definition: MathVectors.h:697
vec3 & operator*=(const vec3< U > &v) noexcept
Definition: MathVectors.h:639
void set(const T *v) noexcept
set the 3 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:707
vec3 operator*(U _f) const noexcept
Definition: MathVectors.h:583
void set(const vec2< T > v) noexcept
set the 3 components of the vector using a smaller source vector
Definition: MathVectors.h:727
bool operator>=(const vec3 &v) const noexcept
Definition: MathVectors.h:549
vec3(T value) noexcept
Definition: MathVectors.h:486
void set(T xIn, T yIn, T zIn) noexcept
set the 3 components of the vector manually
Definition: MathVectors.h:717
vec3(const vec4< U > &v) noexcept
Definition: MathVectors.h:533
T distanceSquared(const vec3 &v) const noexcept
compute the vector's squared distance to another specified vector
vec3(T xIn, T yIn, T zIn) noexcept
Definition: MathVectors.h:493
vec3 operator-() const noexcept
Definition: MathVectors.h:596
vec3 projectToNorm(const vec3< T > &direction) noexcept
project this vector onto the given direction
vec2< T > rb() const noexcept
GLSL like accessors (const to prevent erroneous usage like .xy() += n)
Definition: MathVectors.h:688
bool compare(const vec3< U > &v) const noexcept
compare 2 vectors
bool isPerpendicular(const vec3< U > &other, F32 epsilon=EPSILON_F32) const noexcept
The current vector is perpendicular to the specified one within epsilon.
vec3() noexcept
Definition: MathVectors.h:484
void set(const vec3 &v) noexcept
set the 3 components of the vector using a source vector
Definition: MathVectors.h:732
T distance(const vec3 &v) const noexcept
compute the vector's distance to another specified vector
vec3 operator*(const vec3< U > &v) const noexcept
Definition: MathVectors.h:612
vec3 & operator+=(U _f) noexcept
Definition: MathVectors.h:618
void round()
round all three values
vec3(const vec3< U > &v) noexcept
Definition: MathVectors.h:529
vec2< T > gb
Definition: MathVectors.h:860
vec4 operator*(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1059
vec4 & operator+=(U _f) noexcept
Definition: MathVectors.h:1073
vec3< T > yzw
Definition: MathVectors.h:1382
vec4(const vec2< U > v) noexcept
Definition: MathVectors.h:967
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:1241
vec4 operator-() const noexcept
Definition: MathVectors.h:1043
vec2< T > xy
Definition: MathVectors.h:1366
vec4 projectToNorm(const vec4< T > &direction)
project this vector onto the given direction
vec2< T > ga() const noexcept
Definition: MathVectors.h:1154
void rb(const vec2< T > rb) noexcept
Definition: MathVectors.h:1179
vec2< T > xw() const noexcept
Definition: MathVectors.h:1150
void yw(T yIn, T wIn) noexcept
Definition: MathVectors.h:1211
vec4 operator+(U _f) const noexcept
Definition: MathVectors.h:1020
void set(const vec3< T > &v) noexcept
set the 4 components of the vector using a smaller source vector
Definition: MathVectors.h:1266
T maxComponent() const noexcept
get the largest value of X,Y,Z or W
vec4 operator-(U _f) const noexcept
Definition: MathVectors.h:1015
vec3< T > rgb
Definition: MathVectors.h:1378
void set(const vec2< T > v) noexcept
set the 4 components of the vector using a smaller source vector
Definition: MathVectors.h:1276
void bgr(const vec3< T > &bgr) noexcept
Definition: MathVectors.h:1215
void xw(const vec2< T > xw) noexcept
Definition: MathVectors.h:1195
void reset() noexcept
set all the components back to 0
Definition: MathVectors.h:1286
vec3< T > xyz
Definition: MathVectors.h:1374
vec4(const vec2< T > v) noexcept
Definition: MathVectors.h:951
void zyx(const vec3< T > &zyx) noexcept
Definition: MathVectors.h:1219
vec2< T > yw() const noexcept
Definition: MathVectors.h:1158
void yw(const vec2< T > yw) noexcept
Definition: MathVectors.h:1207
void xw(T xIn, T wIn) noexcept
Definition: MathVectors.h:1199
vec4(U value) noexcept
Definition: MathVectors.h:945
bool operator<=(const vec4 &v) const noexcept
Definition: MathVectors.h:987
bool operator!=(const vec4 &v) const noexcept
Definition: MathVectors.h:999
bool operator>=(const vec4 &v) const noexcept
Definition: MathVectors.h:991
void xz(T xIn, T zIn) noexcept
Definition: MathVectors.h:1187
T & operator[](U i) noexcept
Definition: MathVectors.h:1127
vec2< T > rb() const noexcept
GLSL like accessors (const to prevent erroneous usage like .xyz() += n)
Definition: MathVectors.h:1138
vec4(const vec2< T > v, T zIn) noexcept
Definition: MathVectors.h:954
vec3< T > xyw() const noexcept
Definition: MathVectors.h:1174
vec4 & operator-=(U _f) noexcept
Definition: MathVectors.h:1078
bool operator>(const vec4 &v) const noexcept
Definition: MathVectors.h:979
vec4 operator*(U _f) const noexcept
Definition: MathVectors.h:1025
vec4 & operator*=(U _f) noexcept
Definition: MathVectors.h:1083
vec4(const vec3< T > &v, T wIn) noexcept
Definition: MathVectors.h:963
T lengthSquared() const noexcept
return the squared distance of the vector
void round() noexcept
round all four values
vec2< T > ra() const noexcept
Definition: MathVectors.h:1146
void swap(vec4 *iv) noexcept
swap the components of this vector with that of the specified one
vec4 & operator/=(U _f) noexcept
Definition: MathVectors.h:1088
vec4 operator/(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1064
vec4(T xIn, T yIn, T zIn) noexcept
Definition: MathVectors.h:924
bool operator==(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1009
vec3< T > gba
Definition: MathVectors.h:1386
vec3< T > rga() const noexcept
Definition: MathVectors.h:1170
vec4() noexcept
Definition: MathVectors.h:919
void xzw(T xIn, T zIn, T wIn) noexcept
Definition: MathVectors.h:1235
T minComponent() const noexcept
get the smallest value of X,Y,Z or W
vec4 & operator/=(const vec4< U > &v) noexcept
Definition: MathVectors.h:1102
const T & operator[](U _i) const noexcept
Definition: MathVectors.h:1132
void set(const vec2< T > v1, const vec2< T > v2) noexcept
set the 4 components of the vector using smaller source vectors
Definition: MathVectors.h:1281
SimdVector< T > _reg
Definition: MathVectors.h:1398
vec4(U xIn, U yIn, U zIn) noexcept
Definition: MathVectors.h:932
vec4(__m128 reg) noexcept
Definition: MathVectors.h:935
void lerp(const vec4 &v, T factor) noexcept
lerp between this and the specified vector by the specified amount
bool compare(const vec4< U > &v) const noexcept
compare 2 vectors
vec2< T > zw
Definition: MathVectors.h:1366
vec4(const vec4< U > &v) noexcept
Definition: MathVectors.h:975
T length() const noexcept
return the vector's length
Definition: MathVectors.h:1312
vec2< T > gb
Definition: MathVectors.h:1394
vec4(T value) noexcept
Definition: MathVectors.h:941
vec2< T > rg
Definition: MathVectors.h:1370
void xyw(T xIn, T yIn, T wIn) noexcept
Definition: MathVectors.h:1231
vec4 operator+(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1049
void xz(const vec2< T > xz) noexcept
Definition: MathVectors.h:1183
vec4 & normalize() noexcept
transform the vector to unit length
vec4(const T *v) noexcept
Definition: MathVectors.h:948
void set(T value) noexcept
set the 4 components of the vector manually
Definition: MathVectors.h:1246
bool isPerpendicular(const vec4< U > &other, F32 epsilon=EPSILON_F32) const noexcept
The current vector is perpendicular to the specified one within epsilon.
void set(U xIn, U yIn, U zIn, U wIn) noexcept
Definition: MathVectors.h:1256
void set(const vec3< T > &v, T wIn) noexcept
set the 4 components of the vector using a smaller source vector
Definition: MathVectors.h:1271
vec4 & operator-=(const vec4< U > &v) noexcept
Definition: MathVectors.h:1112
bool compare(const vec4< U > &v, U epsi) const noexcept
compare 2 vectors within the specified tolerance
vec4(T xIn, T yIn, T zIn, T wIn) noexcept
Definition: MathVectors.h:921
void ga(const vec2< T > ga) noexcept
Definition: MathVectors.h:1203
vec3< T > bgr() const noexcept
Definition: MathVectors.h:1162
void rga(const vec3< T > &rga) noexcept
Definition: MathVectors.h:1223
void set(const vec4 &v) noexcept
set the 4 components of the vector using a source vector
Definition: MathVectors.h:1261
T dot(const vec4 &v) const noexcept
calculate the dot product between this vector and the specified one
vec4 operator-(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1054
vec4 operator/(U _f) const noexcept
Definition: MathVectors.h:1030
vec3< T > zyx() const noexcept
Definition: MathVectors.h:1166
void set(T xIn, T yIn, T zIn, T wIn) noexcept
set the 4 components of the vector manually
Definition: MathVectors.h:1251
vec4 & operator*=(const vec4< U > &v) noexcept
Definition: MathVectors.h:1097
vec2< T > yz
Definition: MathVectors.h:1390
vec4 & operator+=(const vec4< U > &v) noexcept
Definition: MathVectors.h:1107
void ra(const vec2< T > ra) noexcept
Definition: MathVectors.h:1191
vec4(const vec2< T > v, T zIn, T wIn) noexcept
Definition: MathVectors.h:957
vec2< T > xz() const noexcept
Definition: MathVectors.h:1142
vec4(const vec3< T > &v) noexcept
Definition: MathVectors.h:960
vec4(U xIn, U yIn, U zIn, U wIn) noexcept
Definition: MathVectors.h:928
bool operator<(const vec4 &v) const noexcept
Definition: MathVectors.h:983
vec4(const vec3< U > &v) noexcept
Definition: MathVectors.h:971
bool operator!=(const vec4< U > &v) const noexcept
Definition: MathVectors.h:1004
bool operator==(const vec4 &v) const noexcept
Definition: MathVectors.h:995
vec4(const SimdVector< T > &reg) noexcept
Definition: MathVectors.h:938
vec2< T > ba
Definition: MathVectors.h:1370
void xyw(const vec3< T > &xyw) noexcept
Definition: MathVectors.h:1227
__m128 SimpleDot(__m128 a, __m128 b) noexcept
Definition: MathVectors.inl:68
__m128 DotSimd(const __m128 &a, const __m128 &b) noexcept
Definition: MathVectors.inl:59
bool Fneq128(__m128 const &a, __m128 const &b) noexcept
Definition: MathVectors.inl:40
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
static const vec3< I32 > iWORLD_Z_NEG_AXIS
Definition: MathVectors.h:1455
vec2< T > Normalized(vec2< T > vector) noexcept
Definition: MathVectors.inl:98
vec3< T > Abs(const vec3< T > &vector) noexcept
static const vec3< I32 > iWORLD_Z_AXIS
Definition: MathVectors.h:1452
static const vec3< I32 > iVECTOR3_ZERO
Definition: MathVectors.h:1448
bool IS_ZERO(const T X) noexcept
static const Rect< I32 > UNIT_RECT
Definition: MathVectors.h:1488
T Lerp(T v1, T v2, U t) noexcept
Definition: MathHelper.inl:240
static const vec2< F32 > VECTOR2_UNIT
Definition: MathVectors.h:1436
vec2< T > operator*(T fl, vec2< T > v) noexcept
multiply a vector by a value
static const vec3< I32 > iWORLD_Y_AXIS
Definition: MathVectors.h:1451
static const vec2< F32 > VECTOR2_ZERO
Quaternion multiplications require these to be floats.
Definition: MathVectors.h:1433
static const vec3< F32 > WORLD_X_NEG_AXIS
Definition: MathVectors.h:1442
T Sqrt(T input) noexcept
Definition: MathHelper.inl:252
static const vec3< F32 > WORLD_X_AXIS
Definition: MathVectors.h:1439
vec3< T > Min(const vec3< T > &v1, const vec3< T > &v2) noexcept
static const vec3< I32 > iWORLD_X_AXIS
Definition: MathVectors.h:1450
static const vec3< F32 > WORLD_Y_NEG_AXIS
Definition: MathVectors.h:1443
static const vec3< F32 > WORLD_Z_AXIS
Definition: MathVectors.h:1441
void CLAMP_IN_RECT(T &inout_x, T &inout_y, T rect_x, T rect_y, T rect_z, T rect_w) noexcept
Definition: MathHelper.inl:162
vec2< T > Inverse(vec2< T > v) noexcept
Definition: MathVectors.inl:86
vec3< T > Perpendicular(const vec3< T > &v) noexcept
static const vec4< I32 > iVECTOR4_ZERO
Definition: MathVectors.h:1449
static const vec3< I32 > iWORLD_Y_NEG_AXIS
Definition: MathVectors.h:1454
T Dot(vec2< T > a, vec2< T > b) noexcept
general vec2 dot product
constexpr F32 EPSILON_F32
eastl::vector< Type > vector
Definition: Vector.h:42
vec3< T > AreOrthogonal(const vec3< T > &v1, const vec3< T > &v2) noexcept
vec3< T > Max(const vec3< T > &v1, const vec3< T > &v2) noexcept
vec2< T > Normalize(vec2< T > &vector) noexcept
static const vec3< F32 > VECTOR3_UNIT
Definition: MathVectors.h:1437
void OrthoNormalize(vec2< T > &n, vec2< T > &u) noexcept
static const vec4< F32 > VECTOR4_UNIT
Definition: MathVectors.h:1438
static const vec3< F32 > DEFAULT_GRAVITY
Definition: MathVectors.h:1445
static const vec3< F32 > WORLD_Z_NEG_AXIS
Definition: MathVectors.h:1444
vec2< T > Cross(vec2< T > v1, vec2< T > v2) noexcept
general vec2 cross function
Definition: MathVectors.inl:80
double D64
static const vec2< I32 > iVECTOR2_ZERO
Definition: MathVectors.h:1447
bool COORDS_IN_RECT(T input_x, T input_y, T rect_x, T rect_y, T rect_z, T rect_w) noexcept
Definition: MathHelper.inl:181
static const vec3< I32 > iWORLD_X_NEG_AXIS
Definition: MathVectors.h:1453
vec3< T > ProjectToNorm(const vec3< T > &in, const vec3< T > &direction)
vec2< T > Clamped(vec2< T > v, vec2< T > min, vec2< T > max) noexcept
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
static const vec4< F32 > VECTOR4_ZERO
Definition: MathVectors.h:1435
static const vec3< F32 > WORLD_Y_AXIS
Definition: MathVectors.h:1440
static const Rect< I32 > UNIT_VIEWPORT
Definition: MathVectors.h:1487