diff --git a/inc/model_instance.hpp b/inc/model_instance.hpp index 997e9a6..8126278 100644 --- a/inc/model_instance.hpp +++ b/inc/model_instance.hpp @@ -16,6 +16,7 @@ private: public: ModelInstance(std::shared_ptr mesh, FIXED scale, VECTOR m_rotation, VECTOR m_pos); + void add_pos(VECTOR d_pos); virtual void render(std::shared_ptr scene_context); }; diff --git a/src/cube.cpp b/src/cube.cpp index c181794..60422a2 100644 --- a/src/cube.cpp +++ b/src/cube.cpp @@ -1,8 +1,12 @@ #include "cube.hpp" Cube::Cube() { - for (std::uint8_t i = 0; i < 8; ++i) - vertices.add({(i >> 2) & 1, (i >> 1) & 1, i & 1}); + for (std::uint8_t i = 0; i < 8; ++i) { + VECTOR vertex = {int2fx((((i >> 2) & 1) << 1) - 1), + int2fx((((i >> 1) & 1) << 1) - 1), + int2fx(((i & 1) << 1) - 1)}; + vertices.add(vertex); + } triangles.add({{0, 4, 5}, 1}); triangles.add({{0, 1, 5}, 1}); diff --git a/src/main.cpp b/src/main.cpp index c08b584..cc21223 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,16 +16,21 @@ int main() { auto cube = std::shared_ptr((Mesh *)new Cube); - ModelInstance modelInstance(cube, int2fx(2), {0x0C7F, 0x0000, 0}, - {int2fx(0), 0, int2fx(0)}); + ModelInstance model_instance(cube, float2fx(0.25), {0, 0x0C00, 0}, + {int2fx(3), int2fx(3), int2fx(3)}); - auto modelInstancePtr = std::shared_ptr(&modelInstance); - scene->renderables.add(modelInstancePtr); + auto model_instance_ptr = std::shared_ptr(&model_instance); + scene->renderables.add(model_instance_ptr); + std::uint8_t frame = 0; while (1) { - - Scene::render(scene); - vid_flip(); + if (frame == 0) { + model_instance.add_pos({0, 0, float2fx(0.2)}); + M4_CLEAR(); + Scene::render(scene); + vid_flip(); + } + frame = (frame + 1) % 10; VBlankIntrWait(); } diff --git a/src/model_instance.cpp b/src/model_instance.cpp index 61204ff..db28243 100644 --- a/src/model_instance.cpp +++ b/src/model_instance.cpp @@ -40,9 +40,8 @@ void ModelInstance::render(std::shared_ptr scene_context) { usu::vector projected(m_mesh->vertices.size()); for (std::uint32_t i = 0; i < projected.size(); i++) { - VECTOR transformed = - m_mesh->vertices[i]; // rotate(m_mesh->vertices[i], m_rot); - // vec_add(&transformed, &transformed, &m_pos); + VECTOR transformed = rotate(m_mesh->vertices[i], m_rot); + vec_add(&transformed, &transformed, &m_pos); projected[i] = scene_context->project_2d(transformed); } @@ -57,3 +56,5 @@ void ModelInstance::render(std::shared_ptr scene_context) { scene_context->draw_line(v2, v0, triangle.color_idx); } } + +void ModelInstance::add_pos(VECTOR d_pos) { vec_add(&m_pos, &m_pos, &d_pos); }