aboutsummaryrefslogtreecommitdiff
path: root/src/o3d
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2023-11-26 08:43:14 +0100
committervimene <vincent.menegaux@gmail.com>2023-11-26 08:43:14 +0100
commit5a1d67d1797a3db874e44500e13237d676843185 (patch)
tree17d0f1c2db6cc32fe40fdde4a081b96e8ad0ae13 /src/o3d
parentf63febed2a769d0c55192e192a20b8e39f162932 (diff)
downloadengine-5a1d67d1797a3db874e44500e13237d676843185.tar.gz
added namespaces, made every function in engine.cpp static and added warnings' flags
Diffstat (limited to 'src/o3d')
-rw-r--r--src/o3d/obj3d.cpp19
-rw-r--r--src/o3d/obj3d.h4
-rw-r--r--src/o3d/tri_vertex.cpp14
-rw-r--r--src/o3d/tri_vertex.h4
-rw-r--r--src/o3d/vertex.cpp6
-rw-r--r--src/o3d/vertex.h12
-rw-r--r--src/o3d/vertex_data.cpp2
-rw-r--r--src/o3d/vertex_data.h4
8 files changed, 45 insertions, 20 deletions
diff --git a/src/o3d/obj3d.cpp b/src/o3d/obj3d.cpp
index 584e304..9ccb93a 100644
--- a/src/o3d/obj3d.cpp
+++ b/src/o3d/obj3d.cpp
@@ -1,9 +1,12 @@
#include "o3d/obj3d.h"
#include <vector>
#include <array>
+#include "math/math_vector.h"
#include "o3d/vertex.h"
#include "o3d/tri_vertex.h"
+using namespace engine::o3d;
+
Object3D::TriangleVertex3Iterator::TriangleVertex3Iterator(const Object3D* obj, int face_ind) : obj{obj}, face_ind{face_ind} {
}
@@ -37,14 +40,14 @@ Object3D::TriangleVertex3Iterator::reference Object3D::TriangleVertex3Iterator::
Object3D Object3D::cube() {
return {
{
- { MathVector3(-1.f, -1.f, -1.f), {} },
- { MathVector3(+1.f, -1.f, -1.f), {} },
- { MathVector3(-1.f, +1.f, -1.f), {} },
- { MathVector3(+1.f, +1.f, -1.f), {} },
- { MathVector3(-1.f, -1.f, +1.f), {} },
- { MathVector3(+1.f, -1.f, +1.f), {} },
- { MathVector3(-1.f, +1.f, +1.f), {} },
- { 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::MathVector3(+1.f, +1.f, +1.f), {} },
},
{
{ 0, 2, 3 }, { 0, 3, 1 }, // face 1
diff --git a/src/o3d/obj3d.h b/src/o3d/obj3d.h
index c65a06b..795b337 100644
--- a/src/o3d/obj3d.h
+++ b/src/o3d/obj3d.h
@@ -7,6 +7,8 @@
#include "o3d/vertex.h"
#include "o3d/tri_vertex.h"
+namespace engine::o3d {
+
class Object3D {
public:
class TriangleVertex3Iterator {
@@ -41,4 +43,6 @@ class Object3D {
std::vector<std::array<int, 3>> faces;
};
+}
+
#endif // O3D_OBJ3D_H
diff --git a/src/o3d/tri_vertex.cpp b/src/o3d/tri_vertex.cpp
index 7b6b379..07185f6 100644
--- a/src/o3d/tri_vertex.cpp
+++ b/src/o3d/tri_vertex.cpp
@@ -5,6 +5,8 @@
#include "o3d/vertex.h"
#include "o3d/tri_vertex.h"
+using namespace engine::o3d;
+
TriangleVertex3::TriangleVertex3(Vertex3 vertex1, Vertex3 vertex2, Vertex3 vertex3) : vertex1{vertex1}, vertex2{vertex2}, vertex3{vertex3} {
}
@@ -46,7 +48,7 @@ static void _crop_x(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n
q3 = &t.vertex1;
break;
}
- MathVector3 dq2 = q1->point - q2->point;
+ engine::math::MathVector3 dq2 = q1->point - q2->point;
float fac2 = (x - q2->point.x) / dq2.x;
Vertex3 r2{
{
@@ -56,7 +58,7 @@ static void _crop_x(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n
},
VertexData::lerp(q2->data, q1->data, fac2)
};
- MathVector3 dq3 = q1->point - q3->point;
+ engine::math::MathVector3 dq3 = q1->point - q3->point;
float fac3 = (x - q3->point.x) / dq3.x;
Vertex3 r3{
{
@@ -131,7 +133,7 @@ static void _crop_y(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n
q3 = &t.vertex1;
break;
}
- MathVector3 dq2 = q1->point - q2->point;
+ engine::math::MathVector3 dq2 = q1->point - q2->point;
float fac2 = (y - q2->point.y) / dq2.y;
Vertex3 r2{
{
@@ -141,7 +143,7 @@ static void _crop_y(std::vector<TriangleVertex3>& tris, TriangleVertex3 t, int n
},
VertexData::lerp(q2->data, q1->data, fac2)
};
- MathVector3 dq3 = q1->point - q3->point;
+ engine::math::MathVector3 dq3 = q1->point - q3->point;
float fac3 = (y - q3->point.y) / dq3.y;
Vertex3 r3{
{
@@ -245,7 +247,7 @@ static void _crop_z(std::vector<TriangleVertex4>& tris, TriangleVertex4 t, int n
q3 = &t.vertex1;
break;
}
- MathVector4 dq2 = q1->point - q2->point;
+ engine::math::MathVector4 dq2 = q1->point - q2->point;
float fac2 = (z - q2->point.z) / dq2.z;
Vertex4 r2{
{
@@ -256,7 +258,7 @@ static void _crop_z(std::vector<TriangleVertex4>& tris, TriangleVertex4 t, int n
},
VertexData::lerp(q2->data, q1->data, fac2)
};
- MathVector4 dq3 = q1->point - q3->point;
+ engine::math::MathVector4 dq3 = q1->point - q3->point;
float fac3 = (z - q3->point.z) / dq3.z;
Vertex4 r3{
{
diff --git a/src/o3d/tri_vertex.h b/src/o3d/tri_vertex.h
index 91e20f5..368a5e0 100644
--- a/src/o3d/tri_vertex.h
+++ b/src/o3d/tri_vertex.h
@@ -4,6 +4,8 @@
#include "o3d/vertex.h"
#include <vector>
+namespace engine::o3d {
+
class TriangleVertex3 {
public:
Vertex3 vertex1;
@@ -26,4 +28,6 @@ class TriangleVertex4 {
TriangleVertex3 div_by_w() const;
};
+}
+
#endif // O3D_TRI_VERTEX_H
diff --git a/src/o3d/vertex.cpp b/src/o3d/vertex.cpp
index c3bddef..4da6aa4 100644
--- a/src/o3d/vertex.cpp
+++ b/src/o3d/vertex.cpp
@@ -2,10 +2,12 @@
#include "math/math_vector.h"
#include "o3d/vertex_data.h"
-Vertex3::Vertex3(MathVector3 point, VertexData data) : point{point}, data{data} {
+using namespace engine::o3d;
+
+Vertex3::Vertex3(engine::math::MathVector3 point, VertexData data) : point{point}, data{data} {
}
-Vertex4::Vertex4(MathVector4 point, VertexData data) : point{point}, data{data} {
+Vertex4::Vertex4(engine::math::MathVector4 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 27ca56a..66d073d 100644
--- a/src/o3d/vertex.h
+++ b/src/o3d/vertex.h
@@ -4,22 +4,26 @@
#include "math/math_vector.h"
#include "o3d/vertex_data.h"
+namespace engine::o3d {
+
class Vertex3 {
public:
- MathVector3 point;
+ engine::math::MathVector3 point;
VertexData data;
- Vertex3(MathVector3 point, VertexData data);
+ Vertex3(engine::math::MathVector3 point, VertexData data);
};
class Vertex4 {
public:
- MathVector4 point;
+ engine::math::MathVector4 point;
VertexData data;
- Vertex4(MathVector4 point, VertexData data);
+ Vertex4(engine::math::MathVector4 point, VertexData data);
Vertex4(Vertex3 vertex);
Vertex3 div_by_w() const;
};
+}
+
#endif // O3D_VERTEX_H
diff --git a/src/o3d/vertex_data.cpp b/src/o3d/vertex_data.cpp
index 8d6f77b..0957742 100644
--- a/src/o3d/vertex_data.cpp
+++ b/src/o3d/vertex_data.cpp
@@ -1,5 +1,7 @@
#include "o3d/vertex_data.h"
+using namespace engine::o3d;
+
VertexData VertexData::lerp(VertexData& vd1, VertexData& vd2, float s) {
return {};
}
diff --git a/src/o3d/vertex_data.h b/src/o3d/vertex_data.h
index 0000dda..dda881b 100644
--- a/src/o3d/vertex_data.h
+++ b/src/o3d/vertex_data.h
@@ -1,6 +1,8 @@
#ifndef O3D_VERTEX_DATA_H
#define O3D_VERTEX_DATA_H
+namespace engine::o3d {
+
class VertexData {
public:
static VertexData lerp(VertexData& vd1, VertexData& vd2, float s);
@@ -9,4 +11,6 @@ class VertexData {
VertexData();
};
+}
+
#endif // O3D_VERTEX_DATA_H