From dbccd866229a4b06d10fbafc3eb3343015caedba Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Nov 2023 16:09:41 -0700 Subject: checkpoint --- inc/model_instance.hpp | 13 +++++++------ inc/palette.hpp | 7 ++++--- inc/renderable.hpp | 2 +- inc/scene.hpp | 10 ++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) (limited to 'inc') diff --git a/inc/model_instance.hpp b/inc/model_instance.hpp index 059d3a5..997e9a6 100644 --- a/inc/model_instance.hpp +++ b/inc/model_instance.hpp @@ -5,17 +5,18 @@ #include "renderable.hpp" #include -class ModelInstance : Renderable { +class ModelInstance : public Renderable { private: + std::shared_ptr m_mesh; FIXED m_scale; - VECTOR m_rotation; // though technically "FIXED"'s, these are simply s32's - // where [0, 2pi] -> [0, 0xFFFF] in the x,y,z axes + 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 m_mesh; - public: - void render(std::shared_ptr scene_context); + ModelInstance(std::shared_ptr mesh, FIXED scale, VECTOR m_rotation, + VECTOR m_pos); + virtual void render(std::shared_ptr 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_context); + virtual void render(std::shared_ptr scene_context) = 0; }; #endif diff --git a/inc/scene.hpp b/inc/scene.hpp index 8e286db..05cdac0 100644 --- a/inc/scene.hpp +++ b/inc/scene.hpp @@ -2,13 +2,14 @@ #define SCENE_HPP #include "model_instance.hpp" +#include "renderable.hpp" #include "vector.hpp" #include #include class Scene { public: - usu::vector renderables; + usu::vector> renderables; std::tuple viewport_dimension; // std::tuple scene_dimension; @@ -16,8 +17,13 @@ public: FIXED z_plane; Scene(); - void render(); 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_ctx) { + for (std::shared_ptr renderable : scene_ctx->renderables) + renderable->render(scene_ctx); + } }; #endif // SCENE_HPP -- cgit v1.2.3-70-g09d2