cangine
Loading...
Searching...
No Matches
vector3.hpp
Go to the documentation of this file.
1#pragma once
2#include "vector2.hpp"
3
4namespace cangine {
5
13struct Vector3 {
14 float x{}, y{}, z{};
15
16 // Constructors
18 constexpr Vector3() noexcept = default;
25 constexpr Vector3(float _x, float _y, float _z) noexcept : x(_x), y(_y), z(_z) {}
31 constexpr Vector3(const Vector2& xy, float _z) noexcept : x(xy.x), y(xy.y), z(_z) {}
36 constexpr Vector3(const Vector2& xy) noexcept : x(xy.x), y(xy.y), z(0) {}
37
38 // Compound assignment operators (Vector3 op Vector3)
44 constexpr Vector3& operator+=(const Vector3& rhs) noexcept { x += rhs.x; y += rhs.y; z += rhs.z; return *this; }
50 constexpr Vector3& operator-=(const Vector3& rhs) noexcept { x -= rhs.x; y -= rhs.y; z -= rhs.z; return *this; }
56 constexpr Vector3& operator*=(const Vector3& rhs) noexcept { x *= rhs.x; y *= rhs.y; z *= rhs.z; return *this; }
62 constexpr Vector3& operator/=(const Vector3& rhs) noexcept { x /= rhs.x; y /= rhs.y; z /= rhs.z; return *this; }
63
64 // Compound assignment operators (Vector3 op scalar)
70 constexpr Vector3& operator+=(float rhs) noexcept { x += rhs; y += rhs; z += rhs; return *this; }
76 constexpr Vector3& operator-=(float rhs) noexcept { x -= rhs; y -= rhs; z -= rhs; return *this; }
82 constexpr Vector3& operator*=(float rhs) noexcept { x *= rhs; y *= rhs; z *= rhs; return *this; }
88 constexpr Vector3& operator/=(float rhs) noexcept { x /= rhs; y /= rhs; z /= rhs; return *this; }
89};
90
98// Free operators for Vector3
99#define CANGINE_VECTOR3_OP(OP) \
100constexpr Vector3 operator OP(const Vector3& lhs, const Vector3& rhs) noexcept { return Vector3(lhs.x OP rhs.x, lhs.y OP rhs.y, lhs.z OP rhs.z); } \
101constexpr Vector3 operator OP(const Vector3& lhs, float rhs) noexcept { return Vector3(lhs.x OP rhs, lhs.y OP rhs, lhs.z OP rhs); } \
102constexpr Vector3 operator OP(float lhs, const Vector3& rhs) noexcept { return Vector3(lhs OP rhs.x, lhs OP rhs.y, lhs OP rhs.z); }
103
108
109#undef CANGINE_VECTOR3_OP
110
111} // namespace cangine
Definition audiomanager.cpp:4
Two-component floating-point vector.
Definition vector2.hpp:13
Three-component floating-point vector.
Definition vector3.hpp:13
constexpr Vector3(const Vector2 &xy, float _z) noexcept
Constructs a vector from a 2D vector and an explicit z.
Definition vector3.hpp:31
constexpr Vector3(const Vector2 &xy) noexcept
Constructs a vector from a 2D vector with z defaulting to 0.
Definition vector3.hpp:36
constexpr Vector3 & operator*=(const Vector3 &rhs) noexcept
Multiplies by another vector component-wise.
Definition vector3.hpp:56
constexpr Vector3 & operator+=(const Vector3 &rhs) noexcept
Adds another vector component-wise.
Definition vector3.hpp:44
constexpr Vector3 & operator/=(float rhs) noexcept
Divides all components by a scalar.
Definition vector3.hpp:88
constexpr Vector3 & operator-=(float rhs) noexcept
Subtracts a scalar from all components.
Definition vector3.hpp:76
float y
Definition vector3.hpp:14
constexpr Vector3 & operator-=(const Vector3 &rhs) noexcept
Subtracts another vector component-wise.
Definition vector3.hpp:50
constexpr Vector3 & operator*=(float rhs) noexcept
Multiplies all components by a scalar.
Definition vector3.hpp:82
float z
Vector components.
Definition vector3.hpp:14
constexpr Vector3 & operator/=(const Vector3 &rhs) noexcept
Divides by another vector component-wise.
Definition vector3.hpp:62
float x
Definition vector3.hpp:14
constexpr Vector3() noexcept=default
Constructs a zero vector (x = y = z = 0).
constexpr Vector3 & operator+=(float rhs) noexcept
Adds a scalar to all components.
Definition vector3.hpp:70
#define CANGINE_VECTOR3_OP(OP)
Defines the free binary operator OP for Vector3.
Definition vector3.hpp:99