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 +#include +#include + +class Scene; + +typedef struct TRIANGLE { + std::tuple vertex_indices; + std::uint8_t color_idx; +} TRIANGLE; + +class Mesh { +protected: + usu::vector m_vertices; + usu::vector 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 + +class ModelInstance : Renderable { +private: + FIXED m_scale; + VECTOR m_rotation; + VECTOR m_pos; + + std::shared_ptr 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 +#include + +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 + +class Scene; + +class Renderable { +public: + virtual void render(std::shared_ptr 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 + +class Scene { +private: + usu::vector 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 + +void Mesh::render(std::shared_ptr 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