diff --git a/arm9/examples/cube.c b/arm9/examples/cube.c index 7b0db55..5f0735a 100644 --- a/arm9/examples/cube.c +++ b/arm9/examples/cube.c @@ -1,7 +1,7 @@ #include "io_registers.h" #include "bits.h" -#include "models/cube.h" +#include "model/cube.h" #include "math/math.h" static const uint16_t face_colors[6] = { @@ -159,29 +159,31 @@ void main() // the following vertices are a quadrilateral io_registers.a.BEGIN_VTXS = BEGIN_VTXS__type__quadrilateral; + const union quadrilateral * quadrilateral = cube_Cube_quadrilateral; + // cube faces for (int i = 0; i < 6; i++) { io_registers.a.COLOR = face_colors[i]; - struct vertex_position * a = &cube_positions[cube_quadrilaterals[i].a.position]; + const struct vertex_position * a = &cube_position[quadrilateral[i].a.position]; io_registers.a.VTX_10 = 0 | VTX_10__z_coordinate(a->z) | VTX_10__y_coordinate(a->y) | VTX_10__x_coordinate(a->x); - struct vertex_position * b = &cube_positions[cube_quadrilaterals[i].b.position]; + const struct vertex_position * b = &cube_position[quadrilateral[i].b.position]; io_registers.a.VTX_10 = 0 | VTX_10__z_coordinate(b->z) | VTX_10__y_coordinate(b->y) | VTX_10__x_coordinate(b->x); - struct vertex_position * c = &cube_positions[cube_quadrilaterals[i].c.position]; + const struct vertex_position * c = &cube_position[quadrilateral[i].c.position]; io_registers.a.VTX_10 = 0 | VTX_10__z_coordinate(c->z) | VTX_10__y_coordinate(c->y) | VTX_10__x_coordinate(c->x); - struct vertex_position * d = &cube_positions[cube_quadrilaterals[i].d.position]; + const struct vertex_position * d = &cube_position[quadrilateral[i].d.position]; io_registers.a.VTX_10 = 0 | VTX_10__z_coordinate(d->z) | VTX_10__y_coordinate(d->y) diff --git a/model/cube.h b/model/cube.h index 985c332..7313df8 100644 --- a/model/cube.h +++ b/model/cube.h @@ -1,7 +1,11 @@ +#pragma once + +#include + #include "model.h" -// .6 fixed-point -struct vertex_position cube_positions[] = { +// 3.6 fixed-point +const vertex_position cube_position[] = { {64, 64, -64}, {64, -64, -64}, {64, 64, 64}, @@ -12,16 +16,16 @@ struct vertex_position cube_positions[] = { {-64, -64, 64}, }; -// .15 fixed-point -struct vertex_texture cube_textures[] = { - {32768, 32768}, - {0, 32768}, +// 1.14 fixed-point +const vertex_texture cube_texture[] = { + {16384, 16384}, + {0, 16384}, {0, 0}, - {32768, 0}, + {16384, 0}, }; -// .9 fixed-point -struct vertex_normal cube_normals[] = { +// 0.9 fixed-point +const vertex_normal cube_normal[] = { {0, 512, 0}, {0, 0, 512}, {-512, 0, 0}, @@ -30,42 +34,61 @@ struct vertex_normal cube_normals[] = { {0, 0, -512}, }; -struct quadrilateral cube_quadrilaterals[] = { - { +const union quadrilateral cube_Cube_quadrilateral[] = { + { .v = { {0, 0, 0}, {4, 1, 0}, {6, 2, 0}, {2, 3, 0}, - }, - { + }}, + { .v = { {3, 3, 1}, {2, 0, 1}, {6, 1, 1}, {7, 2, 1}, - }, - { + }}, + { .v = { {7, 2, 2}, {6, 1, 2}, {4, 0, 2}, {5, 3, 2}, - }, - { + }}, + { .v = { {5, 1, 3}, {1, 0, 3}, {3, 3, 3}, {7, 2, 3}, - }, - { + }}, + { .v = { {1, 3, 4}, {0, 0, 4}, {2, 1, 4}, {3, 2, 4}, - }, - { + }}, + { .v = { {5, 2, 5}, {4, 1, 5}, {0, 0, 5}, {1, 3, 5}, - }, + }}, }; +const struct object cube_Cube = { + .triangle = NULL, + .quadrilateral = &cube_Cube_quadrilateral[0], + .triangle_count = 0, + .quadrilateral_count = 6, + .material = -1, +}; + +const struct object * cube_object_list[] = { + &cube_Cube, +}; + +const struct model cube_model = { + .position = &cube_position[0], + .texture = &cube_texture[0], + .normal = &cube_normal[0], + .object = &cube_object_list[0], + .object_count = 1, +}; diff --git a/model/model.h b/model/model.h index 7832fcd..7062d5a 100644 --- a/model/model.h +++ b/model/model.h @@ -3,45 +3,45 @@ #include struct index_ptn { - uint16_t position; - uint16_t texture; - uint16_t normal; + const uint16_t position; + const uint16_t texture; + const uint16_t normal; }; union triangle { struct { - struct index_ptn a; - struct index_ptn b; - struct index_ptn c; + const struct index_ptn a; + const struct index_ptn b; + const struct index_ptn c; }; - struct index_ptn v[3]; + const struct index_ptn v[3]; }; union quadrilateral { struct { - struct index_ptn a; - struct index_ptn b; - struct index_ptn c; - struct index_ptn d; + const struct index_ptn a; + const struct index_ptn b; + const struct index_ptn c; + const struct index_ptn d; }; - struct index_ptn v[4]; + const struct index_ptn v[4]; }; struct vertex_position { // signed 4.6 fixed point - int16_t x; - int16_t y; - int16_t z; + const int16_t x; + const int16_t y; + const int16_t z; }; struct vertex_normal { // s.9 fixed point - int16_t x; - int16_t y; - int16_t z; + const int16_t x; + const int16_t y; + const int16_t z; }; struct vertex_texture { // s.15 fixed point - int16_t u; - int16_t v; + const int16_t u; + const int16_t v; }; typedef struct vertex_position vertex_position; @@ -49,18 +49,18 @@ typedef struct vertex_normal vertex_normal; typedef struct vertex_texture vertex_texture; struct object { - union triangle * triangle; - union quadrilateral * quadrilateral; - int triangle_count; - int quadrilateral_count; - int material; + const union triangle * triangle; + const union quadrilateral * quadrilateral; + const int triangle_count; + const int quadrilateral_count; + const int material; }; struct model { - vertex_position * position; - vertex_texture * texture; - vertex_normal * normal; + const vertex_position * position; + const vertex_texture * texture; + const vertex_normal * normal; - struct object ** object; - int object_count; + const struct object ** object; + const int object_count; };