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.h21
-rw-r--r--src/o3d/mesh.cpp33
-rw-r--r--src/o3d/mesh.h23
-rw-r--r--src/o3d/obj3d.cpp69
-rw-r--r--src/o3d/obj3d.h44
-rw-r--r--src/o3d/scene.cpp12
-rw-r--r--src/o3d/scene.h20
-rw-r--r--src/o3d/vertex_data.cpp8
9 files changed, 137 insertions, 100 deletions
diff --git a/src/o3d/camera.cpp b/src/o3d/camera.cpp
new file mode 100644
index 0000000..9ad2ac7
--- /dev/null
+++ b/src/o3d/camera.cpp
@@ -0,0 +1,7 @@
+#include "o3d/camera.h"
+#include "math/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} {
+}
diff --git a/src/o3d/camera.h b/src/o3d/camera.h
new file mode 100644
index 0000000..1039f86
--- /dev/null
+++ b/src/o3d/camera.h
@@ -0,0 +1,21 @@
+#ifndef O3D_CAMERA_H
+#define O3D_CAMERA_H
+
+#include "math/math_vector.h"
+
+namespace engine::o3d {
+
+class Scene;
+
+class Camera {
+ public:
+ Scene* scene = nullptr;
+ engine::math::MathVector3 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);
+};
+
+}
+
+#endif // O3D_CAMERA_H
diff --git a/src/o3d/mesh.cpp b/src/o3d/mesh.cpp
new file mode 100644
index 0000000..7da77aa
--- /dev/null
+++ b/src/o3d/mesh.cpp
@@ -0,0 +1,33 @@
+#include "o3d/mesh.h"
+#include <vector>
+#include <array>
+#include "math/math_vector.h"
+#include "o3d/vertex.h"
+
+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), {} },
+ },
+ {
+ { 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(std::vector<Vertex3> pts, std::vector<std::array<int, 3>> faces) : pts{pts}, faces{faces} {
+}
diff --git a/src/o3d/mesh.h b/src/o3d/mesh.h
new file mode 100644
index 0000000..579c8b2
--- /dev/null
+++ b/src/o3d/mesh.h
@@ -0,0 +1,23 @@
+#ifndef O3D_MESH_H
+#define O3D_MESH_H
+
+#include <vector>
+#include <array>
+#include <iterator>
+#include "o3d/vertex.h"
+
+namespace engine::o3d {
+
+class Mesh {
+ public:
+ static Mesh cube(); // this function should not be in this file
+
+ std::vector<Vertex3> pts;
+ std::vector<std::array<int, 3>> faces;
+
+ Mesh(std::vector<Vertex3> pts, std::vector<std::array<int, 3>> faces);
+};
+
+}
+
+#endif // O3D_MESH_H
diff --git a/src/o3d/obj3d.cpp b/src/o3d/obj3d.cpp
index 9ccb93a..047bf3e 100644
--- a/src/o3d/obj3d.cpp
+++ b/src/o3d/obj3d.cpp
@@ -1,72 +1,9 @@
#include "o3d/obj3d.h"
-#include <vector>
-#include <array>
#include "math/math_vector.h"
-#include "o3d/vertex.h"
-#include "o3d/tri_vertex.h"
+#include "o3d/mesh.h"
using namespace engine::o3d;
-Object3D::TriangleVertex3Iterator::TriangleVertex3Iterator(const Object3D* obj, int face_ind) : obj{obj}, face_ind{face_ind} {
-}
-
-Object3D::TriangleVertex3Iterator& Object3D::TriangleVertex3Iterator::operator++() {
- face_ind++;
- return *this;
-}
-
-Object3D::TriangleVertex3Iterator Object3D::TriangleVertex3Iterator::operator++(int) {
- TriangleVertex3Iterator retval = *this;
- ++(*this);
- return retval;
-}
-
-bool Object3D::TriangleVertex3Iterator::operator==(TriangleVertex3Iterator other) const {
- return obj == other.obj && face_ind == other.face_ind;
-}
-
-bool Object3D::TriangleVertex3Iterator::operator!=(TriangleVertex3Iterator other) const {
- return !(*this == other);
-}
-
-Object3D::TriangleVertex3Iterator::reference Object3D::TriangleVertex3Iterator::operator*() const {
- return {
- obj->pts[obj->faces[face_ind][0]],
- obj->pts[obj->faces[face_ind][1]],
- obj->pts[obj->faces[face_ind][2]]
- };
-}
-
-Object3D Object3D::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), {} },
- },
- {
- { 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
- }
- };
-}
-
-Object3D::Object3D(std::vector<Vertex3> pts, std::vector<std::array<int, 3>> faces) : pts{pts}, faces{faces} {
-}
-
-Object3D::TriangleVertex3Iterator Object3D::begin() {
- return Object3D::TriangleVertex3Iterator{this};
-}
-
-Object3D::TriangleVertex3Iterator Object3D::end() {
- return Object3D::TriangleVertex3Iterator{this, static_cast<int>(faces.size())};
+Object3D::Object3D(Mesh mesh, engine::math::MathVector3 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 795b337..3a931b1 100644
--- a/src/o3d/obj3d.h
+++ b/src/o3d/obj3d.h
@@ -1,46 +1,22 @@
#ifndef O3D_OBJ3D_H
#define O3D_OBJ3D_H
-#include <vector>
-#include <array>
-#include <iterator>
-#include "o3d/vertex.h"
-#include "o3d/tri_vertex.h"
+#include "math/math_vector.h"
+#include "o3d/mesh.h"
namespace engine::o3d {
+class Scene;
+
class Object3D {
public:
- class TriangleVertex3Iterator {
- public:
- using iterator_category = std::input_iterator_tag;
- using value_type = TriangleVertex3;
- using difference_type = TriangleVertex3;
- using pointer = const TriangleVertex3*;
- using reference = TriangleVertex3;
-
- explicit TriangleVertex3Iterator(const Object3D* obj, int face_ind = 0);
- TriangleVertex3Iterator& operator++();
- TriangleVertex3Iterator operator++(int);
- bool operator==(TriangleVertex3Iterator other) const;
- bool operator!=(TriangleVertex3Iterator other) const;
- reference operator*() const;
-
- private:
- const Object3D* obj;
- int face_ind;
-
- };
-
- static Object3D cube(); // this function should not be in this file
-
- Object3D(std::vector<Vertex3> pts, std::vector<std::array<int, 3>> faces);
- TriangleVertex3Iterator begin();
- TriangleVertex3Iterator end();
+ Scene* scene = nullptr;
+ Mesh mesh;
+ engine::math::MathVector3 loc;
+ float scale;
+ float rot_x, rot_y, rot_z;
- private:
- std::vector<Vertex3> pts;
- std::vector<std::array<int, 3>> faces;
+ Object3D(Mesh mesh, engine::math::MathVector3 loc, float scale, float rot_x, float rot_y, float rot_z);
};
}
diff --git a/src/o3d/scene.cpp b/src/o3d/scene.cpp
new file mode 100644
index 0000000..aba25dc
--- /dev/null
+++ b/src/o3d/scene.cpp
@@ -0,0 +1,12 @@
+#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
new file mode 100644
index 0000000..3759cfb
--- /dev/null
+++ b/src/o3d/scene.h
@@ -0,0 +1,20 @@
+#ifndef O3D_SCENE_H
+#define O3D_SCENE_H
+
+#include <vector>
+#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);
+};
+
+}
+
+#endif // O3D_SCENE_H
diff --git a/src/o3d/vertex_data.cpp b/src/o3d/vertex_data.cpp
index 0957742..4e0ab04 100644
--- a/src/o3d/vertex_data.cpp
+++ b/src/o3d/vertex_data.cpp
@@ -3,10 +3,18 @@
using namespace engine::o3d;
VertexData VertexData::lerp(VertexData& vd1, VertexData& vd2, float s) {
+ (void) vd1;
+ (void) vd2;
+ (void) s;
return {};
}
VertexData VertexData::bilerp(VertexData& vd1, VertexData& vd2, VertexData& vd3, float s, float t) {
+ (void) vd1;
+ (void) vd2;
+ (void) vd3;
+ (void) s;
+ (void) t;
return {};
}