aboutsummaryrefslogtreecommitdiff
path: root/src/o3d
diff options
context:
space:
mode:
Diffstat (limited to 'src/o3d')
-rw-r--r--src/o3d/camera.cpp7
-rw-r--r--src/o3d/camera.h13
-rw-r--r--src/o3d/deriv_vertex.cpp11
-rw-r--r--src/o3d/deriv_vertex.h14
-rw-r--r--src/o3d/mesh.cpp30
-rw-r--r--src/o3d/mesh.h19
-rw-r--r--src/o3d/obj3d.cpp9
-rw-r--r--src/o3d/obj3d.h17
-rw-r--r--src/o3d/scene.cpp12
-rw-r--r--src/o3d/scene.h10
-rw-r--r--src/o3d/tri.cpp16
-rw-r--r--src/o3d/tri.h15
-rw-r--r--src/o3d/tri_deriv.cpp8
-rw-r--r--src/o3d/tri_deriv.h19
-rw-r--r--src/o3d/vertex.cpp9
-rw-r--r--src/o3d/vertex.h11
-rw-r--r--src/o3d/vertex_data.cpp20
-rw-r--r--src/o3d/vertex_data.h20
18 files changed, 63 insertions, 197 deletions
diff --git a/src/o3d/camera.cpp b/src/o3d/camera.cpp
deleted file mode 100644
index cbb3cd2..0000000
--- a/src/o3d/camera.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "o3d/camera.h"
-#include "math/vector.h"
-
-using namespace engine::o3d;
-
-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 5d72d29..27c31eb 100644
--- a/src/o3d/camera.h
+++ b/src/o3d/camera.h
@@ -1,19 +1,12 @@
#ifndef O3D_CAMERA_H
#define O3D_CAMERA_H
-#include "math/vector.h"
+#include "math/tform.h"
namespace engine::o3d {
-class Scene;
-
-class Camera {
- public:
- Scene* scene = nullptr;
- engine::math::Vector3 loc;
- float rot_x, rot_y, rot_z; // TODO: replace by quaternions
-
- Camera(engine::math::Vector3 loc, float rot_x, float rot_y, float rot_z);
+struct Camera {
+ engine::math::Transform transform;
};
}
diff --git a/src/o3d/deriv_vertex.cpp b/src/o3d/deriv_vertex.cpp
deleted file mode 100644
index 7123b1c..0000000
--- a/src/o3d/deriv_vertex.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "o3d/deriv_vertex.h"
-#include "math/vector.h"
-
-using namespace engine::o3d;
-
-DerivedVertex::DerivedVertex(engine::math::Vector4 vertex, float b0, float b1) : vertex{vertex}, b0{b0}, b1{b1} {
-}
-
-DerivedVertex DerivedVertex::div_by_w() const {
- return {vertex.div_by_w(), b0, b1};
-}
diff --git a/src/o3d/deriv_vertex.h b/src/o3d/deriv_vertex.h
index 7524f9b..c435a7e 100644
--- a/src/o3d/deriv_vertex.h
+++ b/src/o3d/deriv_vertex.h
@@ -5,13 +5,15 @@
namespace engine::o3d {
-class DerivedVertex {
- public:
- engine::math::Vector4 vertex;
- float b0, b1;
+using engine::math::Vector4;
- DerivedVertex(engine::math::Vector4 vertex, float b0, float b1);
- DerivedVertex div_by_w() const;
+struct DerivedVertex {
+ Vector4 vertex;
+ float b0, b1;
+
+ constexpr DerivedVertex div_by_w() const & {
+ return {vertex.div_by_w(), b0, b1};
+ }
};
}
diff --git a/src/o3d/mesh.cpp b/src/o3d/mesh.cpp
index 2dba328..60c7f8b 100644
--- a/src/o3d/mesh.cpp
+++ b/src/o3d/mesh.cpp
@@ -6,29 +6,6 @@
using namespace engine::o3d;
-// Mesh Mesh::cube() {
-// return {
-// {
-// { 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
-// { 0, 4, 6 }, { 0, 6, 2 }, // face 2
-// { 0, 1, 5 }, { 0, 5, 4 }, // face 3
-// { 7, 6, 4 }, { 7, 4, 5 }, // face 4
-// { 7, 3, 2 }, { 7, 2, 6 }, // face 5
-// { 7, 5, 1 }, { 7, 1, 3 }, // face 6
-// }
-// };
-// }
-
Mesh Mesh::plane() {
return {
{
@@ -52,10 +29,3 @@ Mesh Mesh::plane() {
}
};
}
-
-Mesh::Mesh(std::vector<engine::math::Vector4> vertices,
- std::vector<engine::math::Vector3> normals,
- std::vector<VertexData> vertices_data,
- std::vector<std::array<std::array<std::size_t, 3>, 3>> indices)
- : vertices{vertices}, normals{normals}, vertices_data{vertices_data}, indices{indices} {
-}
diff --git a/src/o3d/mesh.h b/src/o3d/mesh.h
index 4aad0e4..1c70ca4 100644
--- a/src/o3d/mesh.h
+++ b/src/o3d/mesh.h
@@ -10,20 +10,15 @@
namespace engine::o3d {
-class Mesh {
- public:
-// static Mesh cube(); // this function should not be in this file
- static Mesh plane(); // this function should not be in this file
+using engine::math::Vector3, engine::math::Vector4;
- std::vector<engine::math::Vector4> vertices;
- std::vector<engine::math::Vector3> normals;
- std::vector<VertexData> vertices_data;
- std::vector<std::array<std::array<std::size_t, 3>, 3>> indices;
+struct Mesh {
+ static Mesh plane();
- Mesh(std::vector<engine::math::Vector4> vertices,
- std::vector<engine::math::Vector3> normals,
- std::vector<VertexData> vertices_data,
- std::vector<std::array<std::array<std::size_t, 3>, 3>> indices);
+ std::vector<Vector4> vertices;
+ std::vector<Vector3> normals;
+ std::vector<VertexData> vertices_data;
+ std::vector<std::array<std::array<std::size_t, 3>, 3>> indices;
};
}
diff --git a/src/o3d/obj3d.cpp b/src/o3d/obj3d.cpp
deleted file mode 100644
index 71fdf7d..0000000
--- a/src/o3d/obj3d.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "o3d/obj3d.h"
-#include "math/vector.h"
-#include "o3d/mesh.h"
-
-using namespace engine::o3d;
-
-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 250b6bc..9f407f9 100644
--- a/src/o3d/obj3d.h
+++ b/src/o3d/obj3d.h
@@ -1,22 +1,15 @@
#ifndef O3D_OBJ3D_H
#define O3D_OBJ3D_H
-#include "math/vector.h"
+#include <type_traits>
+#include "math/tform.h"
#include "o3d/mesh.h"
namespace engine::o3d {
-class Scene;
-
-class Object3D {
- public:
- Scene* scene = nullptr;
- Mesh mesh;
- engine::math::Vector3 loc;
- float scale;
- float rot_x, rot_y, rot_z;
-
- Object3D(Mesh mesh, engine::math::Vector3 loc, float scale, float rot_x, float rot_y, float rot_z);
+struct Object3D {
+ Mesh mesh;
+ math::Transform transform;
};
}
diff --git a/src/o3d/scene.cpp b/src/o3d/scene.cpp
deleted file mode 100644
index 50f83be..0000000
--- a/src/o3d/scene.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "o3d/scene.h"
-#include <vector>
-#include "o3d/camera.h"
-#include "o3d/obj3d.h"
-
-using namespace engine::o3d;
-
-Scene::Scene(Camera camera, std::vector<Object3D> objs) : camera{camera}, objs{objs} {
- this->camera.scene = this;
- for (auto& obj : this->objs)
- obj.scene = this;
-}
diff --git a/src/o3d/scene.h b/src/o3d/scene.h
index 3759cfb..3b9131c 100644
--- a/src/o3d/scene.h
+++ b/src/o3d/scene.h
@@ -2,17 +2,15 @@
#define O3D_SCENE_H
#include <vector>
+#include <type_traits>
#include "o3d/obj3d.h"
#include "o3d/camera.h"
namespace engine::o3d {
-class Scene {
- public:
- Camera camera;
- std::vector<Object3D> objs;
-
- Scene(Camera camera, std::vector<Object3D> objs);
+struct Scene {
+ Camera camera;
+ std::vector<Object3D> objs;
};
}
diff --git a/src/o3d/tri.cpp b/src/o3d/tri.cpp
deleted file mode 100644
index 73410bf..0000000
--- a/src/o3d/tri.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "o3d/tri.h"
-#include <vector>
-#include "math/vector.h"
-#include "o3d/vertex_data.h"
-#include "o3d/deriv_vertex.h"
-#include "o3d/vertex.h"
-#include "o3d/tri_deriv.h"
-
-using namespace engine::o3d;
-
-Triangle::Triangle(Vertex vertex1, Vertex vertex2, Vertex vertex3) : vertex1{vertex1}, vertex2{vertex2}, vertex3{vertex3} {
-}
-
-TriangleDerived Triangle::to_derived() const {
- return {{vertex1.vertex, 1.f, 0.f}, {vertex2.vertex, 0.f, 1.f}, {vertex3.vertex, 0.f, 0.f}};
-}
diff --git a/src/o3d/tri.h b/src/o3d/tri.h
index 7fa37fe..4b50f91 100644
--- a/src/o3d/tri.h
+++ b/src/o3d/tri.h
@@ -3,19 +3,18 @@
#include <vector>
#include "o3d/vertex.h"
-#include "o3d/tri.h"
#include "o3d/tri_deriv.h"
namespace engine::o3d {
-class Triangle {
- public:
- Vertex vertex1;
- Vertex vertex2;
- Vertex vertex3;
+struct Triangle {
+ Vertex vertex1;
+ Vertex vertex2;
+ Vertex vertex3;
- Triangle(Vertex vertex1, Vertex vertex2, Vertex vertex3);
- TriangleDerived to_derived() const;
+ constexpr TriangleDerived to_derived() const & {
+ return {{vertex1.vertex, 1.f, 0.f}, {vertex2.vertex, 0.f, 1.f}, {vertex3.vertex, 0.f, 0.f}};
+ }
};
}
diff --git a/src/o3d/tri_deriv.cpp b/src/o3d/tri_deriv.cpp
index 81f60a0..b4184bc 100644
--- a/src/o3d/tri_deriv.cpp
+++ b/src/o3d/tri_deriv.cpp
@@ -5,10 +5,6 @@
using namespace engine::o3d;
-TriangleDerived::TriangleDerived(DerivedVertex derived_vertex1, DerivedVertex derived_vertex2, DerivedVertex derived_vertex3)
- : derived_vertex1{derived_vertex1}, derived_vertex2{derived_vertex2}, derived_vertex3{derived_vertex3} {
-}
-
#define P1_OUT 1
#define P2_OUT 2
#define P3_OUT 4
@@ -315,7 +311,3 @@ std::vector<TriangleDerived> TriangleDerived::crop_z_out(float z1, float z2) con
#undef P1_OUT
#undef P2_OUT
#undef P3_OUT
-
-TriangleDerived TriangleDerived::div_by_w() const {
- return {derived_vertex1.div_by_w(), derived_vertex2.div_by_w(), derived_vertex3.div_by_w()};
-}
diff --git a/src/o3d/tri_deriv.h b/src/o3d/tri_deriv.h
index 201539b..16a21f8 100644
--- a/src/o3d/tri_deriv.h
+++ b/src/o3d/tri_deriv.h
@@ -7,16 +7,17 @@
namespace engine::o3d {
-class TriangleDerived {
- public:
- DerivedVertex derived_vertex1;
- DerivedVertex derived_vertex2;
- DerivedVertex derived_vertex3;
+struct TriangleDerived {
+ DerivedVertex derived_vertex1;
+ DerivedVertex derived_vertex2;
+ DerivedVertex derived_vertex3;
- TriangleDerived(DerivedVertex derived_vertex1, DerivedVertex derived_vertex2, DerivedVertex derived_vertex3);
- std::vector<TriangleDerived> perspective_crop_xy_out(float x1, float x2, float y1, float y2) const;
- std::vector<TriangleDerived> crop_z_out(float z1, float z2) const;
- TriangleDerived div_by_w() const;
+ std::vector<TriangleDerived> perspective_crop_xy_out(float x1, float x2, float y1, float y2) const;
+ std::vector<TriangleDerived> crop_z_out(float z1, float z2) const;
+
+ constexpr TriangleDerived div_by_w() const & {
+ return {derived_vertex1.div_by_w(), derived_vertex2.div_by_w(), derived_vertex3.div_by_w()};
+ }
};
}
diff --git a/src/o3d/vertex.cpp b/src/o3d/vertex.cpp
deleted file mode 100644
index 5845e27..0000000
--- a/src/o3d/vertex.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "o3d/vertex.h"
-#include "math/vector.h"
-#include "o3d/vertex_data.h"
-
-using namespace engine::o3d;
-
-Vertex::Vertex(engine::math::Vector4 vertex, engine::math::Vector3 normal, VertexData data)
- : vertex{vertex}, normal{normal}, data{data} {
-}
diff --git a/src/o3d/vertex.h b/src/o3d/vertex.h
index 1247fc8..438f8b3 100644
--- a/src/o3d/vertex.h
+++ b/src/o3d/vertex.h
@@ -6,13 +6,12 @@
namespace engine::o3d {
-class Vertex {
- public:
- engine::math::Vector4 vertex;
- engine::math::Vector3 normal;
- VertexData data;
+using engine::math::Vector3, engine::math::Vector4;
- Vertex(engine::math::Vector4 vertex, engine::math::Vector3 normal, VertexData data);
+struct Vertex {
+ Vector4 vertex;
+ Vector3 normal;
+ VertexData data;
};
}
diff --git a/src/o3d/vertex_data.cpp b/src/o3d/vertex_data.cpp
deleted file mode 100644
index b05e382..0000000
--- a/src/o3d/vertex_data.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "o3d/vertex_data.h"
-
-using namespace engine::o3d;
-
-VertexData VertexData::lerp(const VertexData& vd1, const VertexData& vd2, float b0) {
- return {
- b0 * vd1.tx + (1.f - b0) * vd2.tx,
- b0 * vd1.ty + (1.f - b0) * vd2.ty
- };
-}
-
-VertexData VertexData::bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float b0, float b1) {
- return {
- b0 * vd1.tx + b1 * vd2.tx + (1.f - b0 - b1) * vd3.tx,
- b0 * vd1.ty + b1 * vd2.ty + (1.f - b0 - b1) * vd3.ty
- };
-}
-
-VertexData::VertexData(float tx, float ty) : tx{tx}, ty{ty} {
-}
diff --git a/src/o3d/vertex_data.h b/src/o3d/vertex_data.h
index b8ed14c..71f42cd 100644
--- a/src/o3d/vertex_data.h
+++ b/src/o3d/vertex_data.h
@@ -3,14 +3,22 @@
namespace engine::o3d {
-class VertexData {
- public:
- static VertexData lerp(const VertexData& vd1, const VertexData& vd2, float b0);
- static VertexData bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float b0, float b1);
+struct VertexData {
+ static constexpr VertexData lerp(const VertexData& vd1, const VertexData& vd2, float b0) {
+ return {
+ b0 * vd1.tx + (1.f - b0) * vd2.tx,
+ b0 * vd1.ty + (1.f - b0) * vd2.ty
+ };
+ }
- float tx, ty;
+ static constexpr VertexData bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float b0, float b1) {
+ return {
+ b0 * vd1.tx + b1 * vd2.tx + (1.f - b0 - b1) * vd3.tx,
+ b0 * vd1.ty + b1 * vd2.ty + (1.f - b0 - b1) * vd3.ty
+ };
+ }
- VertexData(float tx, float ty);
+ float tx, ty;
};
}