diff options
author | vimene <vincent.menegaux@gmail.com> | 2023-12-03 09:27:32 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2023-12-03 09:27:32 +0100 |
commit | 48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0 (patch) | |
tree | 259ec6e395e44b0af117adc9605203f8affb4b0f | |
parent | 5a8bc0a4936cdd461c43740437541f8c991ff117 (diff) | |
download | engine-48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0.tar.gz |
renamed MathVector{2,3,4} to Vector{2,3,4} and Mat4 to Matrix4 in engine::math
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/engine.cpp | 26 | ||||
-rw-r--r-- | src/fb/chfb.cpp | 10 | ||||
-rw-r--r-- | src/fb/chfb.h | 2 | ||||
-rw-r--r-- | src/fb/pixfb.cpp | 10 | ||||
-rw-r--r-- | src/fb/pixfb.h | 2 | ||||
-rw-r--r-- | src/math/mat4.cpp | 34 | ||||
-rw-r--r-- | src/math/mat4.h | 34 | ||||
-rw-r--r-- | src/math/vector.cpp | 90 | ||||
-rw-r--r-- | src/math/vector.h | 100 | ||||
-rw-r--r-- | src/o3d/camera.cpp | 4 | ||||
-rw-r--r-- | src/o3d/camera.h | 6 | ||||
-rw-r--r-- | src/o3d/mesh.cpp | 18 | ||||
-rw-r--r-- | src/o3d/obj3d.cpp | 4 | ||||
-rw-r--r-- | src/o3d/obj3d.h | 6 | ||||
-rw-r--r-- | src/o3d/tri_vertex.cpp | 14 | ||||
-rw-r--r-- | src/o3d/vertex.cpp | 6 | ||||
-rw-r--r-- | src/o3d/vertex.h | 10 |
18 files changed, 189 insertions, 189 deletions
diff --git a/Makefile.am b/Makefile.am index 87033a8..c0f1b53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,7 +9,7 @@ bin_PROGRAMS = engine engine_SOURCES = src/engine.cpp \ src/fb/chfb.h src/fb/chfb.cpp src/fb/pixfb.h src/fb/pixfb.cpp \ - src/math/math_vector.h src/math/math_vector.cpp \ + src/math/vector.h src/math/vector.cpp \ src/math/mat4.h src/math/mat4.cpp \ src/o3d/mesh.h src/o3d/mesh.cpp src/o3d/tri_vertex.h \ src/o3d/obj3d.h src/o3d/obj3d.cpp src/o3d/tri_vertex.h \ diff --git a/src/engine.cpp b/src/engine.cpp index 145c1f9..aeae21c 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -25,7 +25,7 @@ #include "o3d/vertex_data.h" #include "o3d/tri_vertex.h" #include "o3d/camera.h" -#include "math/math_vector.h" +#include "math/vector.h" #include "math/mat4.h" #define FPS 60 @@ -60,17 +60,17 @@ static void scene_main(FB& fb, std::function<bool()> update_frame) { { // objects engine::o3d::Object3D{ engine::o3d::Mesh::cube(), - -rad * engine::math::MathVector3(.5f, .5f, .5f), + -rad * engine::math::Vector3(.5f, .5f, .5f), rad, 0.f, 0.f, 0.f }, engine::o3d::Object3D{ engine::o3d::Mesh::cube(), - +rad * engine::math::MathVector3(.5f, .5f, .5f), + +rad * engine::math::Vector3(.5f, .5f, .5f), rad, 0.f, 0.f, 0.f }, } }; - auto scale_mat = engine::math::Mat4::scale(rad); + auto scale_mat = engine::math::Matrix4::scale(rad); while (cont) { scene.camera.rot_x += .0050f; scene.camera.rot_y += .0065f; @@ -78,21 +78,21 @@ static void scene_main(FB& fb, std::function<bool()> update_frame) { fb.clear(); auto transform_mat = - engine::math::Mat4::translate(-scene.camera.loc) - * engine::math::Mat4::rot_x(-scene.camera.rot_x) - * engine::math::Mat4::rot_y(-scene.camera.rot_y) - * engine::math::Mat4::rot_z(-scene.camera.rot_z); - std::array<engine::math::Mat4, 2> mats{{ - transform_mat * engine::math::Mat4::translate(engine::math::MathVector3{-.5f * rad, -.5f * rad, -.5f * rad}) * scale_mat, - transform_mat * engine::math::Mat4::translate(engine::math::MathVector3{+.5f * rad, +.5f * rad, +.5f * rad}) * scale_mat, + engine::math::Matrix4::translate(-scene.camera.loc) + * engine::math::Matrix4::rot_x(-scene.camera.rot_x) + * engine::math::Matrix4::rot_y(-scene.camera.rot_y) + * engine::math::Matrix4::rot_z(-scene.camera.rot_z); + std::array<engine::math::Matrix4, 2> mats{{ + transform_mat * engine::math::Matrix4::translate(engine::math::Vector3{-.5f * rad, -.5f * rad, -.5f * rad}) * scale_mat, + transform_mat * engine::math::Matrix4::translate(engine::math::Vector3{+.5f * rad, +.5f * rad, +.5f * rad}) * scale_mat, }}; - auto projection_mat = engine::math::Mat4::projection(static_cast<float>(fb.height()) / static_cast<float>(fb.width()), 2.f, 50.f); + auto projection_mat = engine::math::Matrix4::projection(static_cast<float>(fb.height()) / static_cast<float>(fb.width()), 2.f, 50.f); for (int i = 0; i < 2; i++) { auto final_mat = projection_mat * mats[i]; const auto& mesh = scene.objs[i].mesh; std::vector<engine::o3d::Vertex4> pts; for (const auto& vert : mesh.pts) - pts.push_back({ final_mat * engine::math::MathVector4{vert.point}, vert.data }); + pts.push_back({ final_mat * engine::math::Vector4{vert.point}, vert.data }); for (auto face : mesh.faces) fb.draw_triangle({pts[face[0]], pts[face[1]], pts[face[2]]}); } diff --git a/src/fb/chfb.cpp b/src/fb/chfb.cpp index 82b8f86..c0e5cc7 100644 --- a/src/fb/chfb.cpp +++ b/src/fb/chfb.cpp @@ -2,7 +2,7 @@ #include <array> #include <cmath> #include <vector> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex.h" #include "o3d/tri_vertex.h" #include "o3d/vertex_data.h" @@ -133,13 +133,13 @@ void CharacterFrameBuffer::draw_triangle(engine::o3d::TriangleVertex4 triangle) t1_2.vertex2.point.x *= 2.f; t1_2.vertex3.point.x *= 2.f; for (auto t2 : t1_2.crop_xy_out(-1.f, 1.f, -1.f, 1.f)) { - engine::math::MathVector2 pp1 = t2.vertex1.point.xy(), + engine::math::Vector2 pp1 = t2.vertex1.point.xy(), pp2 = t2.vertex2.point.xy(), pp3 = t2.vertex3.point.xy(); if ((pp2 - pp1).det(pp3 - pp1) >= 0.f) continue; - t2.vertex1.point = (t2.vertex1.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; - t2.vertex2.point = (t2.vertex2.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; - t2.vertex3.point = (t2.vertex3.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex1.point = (t2.vertex1.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex2.point = (t2.vertex2.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex3.point = (t2.vertex3.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; float fw = static_cast<float>(w), fh = static_cast<float>(h); t2.vertex1.point.x = t2.vertex1.point.x * fw - .5f; t2.vertex1.point.y = t2.vertex1.point.y * fh - .5f; diff --git a/src/fb/chfb.h b/src/fb/chfb.h index 1bf8b69..9e10a0d 100644 --- a/src/fb/chfb.h +++ b/src/fb/chfb.h @@ -2,7 +2,7 @@ #define FB_CHFB_H #include <vector> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/tri_vertex.h" namespace engine::fb { diff --git a/src/fb/pixfb.cpp b/src/fb/pixfb.cpp index c9e9927..af220c6 100644 --- a/src/fb/pixfb.cpp +++ b/src/fb/pixfb.cpp @@ -3,7 +3,7 @@ #include <cmath> #include <vector> #include <cstdint> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex.h" #include "o3d/tri_vertex.h" #include "o3d/vertex_data.h" @@ -130,13 +130,13 @@ void PixelFrameBuffer::draw_triangle(engine::o3d::TriangleVertex4 triangle) { face_ind++; for (auto t1 : triangle.crop_z_out(-1.f, 1.f)) { for (auto t2 : t1.div_by_w().crop_xy_out(-1.f, 1.f, -1.f, 1.f)) { - engine::math::MathVector2 pp1 = t2.vertex1.point.xy(), + engine::math::Vector2 pp1 = t2.vertex1.point.xy(), pp2 = t2.vertex2.point.xy(), pp3 = t2.vertex3.point.xy(); if ((pp2 - pp1).det(pp3 - pp1) >= 0.f) continue; - t2.vertex1.point = (t2.vertex1.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; - t2.vertex2.point = (t2.vertex2.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; - t2.vertex3.point = (t2.vertex3.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex1.point = (t2.vertex1.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex2.point = (t2.vertex2.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; + t2.vertex3.point = (t2.vertex3.point + engine::math::Vector3{1.f, 1.f, 0.f}) / 2.f; float fw = static_cast<float>(w), fh = static_cast<float>(h); t2.vertex1.point.x = t2.vertex1.point.x * fw - .5f; t2.vertex1.point.y = t2.vertex1.point.y * fh - .5f; diff --git a/src/fb/pixfb.h b/src/fb/pixfb.h index bf37d51..cdfac18 100644 --- a/src/fb/pixfb.h +++ b/src/fb/pixfb.h @@ -3,7 +3,7 @@ #include <vector> #include <cstdint> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/tri_vertex.h" namespace engine::fb { diff --git a/src/math/mat4.cpp b/src/math/mat4.cpp index 6418e9c..f1f28b7 100644 --- a/src/math/mat4.cpp +++ b/src/math/mat4.cpp @@ -1,11 +1,11 @@ #include "math/mat4.h" #include <array> #include <cmath> -#include "math/math_vector.h" +#include "math/vector.h" using namespace engine::math; -Mat4 Mat4::idty() { +Matrix4 Matrix4::idty() { return { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, @@ -14,7 +14,7 @@ Mat4 Mat4::idty() { }; } -Mat4 Mat4::translate(MathVector3 v) { +Matrix4 Matrix4::translate(Vector3 v) { return { 1.f, 0.f, 0.f, v.x, 0.f, 1.f, 0.f, v.y, @@ -22,7 +22,7 @@ Mat4 Mat4::translate(MathVector3 v) { 0.f, 0.f, 0.f, 1.f, }; } -Mat4 Mat4::scale(float fac) { +Matrix4 Matrix4::scale(float fac) { return { fac, 0.f, 0.f, 0.f, 0.f, fac, 0.f, 0.f, @@ -31,7 +31,7 @@ Mat4 Mat4::scale(float fac) { }; } -Mat4 Mat4::rot_x(float a) { +Matrix4 Matrix4::rot_x(float a) { float c = std::cos(a); float s = std::sin(a); return { @@ -42,7 +42,7 @@ Mat4 Mat4::rot_x(float a) { }; } -Mat4 Mat4::rot_y(float a) { +Matrix4 Matrix4::rot_y(float a) { float c = std::cos(a); float s = std::sin(a); return { @@ -53,7 +53,7 @@ Mat4 Mat4::rot_y(float a) { }; } -Mat4 Mat4::rot_z(float a) { +Matrix4 Matrix4::rot_z(float a) { float c = std::cos(a); float s = std::sin(a); return { @@ -64,7 +64,7 @@ Mat4 Mat4::rot_z(float a) { }; } -Mat4 Mat4::projection(float aspect_ratio, float min_z, float max_z) { +Matrix4 Matrix4::projection(float aspect_ratio, float min_z, float max_z) { return {{ aspect_ratio, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, @@ -73,11 +73,11 @@ Mat4 Mat4::projection(float aspect_ratio, float min_z, float max_z) { }}; } -Mat4 Mat4::operator+() { +Matrix4 Matrix4::operator+() { return *this; } -Mat4 Mat4::operator-() { +Matrix4 Matrix4::operator-() { return { -values[ 0], -values[ 1], -values[ 2], -values[ 3], -values[ 4], -values[ 5], -values[ 6], -values[ 7], @@ -86,7 +86,7 @@ Mat4 Mat4::operator-() { }; } -Mat4 Mat4::operator+(Mat4 m) { +Matrix4 Matrix4::operator+(Matrix4 m) { return { values[ 0] + m.values[ 0], values[ 1] + m.values[ 1], values[ 2] + m.values[ 2], values[ 3] + m.values[ 3], values[ 4] + m.values[ 4], values[ 5] + m.values[ 5], values[ 6] + m.values[ 6], values[ 7] + m.values[ 7], @@ -95,12 +95,12 @@ Mat4 Mat4::operator+(Mat4 m) { }; } -Mat4 Mat4::operator-(Mat4 m) { +Matrix4 Matrix4::operator-(Matrix4 m) { return *this + (-m); } -Mat4 Mat4::operator*(Mat4 m) { - Mat4 ret; +Matrix4 Matrix4::operator*(Matrix4 m) { + Matrix4 ret; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { ret.values[i * 4 + j] = 0.f; @@ -111,7 +111,7 @@ Mat4 Mat4::operator*(Mat4 m) { return ret; } -MathVector4 Mat4::operator*(MathVector4 v) { +Vector4 Matrix4::operator*(Vector4 v) { return { values[ 0] * v.x + values[ 1] * v.y + values[ 2] * v.z + values[ 3] * v.w, values[ 4] * v.x + values[ 5] * v.y + values[ 6] * v.z + values[ 7] * v.w, @@ -120,7 +120,7 @@ MathVector4 Mat4::operator*(MathVector4 v) { }; } -std::array<MathVector4, 4> Mat4::to_vecs() { +std::array<Vector4, 4> Matrix4::to_vecs() { return {{ { values[ 0], values[ 4], values[ 8], values[12] }, { values[ 1], values[ 5], values[ 9], values[13] }, @@ -129,7 +129,7 @@ std::array<MathVector4, 4> Mat4::to_vecs() { }}; } -Mat4 engine::math::operator*(float fac, Mat4 m) { +Matrix4 engine::math::operator*(float fac, Matrix4 m) { return { fac * m.values[ 0], fac * m.values[ 1], fac * m.values[ 2], fac * m.values[ 3], fac * m.values[ 4], fac * m.values[ 5], fac * m.values[ 6], fac * m.values[ 7], diff --git a/src/math/mat4.h b/src/math/mat4.h index d8b66c4..66d6cd2 100644 --- a/src/math/mat4.h +++ b/src/math/mat4.h @@ -2,32 +2,32 @@ #define MATH_MAT4_H #include <array> -#include "math/math_vector.h" +#include "math/vector.h" namespace engine::math { -class Mat4 { +class Matrix4 { public: - static Mat4 idty(); - static Mat4 translate(MathVector3 v); - static Mat4 scale(float fac); - static Mat4 rot_x(float a); - static Mat4 rot_y(float a); - static Mat4 rot_z(float a); - static Mat4 projection(float aspect_ratio, float min_z, float max_z); + static Matrix4 idty(); + static Matrix4 translate(Vector3 v); + static Matrix4 scale(float fac); + static Matrix4 rot_x(float a); + static Matrix4 rot_y(float a); + static Matrix4 rot_z(float a); + static Matrix4 projection(float aspect_ratio, float min_z, float max_z); std::array<float, 16> values; - Mat4 operator+(); - Mat4 operator-(); - Mat4 operator+(Mat4 m); - Mat4 operator-(Mat4 m); - Mat4 operator*(Mat4 m); - MathVector4 operator*(MathVector4 v); - std::array<MathVector4, 4> to_vecs(); + Matrix4 operator+(); + Matrix4 operator-(); + Matrix4 operator+(Matrix4 m); + Matrix4 operator-(Matrix4 m); + Matrix4 operator*(Matrix4 m); + Vector4 operator*(Vector4 v); + std::array<Vector4, 4> to_vecs(); }; -Mat4 operator*(float fac, Mat4 m); +Matrix4 operator*(float fac, Matrix4 m); } diff --git a/src/math/vector.cpp b/src/math/vector.cpp index aacff86..36e813d 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -1,97 +1,97 @@ -#include "math/math_vector.h" +#include "math/vector.h" #include <cmath> using namespace engine::math; -MathVector2::MathVector2() { +Vector2::Vector2() { } -MathVector2::MathVector2(float x, float y) : x{x}, y{y} { +Vector2::Vector2(float x, float y) : x{x}, y{y} { } -bool MathVector2::operator==(MathVector2 other) const { +bool Vector2::operator==(Vector2 other) const { return x == other.x && y == other.y; } -bool MathVector2::operator!=(MathVector2 other) const { +bool Vector2::operator!=(Vector2 other) const { return !(*this == other); } -MathVector2 MathVector2::operator+() const { +Vector2 Vector2::operator+() const { return *this; } -MathVector2 MathVector2::operator-() const { +Vector2 Vector2::operator-() const { return { -x, -y }; } -MathVector2 MathVector2::operator+(MathVector2 other) const { +Vector2 Vector2::operator+(Vector2 other) const { return { x + other.x, y + other.y }; } -MathVector2 MathVector2::operator-(MathVector2 other) const { +Vector2 Vector2::operator-(Vector2 other) const { return *this + (-other); } -float MathVector2::det(MathVector2 other) const { +float Vector2::det(Vector2 other) const { return this->x * other.y - other.x * this->y; } -MathVector2 MathVector2::round() const { +Vector2 Vector2::round() const { return { std::round(x), std::round(y) }; } -MathVector2 engine::math::operator*(float n, MathVector2 other) { +Vector2 engine::math::operator*(float n, Vector2 other) { return { n * other.x, n * other.y }; } -MathVector2 engine::math::operator*(MathVector2 other, float n) { +Vector2 engine::math::operator*(Vector2 other, float n) { return n * other; } -MathVector2 engine::math::operator/(MathVector2 other, float n) { +Vector2 engine::math::operator/(Vector2 other, float n) { return { other.x / n, other.y / n }; } -MathVector3::MathVector3() { +Vector3::Vector3() { } -MathVector3::MathVector3(float x, float y, float z) : x{x}, y{y}, z{z} { +Vector3::Vector3(float x, float y, float z) : x{x}, y{y}, z{z} { } -bool MathVector3::operator==(MathVector3 other) const { +bool Vector3::operator==(Vector3 other) const { return x == other.x && y == other.y && z == other.z; } -bool MathVector3::operator!=(MathVector3 other) const { +bool Vector3::operator!=(Vector3 other) const { return !(*this == other); } -MathVector3 MathVector3::operator+() const { +Vector3 Vector3::operator+() const { return *this; } -MathVector3 MathVector3::operator-() const { +Vector3 Vector3::operator-() const { return { -x, -y, -z }; } -MathVector3 MathVector3::operator+(MathVector3 other) const { +Vector3 Vector3::operator+(Vector3 other) const { return { x + other.x, y + other.y, z + other.z }; } -MathVector3 MathVector3::operator-(MathVector3 other) const { +Vector3 Vector3::operator-(Vector3 other) const { return *this + (-other); } -MathVector3 MathVector3::round() const { +Vector3 Vector3::round() const { return { std::round(x), std::round(y), std::round(z) }; } -MathVector2 MathVector3::xy() const { +Vector2 Vector3::xy() const { return { x, y }; } -MathVector3 MathVector3::cross(MathVector3 other) const { +Vector3 Vector3::cross(Vector3 other) const { return { y * other.z - z * other.y, z * other.x - x * other.z, @@ -99,77 +99,77 @@ MathVector3 MathVector3::cross(MathVector3 other) const { }; } -MathVector3 engine::math::operator*(float n, MathVector3 other) { +Vector3 engine::math::operator*(float n, Vector3 other) { return { n * other.x, n * other.y, n * other.z }; } -MathVector3 engine::math::operator*(MathVector3 other, float n) { +Vector3 engine::math::operator*(Vector3 other, float n) { return n * other; } -MathVector3 engine::math::operator/(MathVector3 other, float n) { +Vector3 engine::math::operator/(Vector3 other, float n) { return { other.x / n, other.y / n, other.z / n }; } -MathVector4::MathVector4() { +Vector4::Vector4() { } -MathVector4::MathVector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} { +Vector4::Vector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} { } -MathVector4::MathVector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} { +Vector4::Vector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} { } -MathVector4::MathVector4(MathVector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} { +Vector4::Vector4(Vector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} { } -MathVector4::MathVector4(MathVector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} { +Vector4::Vector4(Vector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} { } -bool MathVector4::operator==(MathVector4 other) const { +bool Vector4::operator==(Vector4 other) const { return x == other.x && y == other.y && z == other.z && w == other.w; } -bool MathVector4::operator!=(MathVector4 other) const { +bool Vector4::operator!=(Vector4 other) const { return !(*this == other); } -MathVector4 MathVector4::operator+() const { +Vector4 Vector4::operator+() const { return *this; } -MathVector4 MathVector4::operator-() const { +Vector4 Vector4::operator-() const { return { -x, -y, -z, -w }; } -MathVector4 MathVector4::operator+(MathVector4 other) const { +Vector4 Vector4::operator+(Vector4 other) const { return { x + other.x, y + other.y, z + other.z, w + other.w }; } -MathVector4 MathVector4::operator-(MathVector4 other) const { +Vector4 Vector4::operator-(Vector4 other) const { return *this + (-other); } -MathVector4 MathVector4::round() const { +Vector4 Vector4::round() const { return { std::round(x), std::round(y), std::round(z), std::round(w) }; } -MathVector3 MathVector4::xyz() const { +Vector3 Vector4::xyz() const { return { x, y, z }; } -MathVector3 MathVector4::div_by_w() const { +Vector3 Vector4::div_by_w() const { return xyz() / w; } -MathVector4 engine::math::operator*(float n, MathVector4 other) { +Vector4 engine::math::operator*(float n, Vector4 other) { return { n * other.x, n * other.y, n * other.z, n * other.w }; } -MathVector4 engine::math::operator*(MathVector4 other, float n) { +Vector4 engine::math::operator*(Vector4 other, float n) { return n * other; } -MathVector4 engine::math::operator/(MathVector4 other, float n) { +Vector4 engine::math::operator/(Vector4 other, float n) { return { other.x / n, other.y / n, other.z / n, other.w / n }; } diff --git a/src/math/vector.h b/src/math/vector.h index 28ae81e..8f7059a 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -1,73 +1,73 @@ -#ifndef MATH_MATH_VECTOR_H -#define MATH_MATH_VECTOR_H +#ifndef MATH_VECTOR_H +#define MATH_VECTOR_H namespace engine::math { -class MathVector2 { +class Vector2 { public: float x, y; - MathVector2(); - MathVector2(float x, float y); - bool operator==(MathVector2 other) const; - bool operator!=(MathVector2 other) const; - MathVector2 operator+() const; - MathVector2 operator-() const; - MathVector2 operator+(MathVector2 other) const; - MathVector2 operator-(MathVector2 other) const; - float det(MathVector2 other) const; - MathVector2 round() const; + Vector2(); + Vector2(float x, float y); + bool operator==(Vector2 other) const; + bool operator!=(Vector2 other) const; + Vector2 operator+() const; + Vector2 operator-() const; + Vector2 operator+(Vector2 other) const; + Vector2 operator-(Vector2 other) const; + float det(Vector2 other) const; + Vector2 round() const; }; -MathVector2 operator*(float n, MathVector2 other); -MathVector2 operator*(MathVector2 other, float n); -MathVector2 operator/(MathVector2 other, float n); +Vector2 operator*(float n, Vector2 other); +Vector2 operator*(Vector2 other, float n); +Vector2 operator/(Vector2 other, float n); -class MathVector3 { +class Vector3 { public: float x, y, z; - MathVector3(); - MathVector3(float x, float y, float z); - bool operator==(MathVector3 other) const; - bool operator!=(MathVector3 other) const; - MathVector3 operator+() const; - MathVector3 operator-() const; - MathVector3 operator+(MathVector3 other) const; - MathVector3 operator-(MathVector3 other) const; - MathVector3 round() const; - MathVector2 xy() const; - MathVector3 cross(MathVector3 other) const; + Vector3(); + Vector3(float x, float y, float z); + bool operator==(Vector3 other) const; + bool operator!=(Vector3 other) const; + Vector3 operator+() const; + Vector3 operator-() const; + Vector3 operator+(Vector3 other) const; + Vector3 operator-(Vector3 other) const; + Vector3 round() const; + Vector2 xy() const; + Vector3 cross(Vector3 other) const; }; -MathVector3 operator*(float n, MathVector3 other); -MathVector3 operator*(MathVector3 other, float n); -MathVector3 operator/(MathVector3 other, float n); +Vector3 operator*(float n, Vector3 other); +Vector3 operator*(Vector3 other, float n); +Vector3 operator/(Vector3 other, float n); -class MathVector4 { +class Vector4 { public: float x, y, z, w; - MathVector4(); - MathVector4(float x, float y, float z, float w); - MathVector4(float x, float y, float z); - MathVector4(MathVector3 v, float w); - MathVector4(MathVector3 v); - bool operator==(MathVector4 other) const; - bool operator!=(MathVector4 other) const; - MathVector4 operator+() const; - MathVector4 operator-() const; - MathVector4 operator+(MathVector4 other) const; - MathVector4 operator-(MathVector4 other) const; - MathVector4 round() const; - MathVector3 xyz() const; - MathVector3 div_by_w() const; + Vector4(); + Vector4(float x, float y, float z, float w); + Vector4(float x, float y, float z); + Vector4(Vector3 v, float w); + Vector4(Vector3 v); + bool operator==(Vector4 other) const; + bool operator!=(Vector4 other) const; + Vector4 operator+() const; + Vector4 operator-() const; + Vector4 operator+(Vector4 other) const; + Vector4 operator-(Vector4 other) const; + Vector4 round() const; + Vector3 xyz() const; + Vector3 div_by_w() const; }; -MathVector4 operator*(float n, MathVector4 other); -MathVector4 operator*(MathVector4 other, float n); -MathVector4 operator/(MathVector4 other, float n); +Vector4 operator*(float n, Vector4 other); +Vector4 operator*(Vector4 other, float n); +Vector4 operator/(Vector4 other, float n); } -#endif // MATH_MATH_VECTOR_H +#endif // MATH_VECTOR_H diff --git a/src/o3d/camera.cpp b/src/o3d/camera.cpp index 9ad2ac7..cbb3cd2 100644 --- a/src/o3d/camera.cpp +++ b/src/o3d/camera.cpp @@ -1,7 +1,7 @@ #include "o3d/camera.h" -#include "math/math_vector.h" +#include "math/vector.h" using namespace engine::o3d; -Camera::Camera(engine::math::MathVector3 loc, float rot_x, float rot_y, float rot_z) : loc{loc}, rot_x{rot_x}, rot_y{rot_y}, rot_z{rot_z} { +Camera::Camera(engine::math::Vector3 loc, float rot_x, float rot_y, float rot_z) : loc{loc}, rot_x{rot_x}, rot_y{rot_y}, rot_z{rot_z} { } diff --git a/src/o3d/camera.h b/src/o3d/camera.h index 1039f86..5d72d29 100644 --- a/src/o3d/camera.h +++ b/src/o3d/camera.h @@ -1,7 +1,7 @@ #ifndef O3D_CAMERA_H #define O3D_CAMERA_H -#include "math/math_vector.h" +#include "math/vector.h" namespace engine::o3d { @@ -10,10 +10,10 @@ class Scene; class Camera { public: Scene* scene = nullptr; - engine::math::MathVector3 loc; + engine::math::Vector3 loc; float rot_x, rot_y, rot_z; // TODO: replace by quaternions - Camera(engine::math::MathVector3 loc, float rot_x, float rot_y, float rot_z); + Camera(engine::math::Vector3 loc, float rot_x, float rot_y, float rot_z); }; } diff --git a/src/o3d/mesh.cpp b/src/o3d/mesh.cpp index 7da77aa..47a1ea2 100644 --- a/src/o3d/mesh.cpp +++ b/src/o3d/mesh.cpp @@ -1,7 +1,7 @@ #include "o3d/mesh.h" #include <vector> #include <array> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex.h" using namespace engine::o3d; @@ -9,14 +9,14 @@ using namespace engine::o3d; Mesh Mesh::cube() { return { { - { engine::math::MathVector3(-1.f, -1.f, -1.f), {} }, - { engine::math::MathVector3(+1.f, -1.f, -1.f), {} }, - { engine::math::MathVector3(-1.f, +1.f, -1.f), {} }, - { engine::math::MathVector3(+1.f, +1.f, -1.f), {} }, - { engine::math::MathVector3(-1.f, -1.f, +1.f), {} }, - { engine::math::MathVector3(+1.f, -1.f, +1.f), {} }, - { engine::math::MathVector3(-1.f, +1.f, +1.f), {} }, - { engine::math::MathVector3(+1.f, +1.f, +1.f), {} }, + { engine::math::Vector3(-1.f, -1.f, -1.f), {} }, + { engine::math::Vector3(+1.f, -1.f, -1.f), {} }, + { engine::math::Vector3(-1.f, +1.f, -1.f), {} }, + { engine::math::Vector3(+1.f, +1.f, -1.f), {} }, + { engine::math::Vector3(-1.f, -1.f, +1.f), {} }, + { engine::math::Vector3(+1.f, -1.f, +1.f), {} }, + { engine::math::Vector3(-1.f, +1.f, +1.f), {} }, + { engine::math::Vector3(+1.f, +1.f, +1.f), {} }, }, { { 0, 2, 3 }, { 0, 3, 1 }, // face 1 diff --git a/src/o3d/obj3d.cpp b/src/o3d/obj3d.cpp index 047bf3e..71fdf7d 100644 --- a/src/o3d/obj3d.cpp +++ b/src/o3d/obj3d.cpp @@ -1,9 +1,9 @@ #include "o3d/obj3d.h" -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/mesh.h" using namespace engine::o3d; -Object3D::Object3D(Mesh mesh, engine::math::MathVector3 loc, float scale, float rot_x, float rot_y, float rot_z) +Object3D::Object3D(Mesh mesh, engine::math::Vector3 loc, float scale, float rot_x, float rot_y, float rot_z) : mesh{mesh}, loc{loc}, scale{scale}, rot_x{rot_x}, rot_y{rot_y}, rot_z{rot_z} { } diff --git a/src/o3d/obj3d.h b/src/o3d/obj3d.h index 3a931b1..250b6bc 100644 --- a/src/o3d/obj3d.h +++ b/src/o3d/obj3d.h @@ -1,7 +1,7 @@ #ifndef O3D_OBJ3D_H #define O3D_OBJ3D_H -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/mesh.h" namespace engine::o3d { @@ -12,11 +12,11 @@ class Object3D { public: Scene* scene = nullptr; Mesh mesh; - engine::math::MathVector3 loc; + engine::math::Vector3 loc; float scale; float rot_x, rot_y, rot_z; - Object3D(Mesh mesh, engine::math::MathVector3 loc, float scale, float rot_x, float rot_y, float rot_z); + Object3D(Mesh mesh, engine::math::Vector3 loc, float scale, float rot_x, float rot_y, float rot_z); }; } diff --git a/src/o3d/tri_vertex.cpp b/src/o3d/tri_vertex.cpp index 07185f6..bda219a 100644 --- a/src/o3d/tri_vertex.cpp +++ b/src/o3d/tri_vertex.cpp @@ -1,6 +1,6 @@ #include "o3d/tri_vertex.h" #include <vector> -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex_data.h" #include "o3d/vertex.h" #include "o3d/tri_vertex.h" @@ -48,7 +48,7 @@ static void _crop_x(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n q3 = &t.vertex1; break; } - engine::math::MathVector3 dq2 = q1->point - q2->point; + engine::math::Vector3 dq2 = q1->point - q2->point; float fac2 = (x - q2->point.x) / dq2.x; Vertex3 r2{ { @@ -58,7 +58,7 @@ static void _crop_x(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n }, VertexData::lerp(q2->data, q1->data, fac2) }; - engine::math::MathVector3 dq3 = q1->point - q3->point; + engine::math::Vector3 dq3 = q1->point - q3->point; float fac3 = (x - q3->point.x) / dq3.x; Vertex3 r3{ { @@ -133,7 +133,7 @@ static void _crop_y(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n q3 = &t.vertex1; break; } - engine::math::MathVector3 dq2 = q1->point - q2->point; + engine::math::Vector3 dq2 = q1->point - q2->point; float fac2 = (y - q2->point.y) / dq2.y; Vertex3 r2{ { @@ -143,7 +143,7 @@ static void _crop_y(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n }, VertexData::lerp(q2->data, q1->data, fac2) }; - engine::math::MathVector3 dq3 = q1->point - q3->point; + engine::math::Vector3 dq3 = q1->point - q3->point; float fac3 = (y - q3->point.y) / dq3.y; Vertex3 r3{ { @@ -247,7 +247,7 @@ static void _crop_z(std::vector<TriangleVertex4>& tris, TriangleVertex4 t, int n q3 = &t.vertex1; break; } - engine::math::MathVector4 dq2 = q1->point - q2->point; + engine::math::Vector4 dq2 = q1->point - q2->point; float fac2 = (z - q2->point.z) / dq2.z; Vertex4 r2{ { @@ -258,7 +258,7 @@ static void _crop_z(std::vector<TriangleVertex4>& tris, TriangleVertex4 t, int n }, VertexData::lerp(q2->data, q1->data, fac2) }; - engine::math::MathVector4 dq3 = q1->point - q3->point; + engine::math::Vector4 dq3 = q1->point - q3->point; float fac3 = (z - q3->point.z) / dq3.z; Vertex4 r3{ { diff --git a/src/o3d/vertex.cpp b/src/o3d/vertex.cpp index 4da6aa4..641eef4 100644 --- a/src/o3d/vertex.cpp +++ b/src/o3d/vertex.cpp @@ -1,13 +1,13 @@ #include "o3d/vertex.h" -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex_data.h" using namespace engine::o3d; -Vertex3::Vertex3(engine::math::MathVector3 point, VertexData data) : point{point}, data{data} { +Vertex3::Vertex3(engine::math::Vector3 point, VertexData data) : point{point}, data{data} { } -Vertex4::Vertex4(engine::math::MathVector4 point, VertexData data) : point{point}, data{data} { +Vertex4::Vertex4(engine::math::Vector4 point, VertexData data) : point{point}, data{data} { } Vertex4::Vertex4(Vertex3 vertex) : point{vertex.point}, data{vertex.data} { diff --git a/src/o3d/vertex.h b/src/o3d/vertex.h index 66d073d..022fdf7 100644 --- a/src/o3d/vertex.h +++ b/src/o3d/vertex.h @@ -1,25 +1,25 @@ #ifndef O3D_VERTEX_H #define O3D_VERTEX_H -#include "math/math_vector.h" +#include "math/vector.h" #include "o3d/vertex_data.h" namespace engine::o3d { class Vertex3 { public: - engine::math::MathVector3 point; + engine::math::Vector3 point; VertexData data; - Vertex3(engine::math::MathVector3 point, VertexData data); + Vertex3(engine::math::Vector3 point, VertexData data); }; class Vertex4 { public: - engine::math::MathVector4 point; + engine::math::Vector4 point; VertexData data; - Vertex4(engine::math::MathVector4 point, VertexData data); + Vertex4(engine::math::Vector4 point, VertexData data); Vertex4(Vertex3 vertex); Vertex3 div_by_w() const; }; |