diff options
author | Elizabeth (Lizzy) Hunt <elizabeth.hunt@simponic.xyz> | 2023-11-28 14:47:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 14:47:29 -0700 |
commit | 4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd (patch) | |
tree | 2d9eb3fbc17d453ee33e478bafb9936beff12eb3 /inc | |
parent | ebc517c800a90f6f0ed157e5c3bd7c3bd18165b5 (diff) | |
parent | 3197f9e40cd7079e19990c64c98de667e2457d75 (diff) | |
download | gbarubik-4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd.tar.gz gbarubik-4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd.zip |
Cube
Diffstat (limited to 'inc')
-rw-r--r-- | inc/mesh.hpp | 6 | ||||
-rw-r--r-- | inc/model_instance.hpp | 12 | ||||
-rw-r--r-- | inc/palette.hpp | 7 | ||||
-rw-r--r-- | inc/renderable.hpp | 2 | ||||
-rw-r--r-- | inc/scene.hpp | 29 |
5 files changed, 36 insertions, 20 deletions
diff --git a/inc/mesh.hpp b/inc/mesh.hpp index db465fb..91fa500 100644 --- a/inc/mesh.hpp +++ b/inc/mesh.hpp @@ -14,9 +14,9 @@ typedef struct TRIANGLE { } TRIANGLE; class Mesh { -protected: - usu::vector<VECTOR> m_vertices; - usu::vector<TRIANGLE> m_triangles; +public: + usu::vector<VECTOR> vertices; + usu::vector<TRIANGLE> triangles; }; #endif // MESH_HPP diff --git a/inc/model_instance.hpp b/inc/model_instance.hpp index a8bbee0..8126278 100644 --- a/inc/model_instance.hpp +++ b/inc/model_instance.hpp @@ -5,13 +5,19 @@ #include "renderable.hpp" #include <tonc.h> -class ModelInstance : Renderable { +class ModelInstance : public Renderable { private: + std::shared_ptr<Mesh> m_mesh; FIXED m_scale; - VECTOR m_rotation; + VECTOR m_rot; // though technically "FIXED"'s, these are simply s32's + // where [0, 2pi] -> [0, 0xFFFF] in the x,y,z axes VECTOR m_pos; - std::shared_ptr<Mesh> m_mesh; +public: + ModelInstance(std::shared_ptr<Mesh> mesh, FIXED scale, VECTOR m_rotation, + VECTOR m_pos); + void add_pos(VECTOR d_pos); + virtual void render(std::shared_ptr<Scene> scene_context); }; #endif // MODEL_INSTANCE_HPP diff --git a/inc/palette.hpp b/inc/palette.hpp index 1850835..e45e9cf 100644 --- a/inc/palette.hpp +++ b/inc/palette.hpp @@ -10,11 +10,12 @@ 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) { +void put_palette(std::uint16_t *palette_address) { toncset16(palette_address, CLR_BLACK, 1); - toncset16(palette_address + 1, CLR_WHITE, 1); + for (std::uint32_t i = 0; i < 6; ++i) + toncset16(palette_address + i + 1, cube_colors[i], 1); + // TODO: PALETTE GRADIENT IN ALPHA DIMENSION (BRIGHTNESS) } - }; // namespace palette #endif // PALETTE_HPP diff --git a/inc/renderable.hpp b/inc/renderable.hpp index 7f72e51..83b7596 100644 --- a/inc/renderable.hpp +++ b/inc/renderable.hpp @@ -7,7 +7,7 @@ class Scene; class Renderable { public: - virtual void render(std::shared_ptr<Scene> scene_context); + virtual void render(std::shared_ptr<Scene> scene_context) = 0; }; #endif diff --git a/inc/scene.hpp b/inc/scene.hpp index f84bcd7..6dd4c35 100644 --- a/inc/scene.hpp +++ b/inc/scene.hpp @@ -1,20 +1,29 @@ -#ifndef CANVAS_HPP -#define CANVAS_HPP +#ifndef SCENE_HPP +#define SCENE_HPP -#include "mesh.hpp" +#include "model_instance.hpp" +#include "renderable.hpp" #include "vector.hpp" #include <cstdint> +#include <tonc.h> class Scene { -private: - usu::vector<Mesh> meshes; - std::uint32_t width; - std::uint32_t height; - public: - Scene(); + usu::vector<std::shared_ptr<Renderable>> renderables; + std::tuple<std::uint32_t, std::uint32_t> + viewport_dimension; // <width, height> + std::tuple<std::uint32_t, std::uint32_t> scene_dimension; + VECTOR directional_light; + FIXED z_plane; - void render(); + Scene(); + POINT project_2d(VECTOR vertex); + POINT viewport_to_scene(POINT p); + void draw_line(POINT p0, POINT p1, std::uint8_t pal_idx); + static inline void render(std::shared_ptr<Scene> scene_ctx) { + for (std::shared_ptr<Renderable> renderable : scene_ctx->renderables) + renderable->render(scene_ctx); + } }; #endif // SCENE_HPP |