summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-11-24 18:19:42 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-11-24 18:19:42 -0700
commitebc517c800a90f6f0ed157e5c3bd7c3bd18165b5 (patch)
tree781ab3e1aca5444fc0cdec56cb8c5b479d59c492
parent9e35115be8950e2891232027aaf4bef7be44ace2 (diff)
downloadgbarubik-ebc517c800a90f6f0ed157e5c3bd7c3bd18165b5.tar.gz
gbarubik-ebc517c800a90f6f0ed157e5c3bd7c3bd18165b5.zip
base 3d uml setup
-rw-r--r--inc/cube.hpp11
-rw-r--r--inc/mesh.hpp22
-rw-r--r--inc/model_instance.hpp17
-rw-r--r--inc/palette.hpp20
-rw-r--r--inc/renderable.hpp13
-rw-r--r--inc/scene.hpp20
-rw-r--r--src/cube.cpp6
-rw-r--r--src/mesh.hpp11
-rw-r--r--src/scene.cpp0
9 files changed, 120 insertions, 0 deletions
diff --git a/inc/cube.hpp b/inc/cube.hpp
new file mode 100644
index 0000000..363af14
--- /dev/null
+++ b/inc/cube.hpp
@@ -0,0 +1,11 @@
+#ifndef CUBE_HPP
+#define CUBE_HPP
+
+#include "mesh.hpp"
+
+class Cube : Mesh {
+public:
+ Cube();
+};
+
+#endif // CUBE_HPP
diff --git a/inc/mesh.hpp b/inc/mesh.hpp
new file mode 100644
index 0000000..db465fb
--- /dev/null
+++ b/inc/mesh.hpp
@@ -0,0 +1,22 @@
+#ifndef MESH_HPP
+#define MESH_HPP
+
+#include "vector.hpp"
+#include <memory>
+#include <tonc.h>
+#include <tuple>
+
+class Scene;
+
+typedef struct TRIANGLE {
+ std::tuple<std::uint8_t, std::uint8_t, std::uint8_t> vertex_indices;
+ std::uint8_t color_idx;
+} TRIANGLE;
+
+class Mesh {
+protected:
+ usu::vector<VECTOR> m_vertices;
+ usu::vector<TRIANGLE> m_triangles;
+};
+
+#endif // MESH_HPP
diff --git a/inc/model_instance.hpp b/inc/model_instance.hpp
new file mode 100644
index 0000000..a8bbee0
--- /dev/null
+++ b/inc/model_instance.hpp
@@ -0,0 +1,17 @@
+#ifndef MODEL_INSTANCE_HPP
+#define MODEL_INSTANCE_HPP
+
+#include "mesh.hpp"
+#include "renderable.hpp"
+#include <tonc.h>
+
+class ModelInstance : Renderable {
+private:
+ FIXED m_scale;
+ VECTOR m_rotation;
+ VECTOR m_pos;
+
+ std::shared_ptr<Mesh> m_mesh;
+};
+
+#endif // MODEL_INSTANCE_HPP
diff --git a/inc/palette.hpp b/inc/palette.hpp
new file mode 100644
index 0000000..1850835
--- /dev/null
+++ b/inc/palette.hpp
@@ -0,0 +1,20 @@
+#ifndef PALETTE_HPP
+#define PALETTE_HPP
+
+#include <cstdint>
+#include <tonc.h>
+
+namespace palette {
+
+constexpr std::uint8_t pal_len = 255;
+constexpr std::uint16_t cube_colors[6] = {CLR_WHITE, CLR_YELLOW, CLR_RED,
+ CLR_ORANGE, CLR_BLUE, CLR_GREEN};
+
+constexpr void put_palette(std::uint16_t *palette_address) {
+ toncset16(palette_address, CLR_BLACK, 1);
+ toncset16(palette_address + 1, CLR_WHITE, 1);
+}
+
+}; // namespace palette
+
+#endif // PALETTE_HPP
diff --git a/inc/renderable.hpp b/inc/renderable.hpp
new file mode 100644
index 0000000..7f72e51
--- /dev/null
+++ b/inc/renderable.hpp
@@ -0,0 +1,13 @@
+#ifndef RENDERABLE_HPP
+#define RENDERABLE_HPP
+
+#include <memory>
+
+class Scene;
+
+class Renderable {
+public:
+ virtual void render(std::shared_ptr<Scene> scene_context);
+};
+
+#endif
diff --git a/inc/scene.hpp b/inc/scene.hpp
new file mode 100644
index 0000000..f84bcd7
--- /dev/null
+++ b/inc/scene.hpp
@@ -0,0 +1,20 @@
+#ifndef CANVAS_HPP
+#define CANVAS_HPP
+
+#include "mesh.hpp"
+#include "vector.hpp"
+#include <cstdint>
+
+class Scene {
+private:
+ usu::vector<Mesh> meshes;
+ std::uint32_t width;
+ std::uint32_t height;
+
+public:
+ Scene();
+
+ void render();
+};
+
+#endif // SCENE_HPP
diff --git a/src/cube.cpp b/src/cube.cpp
new file mode 100644
index 0000000..fddc601
--- /dev/null
+++ b/src/cube.cpp
@@ -0,0 +1,6 @@
+#include "cube.hpp"
+
+Cube::Cube() {
+ for (std::uint8_t i = 0; i < 8; ++i)
+ m_vertices.add({(i >> 2) & 1, (i >> 1) & 1, i & 1});
+}
diff --git a/src/mesh.hpp b/src/mesh.hpp
new file mode 100644
index 0000000..55b414a
--- /dev/null
+++ b/src/mesh.hpp
@@ -0,0 +1,11 @@
+#include "mesh.hpp"
+#include "scene.hpp"
+#include <tuple>
+
+void Mesh::render(std::shared_ptr<Scene> scene_context) {
+ for (const TRIANGLE triangle : m_triangles) {
+ VECTOR v0 = m_vertices[std::get<0>(triangle.vertex_indices)];
+ VECTOR v1 = m_vertices[std::get<1>(triangle.vertex_indices)];
+ VECTOR v2 = m_vertices[std::get<2>(triangle.vertex_indices)];
+ }
+}
diff --git a/src/scene.cpp b/src/scene.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/scene.cpp