OpenBarnyard
 
Loading...
Searching...
No Matches
TVector2.h
Go to the documentation of this file.
1#pragma once
2
4
6{
7public:
8 constexpr TVector2() = default;
9 constexpr TVector2( TFLOAT x, TFLOAT y ) { Set( x, y ); }
10 constexpr TVector2( TFLOAT coords[ 2 ] ) { Set( coords[ 0 ], coords[ 1 ] ); }
11 constexpr TVector2( const TVector2& other ) { Set( other ); }
12
13 constexpr void Set( TFLOAT x, TFLOAT y )
14 {
15 TVector2::x = x;
16 TVector2::y = y;
17 }
18
19 constexpr void Set( TFLOAT coords[ 2 ] )
20 {
21 TVector2::x = coords[ 0 ];
22 TVector2::y = coords[ 1 ];
23 }
24
25 constexpr void Set( const TVector2& other )
26 {
27 TVector2::x = other.x;
28 TVector2::y = other.y;
29 }
30
31 constexpr void Add( const TVector2& vec )
32 {
33 x += vec.x;
34 y += vec.y;
35 }
36
37 constexpr void Add( const TVector2& a, const TVector2& b )
38 {
39 Set( a + b );
40 }
41
42 constexpr void Divide( const TVector2& vec )
43 {
44 x /= vec.x;
45 y /= vec.y;
46 }
47
48 constexpr void Divide( TFLOAT scalar )
49 {
50 TFLOAT ratio = 1.0f / scalar;
51 x *= ratio;
52 y *= ratio;
53 }
54
55 constexpr void Divide( const TVector2& vec1, const TVector2& vec2 )
56 {
57 Set( vec1 / vec2 );
58 }
59
60 constexpr void Divide( const TVector2& vec, TFLOAT scalar )
61 {
62 Set( vec );
63 Divide( scalar );
64 }
65
66 constexpr void Multiply( const TVector2& vec )
67 {
68 x *= vec.x;
69 y *= vec.y;
70 }
71
72 constexpr void Multiply( TFLOAT scalar )
73 {
74 x *= scalar;
75 y *= scalar;
76 }
77
78 constexpr void Multiply( const TVector2& vec1, const TVector2& vec2 )
79 {
80 Set( vec1 * vec2 );
81 }
82
83 constexpr void Multiply( const TVector2& vec, TFLOAT scalar )
84 {
85 Set( vec );
86 Multiply( scalar );
87 }
88
89 constexpr void Negate()
90 {
91 Set( -x, -y );
92 }
93
94 // $Barnyard: FUNCTION 006cce70
95 void Normalize()
96 {
97 if ( MagnitudeSq() != 0.0f )
98 {
99 TFLOAT magnitude = TMath::OneOverSqrt( MagnitudeSq() );
100 Set( x * magnitude, y * magnitude );
101 }
102 else
103 {
104 Set( 1.0f, 0.0f );
105 }
106 }
107
108 void Abs( const TVector2& vec3 ) { Set( TMath::Abs( vec3.x ), TMath::Abs( vec3.y ) ); }
109 void Abs() { Set( TMath::Abs( x ), TMath::Abs( y ) ); }
110
111 // $Barnyard: FUNCTION 006ccdf0
112 TFLOAT Magnitude() const { return TMath::Sqrt( x * x + y * y ); }
113 constexpr TFLOAT MagnitudeSq() const { return x * x + y * y; }
114
115 TBOOL IsEqual( const TVector2& vec ) { return TMath::Abs( x - vec.x ) < 0.00001f && TMath::Abs( y - vec.y ) < 0.00001f; }
116
117 constexpr TVector2 operator+( const TVector2& other ) const { return { x + other.x, y + other.y }; }
118 constexpr TVector2 operator-( const TVector2& other ) const { return { x - other.x, y - other.y }; }
119 constexpr TVector2 operator*( const TVector2& other ) const { return { x * other.x, y * other.y }; }
120 constexpr TVector2 operator/( const TVector2& other ) const { return { x / other.x, y / other.y }; }
121
122 constexpr void operator=( const TVector2& other ) { Set( other ); }
123 constexpr void operator+=( const TVector2& other ) { Add( other ); }
124 constexpr void operator/=( const TVector2& other ) { Divide( other ); }
125
126public:
127 static TFLOAT Distance( const TVector2& vec1, const TVector2& vec2 ) { return ( vec2 - vec1 ).Magnitude(); }
128 static constexpr TFLOAT DistanceSq( const TVector2& vec1, const TVector2& vec2 ) { return ( vec2 - vec1 ).MagnitudeSq(); }
129 static constexpr TFLOAT DotProduct( const TVector2& vec1, const TVector2& vec2 ) { return vec1.x * vec2.x + vec1.y * vec2.y; }
130
131public:
132 constinit const static TVector2 VEC_ZERO;
133 constinit const static TVector2 VEC_POSX;
134 constinit const static TVector2 VEC_POSY;
135 constinit const static TVector2 VEC_NEGX;
136 constinit const static TVector2 VEC_NEGY;
137
138public:
140};
141
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
float TFLOAT
Definition Typedefs.h:4
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE TFLOAT Abs(TFLOAT fVal)
Definition TMathInline.h:63
TFORCEINLINE TFLOAT OneOverSqrt(TFLOAT a_fX)
Definition TMathInline.h:92
TFORCEINLINE TFLOAT Sqrt(TFLOAT a_fX)
Definition TMathInline.h:84
constinit static const TVector2 VEC_NEGY
Definition TVector2.h:136
constexpr TVector2()=default
constexpr void Divide(const TVector2 &vec)
Definition TVector2.h:42
static TFLOAT Distance(const TVector2 &vec1, const TVector2 &vec2)
Definition TVector2.h:127
TFLOAT Magnitude() const
Definition TVector2.h:112
constexpr TVector2 operator+(const TVector2 &other) const
Definition TVector2.h:117
constexpr void Multiply(const TVector2 &vec, TFLOAT scalar)
Definition TVector2.h:83
constexpr TVector2 operator-(const TVector2 &other) const
Definition TVector2.h:118
constexpr void Add(const TVector2 &a, const TVector2 &b)
Definition TVector2.h:37
TFLOAT y
Definition TVector2.h:139
void Abs()
Definition TVector2.h:109
constexpr void Set(TFLOAT x, TFLOAT y)
Definition TVector2.h:13
constexpr TVector2(TFLOAT coords[2])
Definition TVector2.h:10
constexpr TVector2(const TVector2 &other)
Definition TVector2.h:11
constinit static const TVector2 VEC_NEGX
Definition TVector2.h:135
constinit static const TVector2 VEC_POSY
Definition TVector2.h:134
constexpr TFLOAT MagnitudeSq() const
Definition TVector2.h:113
constexpr void Divide(const TVector2 &vec1, const TVector2 &vec2)
Definition TVector2.h:55
constexpr void operator+=(const TVector2 &other)
Definition TVector2.h:123
constexpr void Set(const TVector2 &other)
Definition TVector2.h:25
constexpr void operator=(const TVector2 &other)
Definition TVector2.h:122
constexpr TVector2 operator/(const TVector2 &other) const
Definition TVector2.h:120
constexpr void Multiply(TFLOAT scalar)
Definition TVector2.h:72
constexpr void Set(TFLOAT coords[2])
Definition TVector2.h:19
constinit static const TVector2 VEC_ZERO
Definition TVector2.h:132
TFLOAT x
Definition TVector2.h:139
constexpr void Multiply(const TVector2 &vec)
Definition TVector2.h:66
constexpr void operator/=(const TVector2 &other)
Definition TVector2.h:124
constexpr void Divide(const TVector2 &vec, TFLOAT scalar)
Definition TVector2.h:60
static constexpr TFLOAT DistanceSq(const TVector2 &vec1, const TVector2 &vec2)
Definition TVector2.h:128
void Normalize()
Definition TVector2.h:95
constexpr TVector2(TFLOAT x, TFLOAT y)
Definition TVector2.h:9
constinit static const TVector2 VEC_POSX
Definition TVector2.h:133
void Abs(const TVector2 &vec3)
Definition TVector2.h:108
constexpr void Add(const TVector2 &vec)
Definition TVector2.h:31
static constexpr TFLOAT DotProduct(const TVector2 &vec1, const TVector2 &vec2)
Definition TVector2.h:129
constexpr void Negate()
Definition TVector2.h:89
TBOOL IsEqual(const TVector2 &vec)
Definition TVector2.h:115
constexpr void Multiply(const TVector2 &vec1, const TVector2 &vec2)
Definition TVector2.h:78
constexpr TVector2 operator*(const TVector2 &other) const
Definition TVector2.h:119
constexpr void Divide(TFLOAT scalar)
Definition TVector2.h:48