11#ifndef INCGUARD_MGL_VECTOR2_H_1606631290
12#define INCGUARD_MGL_VECTOR2_H_1606631290
44 constexpr Vector2(
float inX,
float inY) noexcept
108 [[nodiscard]]
bool IsZero() const noexcept
110 return ((std::fabs(
x) <= Math::kEpsilon) && (std::fabs(
y) <= Math::kEpsilon));
119 [[nodiscard]]
float Length() const noexcept
121 return std::sqrt((
x *
x) + (
y *
y));
133 return Vector2(
x - target.x,
y - target.y).Length();
145 return (
x * rhs.y) - (rhs.x *
y);
158 return (lhs.x * rhs.y) - (rhs.x * lhs.y);
170 return (
x * rhs.x) + (
y * rhs.y);
183 return (lhs.x * rhs.x) + (lhs.y * rhs.y);
195 auto length =
Length() * target.Length();
196 if ((length == 0.0f) || (length == -0.0f))
201 auto dot =
Dot(target);
202 if ((dot == 0.0f) || (dot == -0.0f))
204 return Math::kHalfPi;
207 const float theta = std::clamp(dot / length, -1.0f, 1.0f);
208 return std::acos(theta);
220 if ((
x == 0.0f) || (
x == -0.0f))
222 if ((
y == 0.0f) || (
y == -0.0f))
244 x = srcX * std::cos(radian) -
y * std::sin(radian);
245 y = srcX * std::sin(radian) +
y * std::cos(radian);
259 return {lhs.x + rhs.x, lhs.y + rhs.y};
272 return {lhs.x - rhs.x, lhs.y - rhs.y};
285 return {lhs.x * rhs, lhs.y * rhs};
298 return {lhs.x / rhs, lhs.y / rhs};
constexpr Vector2 operator-(const Vector2 &lhs, const Vector2 &rhs) noexcept
Vector2の減算
Definition mgl_vector2.h:270
constexpr Vector2 operator*(const Vector2 &lhs, float rhs) noexcept
Vector2の乗算
Definition mgl_vector2.h:283
constexpr Vector2 operator/(const Vector2 &lhs, float rhs) noexcept
Vector2の除算
Definition mgl_vector2.h:296
constexpr Vector2 operator+(const Vector2 &lhs, const Vector2 &rhs) noexcept
Vector2の加算
Definition mgl_vector2.h:257
2Dベクトル
Definition mgl_vector2.h:23
float y
Y成分
Definition mgl_vector2.h:25
float Cross(const Vector2 &rhs) const noexcept
外積を求める
Definition mgl_vector2.h:143
static float Cross(const Vector2 &lhs, const Vector2 &rhs) noexcept
外積を求める
Definition mgl_vector2.h:156
static float Dot(const Vector2 &lhs, const Vector2 &rhs) noexcept
内積を求める
Definition mgl_vector2.h:181
bool IsZero() const noexcept
値がほぼゼロかを調べる
Definition mgl_vector2.h:108
constexpr Vector2 & operator+=(const Vector2 &rhs) noexcept
単項加算演算子
Definition mgl_vector2.h:54
constexpr Vector2(float inX, float inY) noexcept
値を指定して初期化
Definition mgl_vector2.h:44
float Distance(const Vector2 &target) const noexcept
ターゲットまでの距離を求める
Definition mgl_vector2.h:131
constexpr Vector2 & operator-=(const Vector2 &rhs) noexcept
単項減算演算子
Definition mgl_vector2.h:67
float Dot(const Vector2 &rhs) const noexcept
内積を求める
Definition mgl_vector2.h:168
float GetAngle(const Vector2 &target) const noexcept
2点間の角度を求める
Definition mgl_vector2.h:193
float Length() const noexcept
長さを求める
Definition mgl_vector2.h:119
void Rotate(float radian) noexcept
ベクトルを回転
Definition mgl_vector2.h:241
bool Normalize() noexcept
ベクトルを正規化する
Definition mgl_vector2.h:218
constexpr Vector2 & operator/=(float rhs) noexcept
単項除算演算子
Definition mgl_vector2.h:93
constexpr Vector2 & operator*=(float rhs) noexcept
単項乗算演算子
Definition mgl_vector2.h:80
constexpr Vector2() noexcept
ゼロ初期化
Definition mgl_vector2.h:32
float x
X成分
Definition mgl_vector2.h:24