OpenBarnyard
 
Loading...
Searching...
No Matches
TVector3.h
Go to the documentation of this file.
1
11
12#pragma once
13
15
17{
18public:
19 constexpr TVector3() = default;
20 constexpr TVector3( TFLOAT x, TFLOAT y, TFLOAT z ) { Set( x, y, z ); }
21 constexpr TVector3( TFLOAT floats[ 3 ] ) { Set( floats ); }
22 constexpr TVector3( const TVector3& other ) { Set( other.x, other.y, other.z ); }
23
24 void Clip( TFLOAT fVal, TFLOAT fVal2 );
25 void CrossProduct( const TVector3&, const TVector3& );
26
27 void RotateX( TFLOAT a_fRotation );
28 void RotateY( TFLOAT a_fRotation );
29 void RotateZ( TFLOAT a_fRotation );
30
31 void Normalize();
32
33 constexpr void Set( const TVector3& vec )
34 {
35 TVector3::x = vec.x;
36 TVector3::y = vec.y;
37 TVector3::z = vec.z;
38 }
39 constexpr void Set( TFLOAT floats[ 3 ] )
40 {
41 TVector3::x = floats[ 0 ];
42 TVector3::y = floats[ 1 ];
43 TVector3::z = floats[ 2 ];
44 }
45 constexpr void Set( TFLOAT x, TFLOAT y, TFLOAT z )
46 {
47 TVector3::x = x;
48 TVector3::y = y;
49 TVector3::z = z;
50 }
51
52 // $Barnyard: FUNCTION 006cbba0
53 constexpr void Lerp( const TVector3& finish, float t ) { Lerp( *this, finish, t ); }
54
55 // $Barnyard: FUNCTION 006cbb60
56 constexpr void Lerp( const TVector3& start, const TVector3& finish, float t )
57 {
58 TVector3 progress = finish - start;
59 progress.Multiply( t );
60
61 Set( start + progress );
62 }
63
64 // $Barnyard: FUNCTION 0040f390
65 constexpr void Add( const TVector3& vec )
66 {
67 x += vec.x;
68 y += vec.y;
69 z += vec.z;
70 }
71
72 constexpr void Add( const TVector3& a, const TVector3& b )
73 {
74 Set( a + b );
75 }
76
77 constexpr void Divide( const TVector3& vec )
78 {
79 x /= vec.x;
80 y /= vec.y;
81 z /= vec.z;
82 }
83
84 constexpr void Divide( TFLOAT scalar )
85 {
86 TFLOAT ratio = 1.0f / scalar;
87 x *= ratio;
88 y *= ratio;
89 z *= ratio;
90 }
91
92 constexpr void Divide( const TVector3& vec1, const TVector3& vec2 )
93 {
94 Set( vec1 / vec2 );
95 }
96
97 constexpr void Divide( const TVector3& vec, TFLOAT scalar )
98 {
99 Set( vec );
100 Divide( scalar );
101 }
102
103 constexpr void Multiply( const TVector3& vec )
104 {
105 x *= vec.x;
106 y *= vec.y;
107 z *= vec.z;
108 }
109
110 constexpr void Multiply( TFLOAT scalar )
111 {
112 x *= scalar;
113 y *= scalar;
114 z *= scalar;
115 }
116
117 constexpr void Multiply( const TVector3& vec1, const TVector3& vec2 )
118 {
119 Set( vec1 * vec2 );
120 }
121
122 constexpr void Multiply( const TVector3& vec, TFLOAT scalar )
123 {
124 Set( vec );
125 Multiply( scalar );
126 }
127
128 void Abs( const TVector3& vec3 ) { Set( TMath::Abs( vec3.x ), TMath::Abs( vec3.y ), TMath::Abs( vec3.z ) ); }
129 void Abs() { Set( TMath::Abs( x ), TMath::Abs( y ), TMath::Abs( z ) ); }
130
131 // $Barnyard: FUNCTION 006c74f0
132 TFLOAT Magnitude() const { return TMath::Sqrt( x * x + y * y + z * z ); }
133 constexpr TFLOAT MagnitudeSq() const { return x * x + y * y + z * z; }
134
135 constexpr TVector3 operator+( const TVector3& other ) const { return { x + other.x, y + other.y, z + other.z }; }
136 constexpr TVector3 operator-( const TVector3& other ) const { return { x - other.x, y - other.y, z - other.z }; }
137 constexpr TVector3 operator*( const TVector3& other ) const { return { x * other.x, y * other.y, z * other.z }; }
138 constexpr TVector3 operator/( const TVector3& other ) const { return { x / other.x, y / other.y, z / other.z }; }
139
140 constexpr void operator=( const TVector3& other ) { Set( other ); }
141 constexpr void operator+=( const TVector3& other ) { Add( other ); }
142 constexpr void operator/=( const TVector3& other ) { Divide( other ); }
143
144public:
145 static TFLOAT Distance( const TVector3& vec1, const TVector3& vec2 ) { return ( vec2 - vec1 ).Magnitude(); }
146 static constexpr TFLOAT DistanceSq( const TVector3& vec1, const TVector3& vec2 ) { return ( vec2 - vec1 ).MagnitudeSq(); }
147 static constexpr TFLOAT DotProduct( const TVector3& vec1, const TVector3& vec2 ) { return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z; }
148
149public:
150 static constinit const TVector3 VEC_ZERO;
151 static constinit const TVector3 VEC_POSX;
152 static constinit const TVector3 VEC_POSY;
153 static constinit const TVector3 VEC_POSZ;
154 static constinit const TVector3 VEC_NEGX;
155 static constinit const TVector3 VEC_NEGY;
156 static constinit const TVector3 VEC_NEGZ;
157 static constinit const TVector3 VEC_NEGXPOSZ;
158 static constinit const TVector3 VEC_NEGXNEGZ;
159 static constinit const TVector3 VEC_POSXPOSZ;
160 static constinit const TVector3 VEC_POSXNEGZ;
161
162public:
164};
165
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
float TFLOAT
Definition Typedefs.h:4
TFORCEINLINE TFLOAT Abs(TFLOAT fVal)
Definition TMathInline.h:63
TFORCEINLINE TFLOAT Sqrt(TFLOAT a_fX)
Definition TMathInline.h:84
static constinit const TVector3 VEC_ZERO
Definition TVector3.h:150
static constinit const TVector3 VEC_NEGXPOSZ
Definition TVector3.h:157
constexpr TVector3 operator/(const TVector3 &other) const
Definition TVector3.h:138
void Abs()
Definition TVector3.h:129
static constinit const TVector3 VEC_NEGZ
Definition TVector3.h:156
constexpr void Lerp(const TVector3 &finish, float t)
Definition TVector3.h:53
constexpr void Multiply(const TVector3 &vec)
Definition TVector3.h:103
constexpr void Divide(const TVector3 &vec)
Definition TVector3.h:77
void CrossProduct(const TVector3 &, const TVector3 &)
Definition TVector3.cpp:25
constexpr TVector3(const TVector3 &other)
Definition TVector3.h:22
constexpr TVector3 operator*(const TVector3 &other) const
Definition TVector3.h:137
static TFLOAT Distance(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:145
constexpr void Divide(TFLOAT scalar)
Definition TVector3.h:84
static constinit const TVector3 VEC_POSZ
Definition TVector3.h:153
static constinit const TVector3 VEC_POSY
Definition TVector3.h:152
constexpr void Divide(const TVector3 &vec, TFLOAT scalar)
Definition TVector3.h:97
TFLOAT y
Definition TVector3.h:163
void Abs(const TVector3 &vec3)
Definition TVector3.h:128
constexpr void operator+=(const TVector3 &other)
Definition TVector3.h:141
constexpr TFLOAT MagnitudeSq() const
Definition TVector3.h:133
constexpr void Lerp(const TVector3 &start, const TVector3 &finish, float t)
Definition TVector3.h:56
void RotateZ(TFLOAT a_fRotation)
Definition TVector3.cpp:59
constexpr void Set(TFLOAT floats[3])
Definition TVector3.h:39
void RotateX(TFLOAT a_fRotation)
Definition TVector3.cpp:34
constexpr void Set(TFLOAT x, TFLOAT y, TFLOAT z)
Definition TVector3.h:45
constexpr void Multiply(TFLOAT scalar)
Definition TVector3.h:110
constexpr TVector3()=default
static constinit const TVector3 VEC_POSX
Definition TVector3.h:151
constexpr void operator=(const TVector3 &other)
Definition TVector3.h:140
constexpr void Set(const TVector3 &vec)
Definition TVector3.h:33
TFLOAT z
Definition TVector3.h:163
constexpr void Divide(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:92
TFLOAT x
Definition TVector3.h:163
constexpr void operator/=(const TVector3 &other)
Definition TVector3.h:142
constexpr void Add(const TVector3 &a, const TVector3 &b)
Definition TVector3.h:72
static constinit const TVector3 VEC_POSXNEGZ
Definition TVector3.h:160
constexpr TVector3 operator+(const TVector3 &other) const
Definition TVector3.h:135
constexpr void Add(const TVector3 &vec)
Definition TVector3.h:65
static constinit const TVector3 VEC_POSXPOSZ
Definition TVector3.h:159
void RotateY(TFLOAT a_fRotation)
Definition TVector3.cpp:47
constexpr void Multiply(const TVector3 &vec, TFLOAT scalar)
Definition TVector3.h:122
constexpr TVector3(TFLOAT floats[3])
Definition TVector3.h:21
void Normalize()
Definition TVector3.cpp:71
static constexpr TFLOAT DistanceSq(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:146
static constinit const TVector3 VEC_NEGXNEGZ
Definition TVector3.h:158
constexpr TVector3(TFLOAT x, TFLOAT y, TFLOAT z)
Definition TVector3.h:20
static constinit const TVector3 VEC_NEGX
Definition TVector3.h:154
static constexpr TFLOAT DotProduct(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:147
TFLOAT Magnitude() const
Definition TVector3.h:132
constexpr void Multiply(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:117
constexpr TVector3 operator-(const TVector3 &other) const
Definition TVector3.h:136
static constinit const TVector3 VEC_NEGY
Definition TVector3.h:155
void Clip(TFLOAT fVal, TFLOAT fVal2)
Definition TVector3.cpp:18