aboutsummaryrefslogtreecommitdiff
path: root/src/math/vector.hpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2026-01-13 02:04:52 +0100
committervimene <vincent.menegaux@gmail.com>2026-01-13 02:04:52 +0100
commitdb41d43345ea73cf7c1bbb29448e52ffb822e3e0 (patch)
tree4635d654e301b3f31f8d2626f3bc2c6f2a6e50a8 /src/math/vector.hpp
parent7f08187a46e30925e4563585fab2c6f92400330a (diff)
downloadengine-db41d43345ea73cf7c1bbb29448e52ffb822e3e0.tar.gz
added textures for the hardware renderer
- removed "using" directive in .hpp - reverse order of arguments for quaternion rotation, i.e. q.rot(v) instead of v.rot(q), where q is a quaterinon and v a vector - pass the inverse of the view matrix to render_and_present_frame, to allow light calculation in shaders (we used to just pass the matrix of the quaternion of the transformation, i.e. discard scaling and translations) - added another mesh and texture (viking_room) for testing purposes - added transparent background option - added Quaternion::look_towards(), which is the equivalent of Matrix4::look_at() but only for rotations - various improvement to .obj parsing - load texture coordinates from .obj file - merged duplicate vertices in Mesh::linearize_indices()
Diffstat (limited to 'src/math/vector.hpp')
-rw-r--r--src/math/vector.hpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/math/vector.hpp b/src/math/vector.hpp
index e836e0d..471f30d 100644
--- a/src/math/vector.hpp
+++ b/src/math/vector.hpp
@@ -2,11 +2,20 @@
#define MATH_VECTOR_HPP
#include <cmath>
-#include "math/quat.hpp"
namespace engine::math {
+struct Vector2;
+constexpr Vector2 operator*(float n, const Vector2& other);
+constexpr Vector2 operator/(const Vector2& other, float n);
+
struct Vector2 {
+ static constexpr size_t size = 2;
+
+ static constexpr Vector2 bilerp(const Vector2& v1, const Vector2& v2, const Vector2& v3, float b0, float b1) {
+ return b0 * v1 + b1 * v2 + (1.f - b0 - b1) * v3;
+ }
+
float x, y;
constexpr bool operator==(const Vector2& other) const & {
@@ -77,6 +86,8 @@ constexpr Vector3 operator*(float n, const Vector3& other);
constexpr Vector3 operator/(const Vector3& other, float n);
struct Vector3 {
+ static constexpr size_t size = 3;
+
static constexpr Vector3 bilerp(const Vector3& v1, const Vector3& v2, const Vector3& v3, float b0, float b1) {
return b0 * v1 + b1 * v2 + (1.f - b0 - b1) * v3;
}
@@ -126,14 +137,6 @@ struct Vector3 {
};
}
- constexpr Vector3 rot(const Quaternion& q) const & {
- return {
- (2.f * (q.w * q.w + q.x * q.x) - 1.f) * x + (2.f * (q.x * q.y - q.w * q.z) ) * y + (2.f * (q.x * q.z + q.w * q.y) ) * z,
- (2.f * (q.x * q.y + q.w * q.z) ) * x + (2.f * (q.w * q.w + q.y * q.y) - 1.f) * y + (2.f * (q.y * q.z - q.w * q.x) ) * z,
- (2.f * (q.x * q.z - q.w * q.y) ) * x + (2.f * (q.y * q.z + q.w * q.x) ) * y + (2.f * (q.w * q.w + q.z * q.z) - 1.f) * z,
- };
- }
-
constexpr float dot(const Vector3& other) const & {
return x * other.x + y * other.y + z * other.z;
}
@@ -168,15 +171,14 @@ constexpr Vector3 operator/(const Vector3& other, float n) {
}
struct Vector4 {
+ static constexpr size_t size = 4;
+
float x, y, z, w;
constexpr Vector4() {}
constexpr Vector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} {}
- constexpr Vector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} {}
constexpr Vector4(const Vector2& v, float z, float w) : x{v.x}, y{v.y}, z{z}, w{w} {}
- constexpr Vector4(const Vector2& v, float z) : x{v.x}, y{v.y}, z{z}, w{1.f} {}
constexpr Vector4(const Vector3& v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} {}
- constexpr Vector4(const Vector3& v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} {}
constexpr bool operator==(const Vector4& other) const & {
return x == other.x && y == other.y && z == other.z && w == other.w;