draw the whole cube

This commit is contained in:
Elizabeth Hunt 2023-11-28 14:39:20 -07:00
parent 1b96b0211e
commit 3197f9e40c
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
4 changed files with 23 additions and 12 deletions

View File

@ -16,6 +16,7 @@ private:
public: public:
ModelInstance(std::shared_ptr<Mesh> mesh, FIXED scale, VECTOR m_rotation, ModelInstance(std::shared_ptr<Mesh> mesh, FIXED scale, VECTOR m_rotation,
VECTOR m_pos); VECTOR m_pos);
void add_pos(VECTOR d_pos);
virtual void render(std::shared_ptr<Scene> scene_context); virtual void render(std::shared_ptr<Scene> scene_context);
}; };

View File

@ -1,8 +1,12 @@
#include "cube.hpp" #include "cube.hpp"
Cube::Cube() { Cube::Cube() {
for (std::uint8_t i = 0; i < 8; ++i) for (std::uint8_t i = 0; i < 8; ++i) {
vertices.add({(i >> 2) & 1, (i >> 1) & 1, i & 1}); 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, 4, 5}, 1});
triangles.add({{0, 1, 5}, 1}); triangles.add({{0, 1, 5}, 1});

View File

@ -16,16 +16,21 @@ int main() {
auto cube = std::shared_ptr<Mesh>((Mesh *)new Cube); auto cube = std::shared_ptr<Mesh>((Mesh *)new Cube);
ModelInstance modelInstance(cube, int2fx(2), {0x0C7F, 0x0000, 0}, ModelInstance model_instance(cube, float2fx(0.25), {0, 0x0C00, 0},
{int2fx(0), 0, int2fx(0)}); {int2fx(3), int2fx(3), int2fx(3)});
auto modelInstancePtr = std::shared_ptr<Renderable>(&modelInstance); auto model_instance_ptr = std::shared_ptr<Renderable>(&model_instance);
scene->renderables.add(modelInstancePtr); scene->renderables.add(model_instance_ptr);
std::uint8_t frame = 0;
while (1) { while (1) {
if (frame == 0) {
Scene::render(scene); model_instance.add_pos({0, 0, float2fx(0.2)});
vid_flip(); M4_CLEAR();
Scene::render(scene);
vid_flip();
}
frame = (frame + 1) % 10;
VBlankIntrWait(); VBlankIntrWait();
} }

View File

@ -40,9 +40,8 @@ void ModelInstance::render(std::shared_ptr<Scene> scene_context) {
usu::vector<POINT> projected(m_mesh->vertices.size()); usu::vector<POINT> projected(m_mesh->vertices.size());
for (std::uint32_t i = 0; i < projected.size(); i++) { for (std::uint32_t i = 0; i < projected.size(); i++) {
VECTOR transformed = VECTOR transformed = rotate(m_mesh->vertices[i], m_rot);
m_mesh->vertices[i]; // rotate(m_mesh->vertices[i], m_rot); vec_add(&transformed, &transformed, &m_pos);
// vec_add(&transformed, &transformed, &m_pos);
projected[i] = scene_context->project_2d(transformed); projected[i] = scene_context->project_2d(transformed);
} }
@ -57,3 +56,5 @@ void ModelInstance::render(std::shared_ptr<Scene> scene_context) {
scene_context->draw_line(v2, v0, triangle.color_idx); scene_context->draw_line(v2, v0, triangle.color_idx);
} }
} }
void ModelInstance::add_pos(VECTOR d_pos) { vec_add(&m_pos, &m_pos, &d_pos); }