draw the whole cube
This commit is contained in:
parent
1b96b0211e
commit
3197f9e40c
@ -16,6 +16,7 @@ private:
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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});
|
||||
|
19
src/main.cpp
19
src/main.cpp
@ -16,16 +16,21 @@ int main() {
|
||||
|
||||
auto cube = std::shared_ptr<Mesh>((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<Renderable>(&modelInstance);
|
||||
scene->renderables.add(modelInstancePtr);
|
||||
auto model_instance_ptr = std::shared_ptr<Renderable>(&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();
|
||||
}
|
||||
|
@ -40,9 +40,8 @@ void ModelInstance::render(std::shared_ptr<Scene> scene_context) {
|
||||
usu::vector<POINT> 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> 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); }
|
||||
|
Loading…
Reference in New Issue
Block a user