base 3d uml setup

This commit is contained in:
Elizabeth Hunt 2023-11-24 18:19:42 -07:00
parent 9e35115be8
commit ebc517c800
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
9 changed files with 120 additions and 0 deletions

11
inc/cube.hpp Normal file
View File

@ -0,0 +1,11 @@
#ifndef CUBE_HPP
#define CUBE_HPP
#include "mesh.hpp"
class Cube : Mesh {
public:
Cube();
};
#endif // CUBE_HPP

22
inc/mesh.hpp Normal file
View File

@ -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

17
inc/model_instance.hpp Normal file
View File

@ -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

20
inc/palette.hpp Normal file
View File

@ -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

13
inc/renderable.hpp Normal file
View File

@ -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

20
inc/scene.hpp Normal file
View File

@ -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

6
src/cube.cpp Normal file
View File

@ -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});
}

11
src/mesh.hpp Normal file
View File

@ -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)];
}
}

0
src/scene.cpp Normal file
View File