| 1 | #pragma once |
| 2 | |
| 3 | #include <math/seadVectorCalcCommon.h> |
| 4 | #ifndef SEAD_MATH_VECTOR_H_ |
| 5 | #include <math/seadVector.h> |
| 6 | #endif |
| 7 | |
| 8 | namespace sead |
| 9 | { |
| 10 | template <typename T> |
| 11 | inline Vector2<T>::Vector2(T x_, T y_) |
| 12 | { |
| 13 | Vector2CalcCommon<T>::set(*this, x_, y_); |
| 14 | } |
| 15 | |
| 16 | template <typename T> |
| 17 | inline Vector2<T>& Vector2<T>::operator+=(const Vector2<T>& other) |
| 18 | { |
| 19 | Vector2CalcCommon<T>::add(*this, *this, other); |
| 20 | return *this; |
| 21 | } |
| 22 | |
| 23 | template <typename T> |
| 24 | inline Vector2<T>& Vector2<T>::operator-=(const Vector2<T>& other) |
| 25 | { |
| 26 | Vector2CalcCommon<T>::sub(*this, *this, other); |
| 27 | return *this; |
| 28 | } |
| 29 | |
| 30 | template <typename T> |
| 31 | inline Vector2<T>& Vector2<T>::operator*=(T t) |
| 32 | { |
| 33 | this->x *= t; |
| 34 | this->y *= t; |
| 35 | return *this; |
| 36 | } |
| 37 | |
| 38 | template <typename T> |
| 39 | inline Vector2<T>& Vector2<T>::operator/=(T t) |
| 40 | { |
| 41 | this->x /= t; |
| 42 | this->y /= t; |
| 43 | return *this; |
| 44 | } |
| 45 | |
| 46 | template <typename T> |
| 47 | inline Vector2<T>& Vector2<T>::operator=(const Vector2<T>& other) |
| 48 | { |
| 49 | this->x = other.x; |
| 50 | this->y = other.y; |
| 51 | return *this; |
| 52 | } |
| 53 | |
| 54 | template <typename T> |
| 55 | inline void Vector2<T>::negate() |
| 56 | { |
| 57 | Vector2CalcCommon<T>::negate(*this); |
| 58 | } |
| 59 | |
| 60 | template <typename T> |
| 61 | inline void Vector2<T>::multScalar(T t) |
| 62 | { |
| 63 | Vector2CalcCommon<T>::multScalar(*this, *this, t); |
| 64 | } |
| 65 | |
| 66 | template <typename T> |
| 67 | inline void Vector2<T>::set(const Vector2<T>& other) |
| 68 | { |
| 69 | Vector2CalcCommon<T>::set(*this, other); |
| 70 | } |
| 71 | |
| 72 | template <typename T> |
| 73 | inline void Vector2<T>::set(T x_, T y_) |
| 74 | { |
| 75 | Vector2CalcCommon<T>::set(*this, x_, y_); |
| 76 | } |
| 77 | |
| 78 | template <typename T> |
| 79 | inline void Vector2<T>::setScale(const Vector2<T>& a, T t) |
| 80 | { |
| 81 | Vector2CalcCommon<T>::multScalar(*this, a, t); |
| 82 | } |
| 83 | |
| 84 | template <typename T> |
| 85 | inline T Vector2<T>::dot(const Vector2<T>& t) const |
| 86 | { |
| 87 | return Vector2CalcCommon<T>::dot(*this, t); |
| 88 | } |
| 89 | |
| 90 | template <typename T> |
| 91 | inline T Vector2<T>::cross(const Vector2<T>& t) const |
| 92 | { |
| 93 | return Vector2CalcCommon<T>::cross(*this, t); |
| 94 | } |
| 95 | |
| 96 | template <typename T> |
| 97 | inline T Vector2<T>::length() const |
| 98 | { |
| 99 | return Vector2CalcCommon<T>::length(*this); |
| 100 | } |
| 101 | |
| 102 | template <typename T> |
| 103 | inline T Vector2<T>::squaredLength() const |
| 104 | { |
| 105 | return Vector2CalcCommon<T>::squaredLength(*this); |
| 106 | } |
| 107 | |
| 108 | template <typename T> |
| 109 | inline T Vector2<T>::normalize() |
| 110 | { |
| 111 | return Vector2CalcCommon<T>::normalize(*this); |
| 112 | } |
| 113 | |
| 114 | template <typename T> |
| 115 | inline Vector3<T>::Vector3(T x_, T y_, T z_) |
| 116 | { |
| 117 | Vector3CalcCommon<T>::set(*this, x_, y_, z_); |
| 118 | } |
| 119 | |
| 120 | template <typename T> |
| 121 | inline Vector3<T>& Vector3<T>::operator=(const Vector3<T>& other) |
| 122 | { |
| 123 | this->x = other.x; |
| 124 | this->y = other.y; |
| 125 | this->z = other.z; |
| 126 | return *this; |
| 127 | } |
| 128 | |
| 129 | template <typename T> |
| 130 | inline bool Vector3<T>::operator==(const Vector3& rhs) const |
| 131 | { |
| 132 | return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; |
| 133 | } |
| 134 | |
| 135 | template <typename T> |
| 136 | inline bool Vector3<T>::operator!=(const Vector3& rhs) const |
| 137 | { |
| 138 | return !operator==(rhs); |
| 139 | } |
| 140 | |
| 141 | template <typename T> |
| 142 | inline Vector3<T>& Vector3<T>::operator+=(const Vector3<T>& other) |
| 143 | { |
| 144 | Vector3CalcCommon<T>::add(*this, *this, other); |
| 145 | return *this; |
| 146 | } |
| 147 | |
| 148 | template <typename T> |
| 149 | inline Vector3<T>& Vector3<T>::operator-=(const Vector3<T>& other) |
| 150 | { |
| 151 | Vector3CalcCommon<T>::sub(*this, *this, other); |
| 152 | return *this; |
| 153 | } |
| 154 | |
| 155 | template <typename T> |
| 156 | inline Vector3<T>& Vector3<T>::operator*=(T t) |
| 157 | { |
| 158 | Vector3CalcCommon<T>::multScalar(*this, *this, t); |
| 159 | return *this; |
| 160 | } |
| 161 | |
| 162 | template <typename T> |
| 163 | inline Vector3<T>& Vector3<T>::operator*=(const Mtx33& m) |
| 164 | { |
| 165 | mul(m); |
| 166 | return *this; |
| 167 | } |
| 168 | |
| 169 | template <typename T> |
| 170 | inline Vector3<T>& Vector3<T>::operator*=(const Mtx34& m) |
| 171 | { |
| 172 | mul(m); |
| 173 | return *this; |
| 174 | } |
| 175 | |
| 176 | template <typename T> |
| 177 | inline Vector3<T>& Vector3<T>::operator/=(T t) |
| 178 | { |
| 179 | this->x /= t; |
| 180 | this->y /= t; |
| 181 | this->z /= t; |
| 182 | return *this; |
| 183 | } |
| 184 | |
| 185 | template <typename T> |
| 186 | inline T Vector3<T>::dot(const Vector3<T>& t) const |
| 187 | { |
| 188 | return Vector3CalcCommon<T>::dot(*this, t); |
| 189 | } |
| 190 | |
| 191 | template <typename T> |
| 192 | inline T Vector3<T>::length() const |
| 193 | { |
| 194 | return Vector3CalcCommon<T>::length(*this); |
| 195 | } |
| 196 | |
| 197 | template <typename T> |
| 198 | inline T Vector3<T>::squaredLength() const |
| 199 | { |
| 200 | return Vector3CalcCommon<T>::squaredLength(*this); |
| 201 | } |
| 202 | |
| 203 | template <typename T> |
| 204 | inline bool Vector3<T>::equals(const Vector3<T>& rhs, T epsilon) const |
| 205 | { |
| 206 | return Vector3CalcCommon<T>::equals(*this, rhs, epsilon); |
| 207 | } |
| 208 | |
| 209 | template <typename T> |
| 210 | inline void Vector3<T>::add(const Vector3<T>& a) |
| 211 | { |
| 212 | Vector3CalcCommon<T>::add(*this, *this, a); |
| 213 | } |
| 214 | |
| 215 | template <typename T> |
| 216 | inline void Vector3<T>::mul(const Mtx33& m) |
| 217 | { |
| 218 | setMul(m, *this); |
| 219 | } |
| 220 | |
| 221 | template <typename T> |
| 222 | inline void Vector3<T>::mul(const Mtx34& m) |
| 223 | { |
| 224 | setMul(m, *this); |
| 225 | } |
| 226 | |
| 227 | template <typename T> |
| 228 | inline void Vector3<T>::rotate(const Mtx33& m) |
| 229 | { |
| 230 | setRotated(m, *this); |
| 231 | } |
| 232 | |
| 233 | template <typename T> |
| 234 | inline void Vector3<T>::rotate(const Mtx34& m) |
| 235 | { |
| 236 | setRotated(m, *this); |
| 237 | } |
| 238 | |
| 239 | template <typename T> |
| 240 | inline void Vector3<T>::rotate(const Quat& q) |
| 241 | { |
| 242 | setRotated(q, *this); |
| 243 | } |
| 244 | |
| 245 | template <typename T> |
| 246 | inline void Vector3<T>::multScalar(T t) |
| 247 | { |
| 248 | Vector3CalcCommon<T>::multScalar(*this, *this, t); |
| 249 | } |
| 250 | |
| 251 | template <typename T> |
| 252 | inline T Vector3<T>::normalize() |
| 253 | { |
| 254 | return Vector3CalcCommon<T>::normalize(*this); |
| 255 | } |
| 256 | |
| 257 | template <typename T> |
| 258 | inline void Vector3<T>::negate() |
| 259 | { |
| 260 | Vector3CalcCommon<T>::negate(*this); |
| 261 | } |
| 262 | |
| 263 | template <typename T> |
| 264 | inline void Vector3<T>::set(const Vector3<T>& other) |
| 265 | { |
| 266 | Vector3CalcCommon<T>::set(*this, other); |
| 267 | } |
| 268 | |
| 269 | template <typename T> |
| 270 | inline void Vector3<T>::set(T x_, T y_, T z_) |
| 271 | { |
| 272 | Vector3CalcCommon<T>::set(*this, x_, y_, z_); |
| 273 | } |
| 274 | |
| 275 | template <typename T> |
| 276 | inline void Vector3<T>::setAdd(const Vector3<T>& a, const Vector3<T>& b) |
| 277 | { |
| 278 | Vector3CalcCommon<T>::add(*this, a, b); |
| 279 | } |
| 280 | |
| 281 | template <typename T> |
| 282 | inline void Vector3<T>::setCross(const Vector3<T>& a, const Vector3<T>& b) |
| 283 | { |
| 284 | Vector3CalcCommon<T>::cross(*this, a, b); |
| 285 | } |
| 286 | |
| 287 | template <typename T> |
| 288 | inline void Vector3<T>::setScale(const Vector3<T>& a, T t) |
| 289 | { |
| 290 | Vector3CalcCommon<T>::multScalar(*this, a, t); |
| 291 | } |
| 292 | |
| 293 | template <typename T> |
| 294 | inline void Vector3<T>::setScaleAdd(T t, const Vector3<T>& a, const Vector3<T>& b) |
| 295 | { |
| 296 | Vector3CalcCommon<T>::multScalarAdd(*this, t, a, b); |
| 297 | } |
| 298 | |
| 299 | template <typename T> |
| 300 | inline void Vector3<T>::setMul(const Mtx33& m, const Vector3<T>& a) |
| 301 | { |
| 302 | Vector3CalcCommon<T>::mul(*this, m, a); |
| 303 | } |
| 304 | |
| 305 | template <typename T> |
| 306 | inline void Vector3<T>::setMul(const Mtx34& m, const Vector3<T>& a) |
| 307 | { |
| 308 | Vector3CalcCommon<T>::mul(*this, m, a); |
| 309 | } |
| 310 | |
| 311 | template <typename T> |
| 312 | inline void Vector3<T>::setRotated(const Mtx33& m, const Vector3<T>& a) |
| 313 | { |
| 314 | Vector3CalcCommon<T>::rotate(*this, m, a); |
| 315 | } |
| 316 | |
| 317 | template <typename T> |
| 318 | inline void Vector3<T>::setRotated(const Mtx34& m, const Vector3<T>& a) |
| 319 | { |
| 320 | Vector3CalcCommon<T>::rotate(*this, m, a); |
| 321 | } |
| 322 | |
| 323 | template <typename T> |
| 324 | inline void Vector3<T>::setRotated(const Quat& q, const Vector3<T>& a) |
| 325 | { |
| 326 | Vector3CalcCommon<T>::rotate(*this, q, a); |
| 327 | } |
| 328 | |
| 329 | template <typename T> |
| 330 | inline void Vector3<T>::setSub(const Vector3<T>& a, const Vector3<T>& b) |
| 331 | { |
| 332 | Vector3CalcCommon<T>::sub(*this, a, b); |
| 333 | } |
| 334 | |
| 335 | template <typename T> |
| 336 | inline Vector4<T>::Vector4(T x_, T y_, T z_, T w_) |
| 337 | { |
| 338 | Vector4CalcCommon<T>::set(*this, x_, y_, z_, w_); |
| 339 | } |
| 340 | |
| 341 | template <typename T> |
| 342 | inline Vector4<T>& Vector4<T>::operator+=(const Vector4<T>& other) |
| 343 | { |
| 344 | this->x += other.x; |
| 345 | this->y += other.y; |
| 346 | this->z += other.z; |
| 347 | this->w += other.w; |
| 348 | return *this; |
| 349 | } |
| 350 | |
| 351 | template <typename T> |
| 352 | inline Vector4<T>& Vector4<T>::operator-=(const Vector4<T>& other) |
| 353 | { |
| 354 | this->x -= other.x; |
| 355 | this->y -= other.y; |
| 356 | this->z -= other.z; |
| 357 | this->w -= other.w; |
| 358 | return *this; |
| 359 | } |
| 360 | |
| 361 | template <typename T> |
| 362 | inline Vector4<T>& Vector4<T>::operator*=(T t) |
| 363 | { |
| 364 | this->x *= t; |
| 365 | this->y *= t; |
| 366 | this->z *= t; |
| 367 | this->w *= t; |
| 368 | return *this; |
| 369 | } |
| 370 | |
| 371 | template <typename T> |
| 372 | inline Vector4<T>& Vector4<T>::operator/=(T t) |
| 373 | { |
| 374 | this->x /= t; |
| 375 | this->y /= t; |
| 376 | this->z /= t; |
| 377 | this->w /= t; |
| 378 | return *this; |
| 379 | } |
| 380 | |
| 381 | template <typename T> |
| 382 | inline Vector4<T>& Vector4<T>::operator=(const Vector4<T>& other) |
| 383 | { |
| 384 | this->x = other.x; |
| 385 | this->y = other.y; |
| 386 | this->z = other.z; |
| 387 | this->w = other.w; |
| 388 | return *this; |
| 389 | } |
| 390 | |
| 391 | template <typename T> |
| 392 | inline T Vector4<T>::normalize() |
| 393 | { |
| 394 | return Vector4CalcCommon<T>::normalize(*this); |
| 395 | } |
| 396 | |
| 397 | template <typename T> |
| 398 | inline void Vector4<T>::negate() |
| 399 | { |
| 400 | Vector4CalcCommon<T>::negate(*this); |
| 401 | } |
| 402 | |
| 403 | template <typename T> |
| 404 | inline T Vector4<T>::length() const |
| 405 | { |
| 406 | return Vector4CalcCommon<T>::length(*this); |
| 407 | } |
| 408 | |
| 409 | template <typename T> |
| 410 | inline T Vector4<T>::squaredLength() const |
| 411 | { |
| 412 | return Vector4CalcCommon<T>::squaredLength(*this); |
| 413 | } |
| 414 | |
| 415 | template <typename T> |
| 416 | inline void Vector4<T>::set(const Vector4<T>& other) |
| 417 | { |
| 418 | Vector4CalcCommon<T>::set(*this, other); |
| 419 | } |
| 420 | |
| 421 | template <typename T> |
| 422 | inline void Vector4<T>::set(T x_, T y_, T z_, T w_) |
| 423 | { |
| 424 | Vector4CalcCommon<T>::set(*this, x_, y_, z_, w_); |
| 425 | } |
| 426 | |
| 427 | } // namespace sead |
| 428 | |