From 7cf3ec589bfcd67baa869fbd7436ad409ce75bda Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sun, 31 May 2026 00:02:05 +0200 Subject: [PATCH] Change examples to use libdragon's fgeom functions --- examples/00_quad/main.c | 27 +++++++------- examples/01_model/main.c | 11 +++--- examples/02_lighting/main.c | 13 ++++--- examples/03_objects/main.c | 10 +++--- examples/04_dynamic/main.c | 7 ++-- examples/05_splitscreen/collision.h | 4 +-- examples/05_splitscreen/main.c | 23 ++++++------ examples/06_offscreen/main.c | 11 +++--- examples/07_skeleton/main.c | 23 +++++++----- examples/08_animation/main.c | 19 +++++----- examples/09_anim_viewer/main.c | 11 +++--- examples/10_flipbook_tex/main.c | 11 +++--- examples/11_segments/main.c | 11 +++--- examples/12_uv_gen/main.c | 13 ++++--- examples/13_cel_shading/main.c | 35 +++++++++--------- examples/14_outline/main.c | 21 ++++++----- examples/15_pointlight/main.c | 26 +++++++------- examples/16_light_clip/main.c | 14 ++++---- examples/17_culling/debugDraw.h | 8 ++--- examples/17_culling/main.c | 30 ++++++++-------- examples/18_particles/main.c | 34 +++++++++--------- examples/18_particles/partSim.h | 4 +-- examples/19_particles_tex/main.c | 33 +++++++++-------- examples/19_particles_tex/partSim.h | 8 ++--- examples/20_mipmaps/main.c | 13 ++++--- examples/21_fresnel/main.c | 21 ++++++----- examples/22_bigtex/src/main.h | 2 +- examples/22_bigtex/src/render/hdModel.cpp | 2 +- examples/22_bigtex/src/render/hdModel.h | 2 +- examples/22_bigtex/src/render/ringMat.h | 2 +- examples/22_bigtex/src/render/skybox.h | 2 +- examples/22_bigtex/src/rsp/rspFX.h | 2 +- examples/22_bigtex/src/scene/camera.cpp | 4 +-- examples/22_bigtex/src/scene/camera.h | 10 +++--- examples/22_bigtex/src/scene/scene.cpp | 4 +-- examples/23_hdr/main.c | 10 +++--- examples/23_hdr/skydome.c | 10 +++--- examples/23_hdr/skydome.h | 2 +- .../24_hdr_bloom/src/actors/envSphere.cpp | 2 +- .../24_hdr_bloom/src/actors/pointGlobe.cpp | 2 +- examples/24_hdr_bloom/src/camera/camera.cpp | 2 +- examples/24_hdr_bloom/src/camera/camera.h | 10 +++--- examples/24_hdr_bloom/src/camera/flyCam.cpp | 6 ++-- examples/24_hdr_bloom/src/camera/flyCam.h | 2 +- .../24_hdr_bloom/src/memory/matrixManager.h | 2 +- examples/24_hdr_bloom/src/render/ptSystem.h | 2 +- examples/24_hdr_bloom/src/rsp/rspFX.h | 2 +- examples/99_testscene/main.c | 36 +++++++++---------- 48 files changed, 274 insertions(+), 285 deletions(-) diff --git a/examples/00_quad/main.c b/examples/00_quad/main.c index d20f55e6..0d405ff5 100644 --- a/examples/00_quad/main.c +++ b/examples/00_quad/main.c @@ -1,7 +1,6 @@ #include #include -#include /** * Simple example with a spinning quad. @@ -18,25 +17,25 @@ int main() t3d_init((T3DInitParams){}); // Init library itself, use empty params for default settings - T3DMat4 modelMat; // matrix for our model, this is a "normal" float matrix - t3d_mat4_identity(&modelMat); + fm_mat4_t modelMat; // matrix for our model, this is a "normal" float matrix + fm_mat4_identity(&modelMat); // Now allocate a fixed-point matrix, this is what t3d uses internally. T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP)); - const T3DVec3 camPos = {{0,0,-18}}; - const T3DVec3 camTarget = {{0,0,0}}; + const fm_vec3_t camPos = {{0,0,-18}}; + const fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {50, 50, 50, 0xFF}; uint8_t colorDir[4] = {0xFF, 0xFF, 0xFF, 0xFF}; - T3DVec3 lightDirVec = {{0.0f, 0.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{0.0f, 0.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); // Allocate vertices (make sure to have an uncached pointer before passing it to the API!) // For performance reasons, 'T3DVertPacked' contains two vertices at once in one struct. T3DVertPacked* vertices = malloc_uncached(sizeof(T3DVertPacked) * 2); - uint16_t norm = t3d_vert_pack_normal(&(T3DVec3){{ 0, 0, 1}}); // normals are packed in a 5.6.5 format + uint16_t norm = t3d_vert_pack_normal(&(fm_vec3_t){{ 0, 0, 1}}); // normals are packed in a 5.6.5 format vertices[0] = (T3DVertPacked){ .posA = {-16, -16, 0}, .rgbaA = 0xFF0000'FF, .normA = norm, .posB = { 16, -16, 0}, .rgbaB = 0x00FF00'FF, .normB = norm, @@ -47,8 +46,8 @@ int main() }; float rotAngle = 0.0f; - T3DVec3 rotAxis = {{-1.0f, 2.5f, 0.25f}}; - t3d_vec3_norm(&rotAxis); + fm_vec3_t rotAxis = {{-1.0f, 2.5f, 0.25f}}; + fm_vec3_norm(&rotAxis, &rotAxis); // create a viewport, this defines the section to draw to (by default the whole screen) // and contains the projection & view (camera) matrices @@ -63,12 +62,12 @@ int main() // we can set up our viewport settings beforehand here t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 100.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // Model-Matrix, t3d offers some basic matrix functions - t3d_mat4_identity(&modelMat); - t3d_mat4_rotate(&modelMat, &rotAxis, rotAngle); - t3d_mat4_scale(&modelMat, 0.4f, 0.4f, 0.4f); + fm_mat4_identity(&modelMat); + fm_mat4_from_axis_angle(&modelMat, &rotAxis, rotAngle); + fm_mat4_scale(&modelMat, &(fm_vec3_t){{0.4f, 0.4f, 0.4f}}); t3d_mat4_to_fixed(modelMatFP, &modelMat); // ======== Draw (3D) ======== // diff --git a/examples/01_model/main.c b/examples/01_model/main.c index 54e57c3e..39881435 100644 --- a/examples/01_model/main.c +++ b/examples/01_model/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #define FB_COUNT 3 @@ -39,14 +38,14 @@ int main() // In an actual game make sure to free this viewport via 't3d_viewport_destroy' if no longer needed. T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - const T3DVec3 camPos = {{0,10.0f,40.0f}}; - const T3DVec3 camTarget = {{0,0,0}}; + const fm_vec3_t camPos = {{0,10.0f,40.0f}}; + const fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {80, 80, 100, 0xFF}; uint8_t colorDir[4] = {0xEE, 0xAA, 0xAA, 0xFF}; - T3DVec3 lightDirVec = {{-1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{-1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); // Load a model-file, this contains the geometry and some metadata T3DModel *model = t3d_model_load("rom:/model.t3dm"); @@ -65,7 +64,7 @@ int main() float modelScale = 0.1f; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // slowly rotate model, for more information on matrices and how to draw objects // see the example: "03_objects" diff --git a/examples/02_lighting/main.c b/examples/02_lighting/main.c index 54ab0a33..db8fc5be 100644 --- a/examples/02_lighting/main.c +++ b/examples/02_lighting/main.c @@ -1,13 +1,12 @@ #include #include -#include #include #define FB_COUNT 3 typedef struct { color_t color; - T3DVec3 dir; + fm_vec3_t dir; } DirLight; /** @@ -37,8 +36,8 @@ int main() T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); T3DMat4FP* lightMatFP = malloc_uncached(sizeof(T3DMat4FP) * 4 * FB_COUNT); - T3DVec3 camPos = {{40.0f,15.0f,0}}; - const T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{40.0f,15.0f,0}}; + const fm_vec3_t camTarget = {{0,0,0}}; DirLight dirLights[4] = { {.color = {0xFF, 0x00, 0x00, 0xFF}, .dir = {{ 1.0f, 1.0f, 0.0f}}}, @@ -48,8 +47,8 @@ int main() }; uint8_t colorAmbient[4] = {0, 0, 0, 0xFF}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 0.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); T3DModel *model = t3d_model_load("rom:/model.t3dm"); T3DModel *modelLight = t3d_model_load("rom:/light.t3dm"); @@ -79,7 +78,7 @@ int main() lightCountTimer += 0.003f; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(65.0f), 10.0f, 250.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // Model Matrix t3d_mat4fp_from_srt_euler(&modelMatFP[frameIdx], diff --git a/examples/03_objects/main.c b/examples/03_objects/main.c index 3e730e6f..14a23fc0 100644 --- a/examples/03_objects/main.c +++ b/examples/03_objects/main.c @@ -110,13 +110,13 @@ int main() actors[i] = actor_create(i, dpls[i*3 % 2]); } - const T3DVec3 camPos = {{100.0f,25.0f,0}}; - const T3DVec3 camTarget = {{0,0,0}}; + const fm_vec3_t camPos = {{100.0f,25.0f,0}}; + const fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {80, 50, 50, 0xFF}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 0.0f}}; uint8_t lightDirColor[4] = {120, 120, 120, 0xFF}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_norm(&lightDirVec, &lightDirVec); int actorCount = 50; @@ -149,7 +149,7 @@ int main() timeUpdate = get_time_ms() - timeUpdate; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(65.0f), 10.0f, 100.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // ======== Draw (3D) ======== // rdpq_attach(display_get(), display_get_zbuf()); diff --git a/examples/04_dynamic/main.c b/examples/04_dynamic/main.c index 393a76fc..c272a33d 100644 --- a/examples/04_dynamic/main.c +++ b/examples/04_dynamic/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #define FB_COUNT 3 @@ -46,7 +45,7 @@ int main() (float[3]){0,0,0} ); - const T3DVec3 camTarget = {{0,0,0}}; + const fm_vec3_t camTarget = {{0,0,0}}; float camAngle = 0.0f; uint8_t colorAmbient[4] = {0xF0, 0xF0, 0xF0, 0xFF}; @@ -104,10 +103,10 @@ int main() camAngle -= 0.005f; tileOffset += 0.1f; - T3DVec3 camPos = {{sinf(camAngle) * 45.0f, 35.0f, cosf(camAngle) * 60.0f}}; + fm_vec3_t camPos = {{sinf(camAngle) * 45.0f, 35.0f, cosf(camAngle) * 60.0f}}; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // transform mesh if(transformEnabled) diff --git a/examples/05_splitscreen/collision.h b/examples/05_splitscreen/collision.h index ec7fcd7f..58778474 100644 --- a/examples/05_splitscreen/collision.h +++ b/examples/05_splitscreen/collision.h @@ -19,7 +19,7 @@ static AABB mapColl[MAP_COLL_AABB_COUNT] = { {{ 500-AABB_BORDER, -270-AABB_BORDER}, {1020+AABB_BORDER, 270+AABB_BORDER}} }; -static void resolve_aabb_collision(AABB *aabb, T3DVec3 *pos) { +static void resolve_aabb_collision(AABB *aabb, fm_vec3_t *pos) { // Check if the point is inside the AABB if(pos->v[0] >= aabb->min[0] && pos->v[0] <= aabb->max[0] && pos->v[2] >= aabb->min[1] && pos->v[2] <= aabb->max[1]) @@ -40,7 +40,7 @@ static void resolve_aabb_collision(AABB *aabb, T3DVec3 *pos) { } } -static void check_map_collision(T3DVec3 *pos) { +static void check_map_collision(fm_vec3_t *pos) { // in a real-world scenario, you would use a more sophisticated collision logic // for example, by having a broad-phase to pre-filter AABBs for(int i=0; i #include -#include #include #include "collision.h" @@ -14,7 +13,7 @@ #define PLAYER_COUNT 3 typedef struct { - T3DVec3 position; + fm_vec3_t position; float rot; T3DMat4FP* mat; color_t color; @@ -40,10 +39,10 @@ int main() joypad_init(); t3d_init((T3DInitParams){}); - T3DMat4 tmpMatrix; + fm_mat4_t tmpMatrix; T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP)); - t3d_mat4_identity(&tmpMatrix); + fm_mat4_identity(&tmpMatrix); t3d_mat4_to_fixed(modelMatFP, &tmpMatrix); int sizeX = display_get_width(); @@ -105,12 +104,12 @@ int main() // Player movement players[selPlayer].rot += joypad.stick_x * 0.06f * deltaTime; - T3DVec3 moveDir = {{ + fm_vec3_t moveDir = {{ fm_cosf(players[selPlayer].rot) * (joypad.stick_y * 6.0f * deltaTime), 0.0f, fm_sinf(players[selPlayer].rot) * (joypad.stick_y * 6.0f * deltaTime) }}; - t3d_vec3_add(&players[selPlayer].position, &players[selPlayer].position, &moveDir); + fm_vec3_add(&players[selPlayer].position, &players[selPlayer].position, &moveDir); check_map_collision(&players[selPlayer].position); for(int p=0; p #include -#include #include #include @@ -67,8 +66,8 @@ int main() (float[3]){0,0,0}, (float[3]){0,-1,0} ); - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); T3DModel *modelBox = t3d_model_load("rom:/box.t3dm"); T3DModel *modelCRT = t3d_model_load("rom:/target.t3dm"); @@ -125,13 +124,13 @@ int main() // zoom-in / out camDist = fmaxf(14.0f, fminf(30.0f, camDist + (float)joypad.stick_y * -deltaTime * 0.6f)); - T3DVec3 camPos = {{sinf(rotAngle) * camDist, 1.5f, cosf(rotAngle) * camDist}}; + fm_vec3_t camPos = {{sinf(rotAngle) * camDist, 1.5f, cosf(rotAngle) * camDist}}; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 1.5f, 100.0f); - t3d_viewport_look_at(&viewport, &camPos, &(T3DVec3){{0,0,0}}, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &(fm_vec3_t){{0,0,0}}, &(fm_vec3_t){{0,1,0}}); t3d_viewport_set_projection(&viewportOffscreen, T3D_DEG_TO_RAD(85.0f), 5.0f, 150.0f); - t3d_viewport_look_at(&viewportOffscreen, &(T3DVec3){{0,5.0f,40.0f}}, &(T3DVec3){{0,0,0}}, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewportOffscreen, &(fm_vec3_t){{0,5.0f,40.0f}}, &(fm_vec3_t){{0,0,0}}, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&matrixBox[frameIdx], (float[3]){0.2f, 0.2f, 0.2f}, diff --git a/examples/07_skeleton/main.c b/examples/07_skeleton/main.c index adce4d24..a6e8c21e 100644 --- a/examples/07_skeleton/main.c +++ b/examples/07_skeleton/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -12,6 +11,12 @@ color_t get_rainbow_color(float s) { return RGBA32(r, g, b, 255); } +static inline void quat_rotate_axis_in_place(fm_quat_t *quat, const fm_vec3_t *axis, float angleRad) { + fm_quat_t out; + fm_quat_rotate(&out, quat, axis, angleRad); + *quat = out; +} + #define STRINGIFY(x) #x #define STYLE(id) "^0" STRINGIFY(id) #define STYLE_TITLE 1 @@ -54,14 +59,14 @@ int main() T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); T3DMat4FP* matrixBoxFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); - T3DVec3 camPos = {{0,40.0f,40.0f}}; - T3DVec3 camTarget = {{0,30,0}}; + fm_vec3_t camPos = {{0,40.0f,40.0f}}; + fm_vec3_t camTarget = {{0,30,0}}; uint8_t colorAmbient[4] = {0xBB, 0xBB, 0xBB, 0xFF}; uint8_t colorDir[4] = {0xEE, 0xAA, 0xAA, 0xFF}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); T3DModel *model = t3d_model_load("rom:/chicken.t3dm"); // Credits (CC0): https://vertexcat.itch.io/farm-animals-set T3DModel *modelBox = t3d_model_load("rom:/box.t3dm"); @@ -115,11 +120,11 @@ int main() skel.bones[activeBone].scale.v[2] += joypad.stick_y * SPEED_SCALE; break; case 1: - t3d_quat_rotate_euler(&skel.bones[activeBone].rotation, (float[3]){1,0,0}, joypad.stick_x * SPEED_ROT); + quat_rotate_axis_in_place(&skel.bones[activeBone].rotation, &(fm_vec3_t){{1,0,0}}, joypad.stick_x * SPEED_ROT); if(joypad.btn.z) { - t3d_quat_rotate_euler(&skel.bones[activeBone].rotation, (float[3]){0,0,1}, joypad.stick_y * SPEED_ROT); + quat_rotate_axis_in_place(&skel.bones[activeBone].rotation, &(fm_vec3_t){{0,0,1}}, joypad.stick_y * SPEED_ROT); } else { - t3d_quat_rotate_euler(&skel.bones[activeBone].rotation, (float[3]){0,1,0}, joypad.stick_y * SPEED_ROT); + quat_rotate_axis_in_place(&skel.bones[activeBone].rotation, &(fm_vec3_t){{0,1,0}}, joypad.stick_y * SPEED_ROT); } break; case 2: @@ -143,7 +148,7 @@ int main() rotAngleAdd *= 0.9f; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // This function updates any matrices that need re-calculating after scale/rot/pos changes t3d_skeleton_update(&skel); diff --git a/examples/08_animation/main.c b/examples/08_animation/main.c index 017232ab..7bb2fff9 100644 --- a/examples/08_animation/main.c +++ b/examples/08_animation/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -38,11 +37,11 @@ int main() T3DMat4FP* mapMatFP = malloc_uncached(sizeof(T3DMat4FP)); t3d_mat4fp_from_srt_euler(mapMatFP, (float[3]){0.3f, 0.3f, 0.3f}, (float[3]){0, 0, 0}, (float[3]){0, 0, -10}); - T3DVec3 camPos = {{0, 45.0f, 80.0f}}; - T3DVec3 camTarget = {{0, 0,-10}}; + fm_vec3_t camPos = {{0, 45.0f, 80.0f}}; + fm_vec3_t camTarget = {{0, 0,-10}}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); uint8_t colorAmbient[4] = {0xAA, 0xAA, 0xAA, 0xFF}; uint8_t colorDir[4] = {0xFF, 0xAA, 0xAA, 0xFF}; @@ -92,8 +91,8 @@ int main() float lastTime = get_time_s() - (1.0f / 60.0f); - T3DVec3 moveDir = {{0,0,0}}; - T3DVec3 playerPos = {{0,0.15f,0}}; + fm_vec3_t moveDir = {{0,0,0}}; + fm_vec3_t playerPos = {{0,0.15f,0}}; float rotY = 0.0f; float currSpeed = 0.0f; @@ -114,11 +113,11 @@ int main() joypad_inputs_t joypad = joypad_get_inputs(JOYPAD_PORT_1); joypad_buttons_t btn = joypad_get_buttons_pressed(JOYPAD_PORT_1); - T3DVec3 newDir = {{ + fm_vec3_t newDir = {{ (float)joypad.stick_x * 0.05f, 0, -(float)joypad.stick_y * 0.05f }}; - float speed = sqrtf(t3d_vec3_len2(&newDir)); + float speed = sqrtf(fm_vec3_len2(&newDir)); // Player Attack if((btn.a || btn.b) && !animAttack.isPlaying) { @@ -162,7 +161,7 @@ int main() camPos.v[2] = camTarget.v[2] + 65; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // Update the animation and modify the skeleton, this will however NOT recalculate the matrices t3d_anim_update(&animIdle, deltaTime); diff --git a/examples/09_anim_viewer/main.c b/examples/09_anim_viewer/main.c index b97305b5..c6f0aa62 100644 --- a/examples/09_anim_viewer/main.c +++ b/examples/09_anim_viewer/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -72,14 +71,14 @@ int main() T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); - T3DVec3 camPos = {{0,40.0f,40.0f}}; - T3DVec3 camTarget = {{0,30,0}}; + fm_vec3_t camPos = {{0,40.0f,40.0f}}; + fm_vec3_t camTarget = {{0,30,0}}; uint8_t colorAmbient[4] = {0xBB, 0xBB, 0xBB, 0xFF}; uint8_t colorDir[4] = {0xEE, 0xAA, 0xAA, 0xFF}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); #define MODEL_COUNT 3 ModelAnim modelData[MODEL_COUNT] = { @@ -173,7 +172,7 @@ int main() lastTime = newTime; t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_anim_update(&md->animInst[activeAnim], deltaTime); diff --git a/examples/10_flipbook_tex/main.c b/examples/10_flipbook_tex/main.c index 3343d6d4..61a753d0 100644 --- a/examples/10_flipbook_tex/main.c +++ b/examples/10_flipbook_tex/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #define FB_COUNT 3 @@ -56,11 +55,11 @@ int main() T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); T3DMat4FP* mapMatFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); - T3DVec3 camPos = {{-84, 12, 0}}; - T3DVec3 camTarget = {{-82, 12,-10}}; + fm_vec3_t camPos = {{-84, 12, 0}}; + fm_vec3_t camTarget = {{-82, 12,-10}}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); uint8_t colorAmbient[4] = {0, 0, 100, 0x4F}; color_t fogColor; @@ -109,7 +108,7 @@ int main() } t3d_viewport_set_perspective(&viewport, T3D_DEG_TO_RAD(85.0f), aspectRatio, 10.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&mapMatFP[frameIdx], (float[3]){0.2f, 0.2f, 0.2f}, diff --git a/examples/11_segments/main.c b/examples/11_segments/main.c index fb13ded7..aa6c0edc 100644 --- a/examples/11_segments/main.c +++ b/examples/11_segments/main.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -42,11 +41,11 @@ int main() // allocate a matrix per frame here, this can be done in a single buffer T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP) * display_get_num_buffers()); - T3DVec3 camPos = {{0, 100, 140}}; - T3DVec3 camTarget = {{0, 100, 0}}; + fm_vec3_t camPos = {{0, 100, 140}}; + fm_vec3_t camTarget = {{0, 100, 0}}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0xFF}; @@ -81,7 +80,7 @@ int main() t3d_skeleton_update(&skel); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(80.0f), 5.0f, 180.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // for our model matrix, determine an index based on the frame... uint32_t matrixIdx = frame % display_get_num_buffers(); diff --git a/examples/12_uv_gen/main.c b/examples/12_uv_gen/main.c index d723cf7d..4cb97b95 100644 --- a/examples/12_uv_gen/main.c +++ b/examples/12_uv_gen/main.c @@ -1,6 +1,5 @@ #include #include -#include #include /** @@ -40,8 +39,8 @@ int main() t3d_init((T3DInitParams){}); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - T3DVec3 camPos = {{0,10.0f,50.0f}}; - T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{0,10.0f,50.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0xFF}; @@ -90,7 +89,7 @@ int main() uint32_t currModelIdx = 0; float rotAngle = 0.0f; - T3DVec3 currentPos = {{0,0,0}}; + fm_vec3_t currentPos = {{0,0,0}}; int frameIdx = 0; for(;;) @@ -113,15 +112,15 @@ int main() if(joypad.btn.a)rotAngle += 0.04f; if(joypad.btn.b)rotAngle = 0; - T3DVec3 trargetPos = (T3DVec3){{ + fm_vec3_t trargetPos = (fm_vec3_t){{ joypad.stick_x * 0.4f, joypad.stick_y * 0.4f, 0.0f }}; - t3d_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); + fm_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 4.0f, 160.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&model->modelMatFP[frameIdx], (float[3]){model->scale, model->scale, model->scale}, diff --git a/examples/13_cel_shading/main.c b/examples/13_cel_shading/main.c index a39816aa..bc4d3611 100644 --- a/examples/13_cel_shading/main.c +++ b/examples/13_cel_shading/main.c @@ -1,6 +1,5 @@ #include #include -#include #include /** @@ -44,13 +43,13 @@ int main() t3d_init((T3DInitParams){}); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - T3DVec3 camPos = {{0,10.0f,50.0f}}; - T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{0,10.0f,50.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 0.0f}}; - T3DVec3 lightDirVec2 = {{1.0f, 1.0f, 0.0f}}; - t3d_vec3_norm(&lightDirVec); - t3d_vec3_norm(&lightDirVec2); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_t lightDirVec2 = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); + fm_vec3_norm(&lightDirVec2, &lightDirVec2); T3DModel *arrowModel = t3d_model_load("rom:/arrow.t3dm"); T3DMat4FP *arrowMatFP = malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); @@ -171,7 +170,7 @@ int main() uint32_t currModelIdx = 0; float rotAngle = 0.0f; - T3DVec3 currentPos = {{0,0,0}}; + fm_vec3_t currentPos = {{0,0,0}}; bool useTwoLights = false; int frameIdx = 0; @@ -194,15 +193,15 @@ int main() if(joypad.btn.a)rotAngle += 0.04f; if(joypad.btn.b)rotAngle = 0; - T3DVec3 targetPos = (T3DVec3){{ + fm_vec3_t targetPos = (fm_vec3_t){{ joypad.stick_x * 0.4f, joypad.stick_y * 0.4f, 0.0f }}; - t3d_vec3_lerp(¤tPos, ¤tPos, &targetPos, 0.2f); + fm_vec3_lerp(¤tPos, ¤tPos, &targetPos, 0.2f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 5.0f, 120.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&model->modelMatFP[frameIdx], (float[3]){model->scale, model->scale, model->scale}, @@ -213,20 +212,20 @@ int main() lightDirVec.v[0] = sinf(rotAngle * 0.5f); lightDirVec.v[1] = sinf(rotAngle * 0.3f); lightDirVec.v[2] = cosf(rotAngle * 0.5f) + 0.25f; - t3d_vec3_norm(&lightDirVec); + fm_vec3_norm(&lightDirVec, &lightDirVec); lightDirVec2.v[0] = sinf(1.0f + rotAngle * -0.35f); lightDirVec2.v[1] = sinf(1.2f + rotAngle * -0.2f); lightDirVec2.v[2] = cosf(1.4f + rotAngle * 0.2f) + 0.22f; - t3d_vec3_norm(&lightDirVec2); + fm_vec3_norm(&lightDirVec2, &lightDirVec2); - T3DMat4 rotMat; - t3d_mat4_rot_from_dir(&rotMat, &lightDirVec, &(T3DVec3){{0,1,0}}); - t3d_mat4_scale(&rotMat, 0.1f, 0.1f, 0.1f); + fm_mat4_t rotMat; + t3d_mat4_rot_from_dir(&rotMat, &lightDirVec, &(fm_vec3_t){{0,1,0}}); + fm_mat4_scale(&rotMat, &(fm_vec3_t){{0.1f, 0.1f, 0.1f}}); t3d_mat4_to_fixed(&arrowMatFP[frameIdx], &rotMat); - t3d_mat4_rot_from_dir(&rotMat, &lightDirVec2, &(T3DVec3){{0,1,0}}); - t3d_mat4_scale(&rotMat, 0.1f, 0.1f, 0.1f); + t3d_mat4_rot_from_dir(&rotMat, &lightDirVec2, &(fm_vec3_t){{0,1,0}}); + fm_mat4_scale(&rotMat, &(fm_vec3_t){{0.1f, 0.1f, 0.1f}}); t3d_mat4_to_fixed(&arrowMat2FP[frameIdx], &rotMat); // ======== Draw ======== // diff --git a/examples/14_outline/main.c b/examples/14_outline/main.c index 6deebd91..de3f5a52 100644 --- a/examples/14_outline/main.c +++ b/examples/14_outline/main.c @@ -1,6 +1,5 @@ #include #include -#include #include /** @@ -57,13 +56,13 @@ int main() t3d_init((T3DInitParams){}); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - T3DVec3 camPos = {{0,10.0f,50.0f}}; - T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{0,10.0f,50.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; - T3DVec3 lightDirVec = {{1.0f, 1.0f, 0.0f}}; - T3DVec3 lightDirVec2 = {{1.0f, 1.0f, 0.0f}}; - t3d_vec3_norm(&lightDirVec); - t3d_vec3_norm(&lightDirVec2); + fm_vec3_t lightDirVec = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_t lightDirVec2 = {{1.0f, 1.0f, 0.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); + fm_vec3_norm(&lightDirVec2, &lightDirVec2); // Thew model we want to draw is already smooth-shaded, and only contains a single mesh T3DModel *itemModel = t3d_model_load("rom:/potion.t3dm"); @@ -93,13 +92,13 @@ int main() rspq_block_t *dplTextbox = NULL; float rotAngle = 0.0f; - T3DVec3 currentPos = {{0,0,0}}; + fm_vec3_t currentPos = {{0,0,0}}; float colorPos = 0.0f; float colorValue = 1.0f; float outlineSize = 16.0f; - T3DVec3 targetPos = (T3DVec3){{0.0f, 7.0f, -4.0f}}; + fm_vec3_t targetPos = (fm_vec3_t){{0.0f, 7.0f, -4.0f}}; int frameIdx = 0; for(;;) @@ -126,10 +125,10 @@ int main() targetPos.v[2] += joypad.cstick_y * 0.1f; targetPos.v[2] = fminf(fmaxf(targetPos.v[2], -100.0f), 12.0f); - t3d_vec3_lerp(¤tPos, ¤tPos, &targetPos, 0.2f); + fm_vec3_lerp(¤tPos, ¤tPos, &targetPos, 0.2f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 5.0f, 120.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); float scale = 0.13f; t3d_mat4fp_from_srt_euler(&itemMatFP[frameIdx], diff --git a/examples/15_pointlight/main.c b/examples/15_pointlight/main.c index 22435ec0..872583cf 100644 --- a/examples/15_pointlight/main.c +++ b/examples/15_pointlight/main.c @@ -17,7 +17,7 @@ * For simplicity, this example just always uses 5 lights without anything fancy. */ -static float getFloorHeight(const T3DVec3 *pos) { +static float getFloorHeight(const fm_vec3_t *pos) { // Usually you would have some collision / raycast for this // Here we just hardcode the floor height and the one stair if(pos->v[2] < -75.0f) { @@ -29,7 +29,7 @@ static float getFloorHeight(const T3DVec3 *pos) { } typedef struct { - T3DVec3 pos; + fm_vec3_t pos; float strength; color_t color; } PointLight; @@ -98,9 +98,9 @@ int main() float time = 0.0f; float rotAngle = 0.0f; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camTargetCurr = {{0,0,0}}; - T3DVec3 camDir = {{1,1,1}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camTargetCurr = {{0,0,0}}; + fm_vec3_t camDir = {{1,1,1}}; float viewZoom = 96.0f; bool isOrtho = true; bool dirLightOn = false; @@ -145,14 +145,14 @@ int main() // setup camera, look at an isometric angle onto the floor below the selected light // and interpolate the camera position to make it smooth - camTarget = (T3DVec3){{ + camTarget = (fm_vec3_t){{ light->pos.v[0], getFloorHeight(&light->pos) + 2.0f, light->pos.v[2] }}; - t3d_vec3_lerp(&camTargetCurr, &camTargetCurr, &camTarget, 0.2f); + fm_vec3_lerp(&camTargetCurr, &camTargetCurr, &camTarget, 0.2f); - T3DVec3 camPos; - t3d_vec3_scale(&camPos, &camDir, 65.0f); - t3d_vec3_add(&camPos, &camTargetCurr, &camPos); + fm_vec3_t camPos; + fm_vec3_scale(&camPos, &camDir, 65.0f); + fm_vec3_add(&camPos, &camTargetCurr, &camPos); // flickering and wobble of the crystal in the center of the room pointLights[4].pos.v[1] = 24.0f + (sinf(time*2.0f) * 3.5f); @@ -199,7 +199,7 @@ int main() t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(65.0f), 3.0f, 220.0f); } - t3d_viewport_look_at(&viewport, &camPos, &camTargetCurr, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTargetCurr, &(fm_vec3_t){{0,1,0}}); // ----------- DRAW (3D) ------------ // rdpq_attach(display_get(), display_get_zbuf()); @@ -218,7 +218,7 @@ int main() for(int i=0; i<5; ++i) { // Sets the actual point light - t3d_light_set_point(i, &pointLights[i].color.r, &(T3DVec3){{ + t3d_light_set_point(i, &pointLights[i].color.r, &(fm_vec3_t){{ pointLights[i].pos.v[0], pointLights[i].pos.v[1] + getFloorHeight(&pointLights[i].pos), pointLights[i].pos.v[2] @@ -228,7 +228,7 @@ int main() // directional lights can still be used together with point lights if(dirLightOn) { - t3d_light_set_directional(5, (uint8_t[]){0xAA, 0xAA, 0xFF, 0xFF}, &(T3DVec3){{1.0f, 0.0f, 0.0f}}); + t3d_light_set_directional(5, (uint8_t[]){0xAA, 0xAA, 0xFF, 0xFF}, &(fm_vec3_t){{1.0f, 0.0f, 0.0f}}); t3d_light_set_count(6); } diff --git a/examples/16_light_clip/main.c b/examples/16_light_clip/main.c index 2de37731..31c61cf5 100644 --- a/examples/16_light_clip/main.c +++ b/examples/16_light_clip/main.c @@ -68,10 +68,10 @@ int main() float time = 0.0f; float rotAngle = 0.0f; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camPos = camTarget; - T3DVec3 camPosCurrent = camPos; - T3DVec3 lightPos = {{0.0f, 0.0f, 0.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camPos = camTarget; + fm_vec3_t camPosCurrent = camPos; + fm_vec3_t lightPos = {{0.0f, 0.0f, 0.0f}}; float angleHor, angleVer; float camDist = 130.0f; @@ -117,10 +117,10 @@ int main() camPos.v[0] = fm_cosf(angleHor) * fm_cosf(angleVer) * camDist; camPos.v[1] = fm_sinf(angleVer) * camDist; camPos.v[2] = fm_sinf(angleHor) * fm_cosf(angleVer) * camDist; - t3d_vec3_lerp(&camPosCurrent, &camPosCurrent, &camPos, deltaTime * 5.0f); + fm_vec3_lerp(&camPosCurrent, &camPosCurrent, &camPos, deltaTime * 5.0f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(64.0f), 2.0f, 200.0f); - t3d_viewport_look_at(&viewport, &camPosCurrent, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPosCurrent, &camTarget, &(fm_vec3_t){{0,1,0}}); // ----------- DRAW (3D) ------------ // rdpq_attach(display_get(), display_get_zbuf()); @@ -139,7 +139,7 @@ int main() t3d_screen_clear_depth(); t3d_fog_set_enabled(false); - t3d_light_set_directional(0, (uint8_t[]){0x99, 0x99, 0xAA, 0}, &(T3DVec3){{0.0f, 1.0f, 0.0f}}); + t3d_light_set_directional(0, (uint8_t[]){0x99, 0x99, 0xAA, 0}, &(fm_vec3_t){{0.0f, 1.0f, 0.0f}}); if(currMode == MODE_LIGHT) { t3d_light_set_ambient(colorAmbientLight); diff --git a/examples/17_culling/debugDraw.h b/examples/17_culling/debugDraw.h index 54482747..a592e8af 100644 --- a/examples/17_culling/debugDraw.h +++ b/examples/17_culling/debugDraw.h @@ -37,7 +37,7 @@ static void debugDrawLine(uint16_t *fb, int px0, int py0, int px1, int py1, uint } } -static inline void debugDrawLineVec3(uint16_t *fb, const T3DVec3 *p0, const T3DVec3 *p1, uint16_t color) +static inline void debugDrawLineVec3(uint16_t *fb, const fm_vec3_t *p0, const fm_vec3_t *p1, uint16_t color) { if(p0->v[2] < 1.0 && p1->v[2] < 1.0) { debugDrawLine(fb, (int)p0->v[0], (int)p0->v[1], (int)p1->v[0], (int)p1->v[1], color); @@ -47,9 +47,9 @@ static inline void debugDrawLineVec3(uint16_t *fb, const T3DVec3 *p0, const T3DV static void debugDrawAABB(uint16_t *fb, const int16_t *min, const int16_t *max, T3DViewport *vp, float scale, uint16_t color) { // transform min/max to screen space - T3DVec3 points[8]; - T3DVec3 pt0 = {{min[0]*scale, min[1]*scale, min[2]*scale}}; - T3DVec3 pt1 = {{max[0]*scale, min[1]*scale, min[2]*scale}}; + fm_vec3_t points[8]; + fm_vec3_t pt0 = {{min[0]*scale, min[1]*scale, min[2]*scale}}; + fm_vec3_t pt1 = {{max[0]*scale, min[1]*scale, min[2]*scale}}; t3d_viewport_calc_viewspace_pos(vp, &points[0], &pt0); t3d_viewport_calc_viewspace_pos(vp, &points[1], &pt1); pt0.v[1] = max[1]*scale; t3d_viewport_calc_viewspace_pos(vp, &points[2], &pt0); pt1.v[1] = max[1]*scale; diff --git a/examples/17_culling/main.c b/examples/17_culling/main.c index 19893601..641f7257 100644 --- a/examples/17_culling/main.c +++ b/examples/17_culling/main.c @@ -44,10 +44,10 @@ int main() T3DMat4FP* modelMatFP = (T3DMat4FP*)malloc_uncached(sizeof(T3DMat4FP) * FB_COUNT); - T3DVec3 camPos = {{-60.0f, 70.0f, 20.f}}; - T3DVec3 camPosTarget = camPos; - T3DVec3 camDir = {{0,0,1}}; - T3DVec3 camPosScreen, camTargetScreen; + fm_vec3_t camPos = {{-60.0f, 70.0f, 20.f}}; + fm_vec3_t camPosTarget = camPos; + fm_vec3_t camDir = {{0,0,1}}; + fm_vec3_t camPosScreen, camTargetScreen; float camRotX = 0.2f; float camRotY = -0.2f; @@ -101,7 +101,7 @@ int main() camDir.v[0] = fm_cosf(camRotX) * fm_cosf(camRotY); camDir.v[1] = fm_sinf(camRotY); camDir.v[2] = fm_sinf(camRotX) * fm_cosf(camRotY); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotXTarget += (float)joypad.stick_x * camRotSpeed; @@ -117,20 +117,20 @@ int main() if(joypad.btn.c_up)camPosTarget.v[1] += camSpeed * 35.0f; if(joypad.btn.c_down)camPosTarget.v[1] -= camSpeed * 35.0f; - t3d_vec3_lerp(&camPos, &camPos, &camPosTarget, 0.8f); + fm_vec3_lerp(&camPos, &camPos, &camPosTarget, 0.8f); camRotX = t3d_lerp(camRotX, camRotXTarget, 0.8f); camRotY = t3d_lerp(camRotY, camRotYTarget, 0.8f); const T3DModel *model = models[currentModel]; - T3DVec3 camTarget; - t3d_vec3_add(&camTarget, &camPos, &camDir); + fm_vec3_t camTarget; + fm_vec3_add(&camTarget, &camPos, &camDir); if(currentModel == 0) { t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(75.0f), 1.0f, 160.0f); } else { t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(60.0f), 4.0f, 110.0f); } - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); float modelScale = currentModel == 0 ? 0.5f : 0.15f; t3d_mat4fp_from_srt_euler(&modelMatFP[frameIdx], @@ -172,11 +172,11 @@ int main() // Debug top-down view, since visibility was already calculated // we can switch the camera to view the mesh independently of culling if(debugView) { - T3DVec3 camPosDebug = (T3DVec3){{camTarget.v[0]+2, currentModel == 0 ? 225.0f : 130.0f, camTarget.v[2]}}; - t3d_viewport_look_at(&viewport, &camPosDebug, &camTarget, &(T3DVec3){{0,1,0}}); + fm_vec3_t camPosDebug = (fm_vec3_t){{camTarget.v[0]+2, currentModel == 0 ? 225.0f : 130.0f, camTarget.v[2]}}; + t3d_viewport_look_at(&viewport, &camPosDebug, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_viewport_calc_viewspace_pos(&viewport, &camPosScreen, &camPos); - t3d_vec3_add(&camTarget, &camPos, &(T3DVec3){{camDir.v[0]*100, camDir.v[1]*100, camDir.v[2]*100}}); + fm_vec3_add(&camTarget, &camPos, &(fm_vec3_t){{camDir.v[0]*100, camDir.v[1]*100, camDir.v[2]*100}}); t3d_viewport_calc_viewspace_pos(&viewport, &camTargetScreen, &camTarget); } @@ -252,9 +252,9 @@ int main() // Top-down debug view, this shows the camera position and direction if(debugView) { int points = 12; - T3DVec3 step; - t3d_vec3_diff(&step, &camTargetScreen, &camPosScreen); - t3d_vec3_scale(&step, &step, 1.0f / points); + fm_vec3_t step; + fm_vec3_sub(&step, &camTargetScreen, &camPosScreen); + fm_vec3_scale(&step, &step, 1.0f / points); rdpq_set_mode_fill(RGBA32(0x00, 0x00, 0xFF, 0xFF)); rdpq_fill_rectangle(camPosScreen.v[0]-4, camPosScreen.v[1]-4, camPosScreen.v[0]+4, camPosScreen.v[1]+4); diff --git a/examples/18_particles/main.c b/examples/18_particles/main.c index 3606c686..708a1108 100644 --- a/examples/18_particles/main.c +++ b/examples/18_particles/main.c @@ -3,7 +3,7 @@ #include #include -#include + #include #include @@ -95,26 +95,26 @@ int main() (float[]){0,-1,0} ); - T3DVec3 camPos = {{-50.0f, 20.0f, 0.0f}}; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camDir = {{0,0,1}}; + fm_vec3_t camPos = {{-50.0f, 20.0f, 0.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camDir = {{0,0,1}}; float camRotX = 0.0f; float camRotY = -0.2f; bool showModel = true; uint32_t example = 0; uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0xFF}; - T3DVec3 lightDirVec = {{0.0f, 0.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{0.0f, 0.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); float partSizeX = 0.4f; float partSizeY = 0.9f; float partMatScaleVal = 0.8f; - T3DVec3 particleMatScale = {{1, 1, 1}}; - T3DVec3 particlePos = {{0, 0, 0}}; - T3DVec3 particleRot = {{0, 0, 0}}; + fm_vec3_t particleMatScale = {{1, 1, 1}}; + fm_vec3_t particlePos = {{0, 0, 0}}; + fm_vec3_t particleRot = {{0, 0, 0}}; float time = 0; bool needRebuild = true; int frameIdx = 0; @@ -165,7 +165,7 @@ int main() camDir.v[0] = fm_cosf(camRotX) * fm_cosf(camRotY); camDir.v[1] = fm_sinf(camRotY); camDir.v[2] = fm_sinf(camRotX) * fm_cosf(camRotY); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotX += (float)joypad.stick_x * camRotSpeed; @@ -190,32 +190,32 @@ int main() { case 0: // Random time += deltaTime * 0.2f; - particleRot = (T3DVec3){{time,time*0.77f,time*1.42f}}; - particleMatScale = (T3DVec3){{partMatScaleVal, partMatScaleVal, partMatScaleVal}}; + particleRot = (fm_vec3_t){{time,time*0.77f,time*1.42f}}; + particleMatScale = (fm_vec3_t){{partMatScaleVal, partMatScaleVal, partMatScaleVal}}; if(needRebuild)generate_particles_random(particlesS8, particleCount); rdpq_set_env_color((color_t){0xFF, 0xFF, 0xFF, 0xFF}); break; case 1: // Flame - particleRot = (T3DVec3){{0,0,0}}; + particleRot = (fm_vec3_t){{0,0,0}}; if(!joypad.btn.z)time += deltaTime * 1.0f; particleCount = 128; float posX = fm_cosf(time) * 80.0f; float posZ = fm_sinf(2*time) * 40.0f; simulate_particles_fire(particlesS8, particleCount, posX, posZ); - particleMatScale = (T3DVec3){{0.9f, partMatScaleVal, 0.9f}}; + particleMatScale = (fm_vec3_t){{0.9f, partMatScaleVal, 0.9f}}; particlePos.y = partMatScaleVal * 130.0f; rdpq_set_env_color((color_t){0xFF, 0xFF, 0xFF, 0xFF}); break; case 2: // Grass time += deltaTime * 1.0f; - particleRot = (T3DVec3){{0,0,0}}; + particleRot = (fm_vec3_t){{0,0,0}}; particlePos.y = 0; if(needRebuild) { particleCount = simulate_particles_grass(particlesS16, particleCount); } - particleMatScale = (T3DVec3){{partMatScaleVal, partSizeY * 2.9f, partMatScaleVal}}; + particleMatScale = (fm_vec3_t){{partMatScaleVal, partSizeY * 2.9f, partMatScaleVal}}; rdpq_set_env_color(blend_colors( (color_t){0xAA, 0xFF, 0x55, 0xFF}, (color_t){0xFF, 0xAA, 0x55, 0xFF}, @@ -229,7 +229,7 @@ int main() t3d_mat4fp_from_srt_euler(&matPartFP[frameIdx], particleMatScale.v, particleRot.v, particlePos.v); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(80.0f), 5.0f, 250.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // ======== Draw (3D) ======== // diff --git a/examples/18_particles/partSim.h b/examples/18_particles/partSim.h index 7df53355..a6a99747 100644 --- a/examples/18_particles/partSim.h +++ b/examples/18_particles/partSim.h @@ -14,13 +14,13 @@ static void generate_particles_random(TPXParticleS8 *particles, uint32_t count) particles[p].sizeA = 20 + (rand() % 10); particles[p].sizeB = 20 + (rand() % 10); - T3DVec3 pos = {{ + fm_vec3_t pos = {{ (i * 1 + rand()) % 128 - 64, (i * 3 + rand()) % 128 - 64, (i * 4 + rand()) % 128 - 64 }}; - t3d_vec3_norm(&pos); + fm_vec3_norm(&pos, &pos); float len = rand() % 40; pos.v[0] *= len; pos.v[1] *= len; diff --git a/examples/19_particles_tex/main.c b/examples/19_particles_tex/main.c index 87844254..e50c4764 100644 --- a/examples/19_particles_tex/main.c +++ b/examples/19_particles_tex/main.c @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -121,26 +120,26 @@ int main() (float[]){0,-1,0} ); - T3DVec3 camPos = {{-80.0f, 40.0f, 0.0f}}; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camDir = {{0,0,1}}; + fm_vec3_t camPos = {{-80.0f, 40.0f, 0.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camDir = {{0,0,1}}; float camRotX = 0.0f; float camRotY = -0.2f; bool showModel = false; uint32_t example = 0; uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0xFF}; - T3DVec3 lightDirVec = {{0.0f, 0.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{0.0f, 0.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); float partSizeX = 1.0f; float partSizeY = 1.0f; float partMatScaleVal = 1.3f; - T3DVec3 particleMatScale = {{1, 1, 1}}; - T3DVec3 particlePos = {{0, 0, 0}}; - T3DVec3 particleRot = {{0, 0, 0}}; + fm_vec3_t particleMatScale = {{1, 1, 1}}; + fm_vec3_t particlePos = {{0, 0, 0}}; + fm_vec3_t particleRot = {{0, 0, 0}}; float time = 0; float timeTile = 0; bool needRebuild = true; @@ -194,7 +193,7 @@ int main() camDir.v[0] = fm_cosf(camRotX) * fm_cosf(camRotY); camDir.v[1] = fm_sinf(camRotY); camDir.v[2] = fm_sinf(camRotX) * fm_cosf(camRotY); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotX += (float)joypad.stick_x * camRotSpeed; @@ -217,7 +216,7 @@ int main() switch(example) { case 4: // Flame - particleRot = (T3DVec3){{0,0,0}}; + particleRot = (fm_vec3_t){{0,0,0}}; if(!joypad.btn.z)time += deltaTime * 1.0f; timeTile += deltaTime * 25.1f; particleCount = 128; @@ -225,7 +224,7 @@ int main() float posZ = fm_sinf(2*time) * 40.0f; simulate_particles_fire(particlesS8, particleCount, posX, posZ); - particleMatScale = (T3DVec3){{0.9f, partMatScaleVal, 0.9f}}; + particleMatScale = (fm_vec3_t){{0.9f, partMatScaleVal, 0.9f}}; particlePos.y = partMatScaleVal * 130.0f; rdpq_set_env_color((color_t){0xFF, 0xFF, 0xFF, 0xFF}); isSpriteRot = true; @@ -233,20 +232,20 @@ int main() case 5: // Coins time += deltaTime * 1.2f; timeTile += deltaTime * 20.0f; - particleRot = (T3DVec3){{0,0,0}}; + particleRot = (fm_vec3_t){{0,0,0}}; particlePos.y = 0; if(needRebuild) { particleCount = simulate_particles_coins(particlesS16, particleCount); } - particleMatScale = (T3DVec3){{partMatScaleVal, partSizeY * 2.9f, partMatScaleVal}}; + particleMatScale = (fm_vec3_t){{partMatScaleVal, partSizeY * 2.9f, partMatScaleVal}}; rdpq_set_env_color((color_t){0xFF, 0xFF, 0xFF, 0xFF}); is16Bit = true; break; default: // Random time += deltaTime * 0.2f; timeTile += deltaTime * 0.1f; - particleRot = (T3DVec3){{time,time*0.77f,time*1.42f}}; - particleMatScale = (T3DVec3){{partMatScaleVal, partMatScaleVal, partMatScaleVal}}; + particleRot = (fm_vec3_t){{time,time*0.77f,time*1.42f}}; + particleMatScale = (fm_vec3_t){{partMatScaleVal, partMatScaleVal, partMatScaleVal}}; if(needRebuild)generate_particles_random(particlesS8, particleCount); rdpq_set_env_color((color_t){0xFF, 0xFF, 0xFF, 0xFF}); @@ -258,7 +257,7 @@ int main() t3d_mat4fp_from_srt_euler(&matPartFP[frameIdx], particleMatScale.v, particleRot.v, particlePos.v); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(80.0f), 5.0f, 250.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // ======== Draw (3D) ======== // diff --git a/examples/19_particles_tex/partSim.h b/examples/19_particles_tex/partSim.h index 7bc1bf72..938f8d99 100644 --- a/examples/19_particles_tex/partSim.h +++ b/examples/19_particles_tex/partSim.h @@ -58,8 +58,8 @@ float randNoise3d_rand(float coX, float coY){ return fract(fm_sinf(coX) * 65979.1347f); } -T3DVec3 randNoise3d(float uvX, float uvY) { - return (T3DVec3){{ +fm_vec3_t randNoise3d(float uvX, float uvY) { + return (fm_vec3_t){{ randNoise3d_rand(uvX + 0.23f * 382.567f, uvX + 0.23f * 382.567f), randNoise3d_rand(uvY + 0.65f * 330.356f, uvX + 0.65f * 330.356f), randNoise3d_rand(uvX + 0.33f * 356.346f, uvY + 0.33f * 356.346f) @@ -81,13 +81,13 @@ static void generate_particles_random(TPXParticleS8 *particles, uint32_t count) particles[p].sizeA = 20 + (rand() % 10); particles[p].sizeB = 20 + (rand() % 10); - T3DVec3 pos = {{ + fm_vec3_t pos = {{ (i * 1 + rand()) % 128 - 64, (i * 3 + rand()) % 128 - 64, (i * 4 + rand()) % 128 - 64 }}; - t3d_vec3_norm(&pos); + fm_vec3_norm(&pos, &pos); float len = rand() % 40; pos.v[0] *= len; pos.v[1] *= len; diff --git a/examples/20_mipmaps/main.c b/examples/20_mipmaps/main.c index cd5e6791..70a5e100 100644 --- a/examples/20_mipmaps/main.c +++ b/examples/20_mipmaps/main.c @@ -1,6 +1,5 @@ #include #include -#include #include /** @@ -45,8 +44,8 @@ int main() t3d_init((T3DInitParams){}); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - T3DVec3 camPos = {{0,0.0f,50.0f}}; - T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{0,0.0f,50.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0xFF}; @@ -109,7 +108,7 @@ int main() uint32_t currModelIdx = 0; float rotAngle = 0.0f; - T3DVec3 currentPos = {{0,0,0}}; + fm_vec3_t currentPos = {{0,0,0}}; int frameIdx = 0; for(;;) @@ -130,15 +129,15 @@ int main() if(joypad.btn.a)rotAngle += 0.04f; if(joypad.btn.b)rotAngle = 0; - T3DVec3 trargetPos = (T3DVec3){{ + fm_vec3_t trargetPos = (fm_vec3_t){{ joypad.stick_x * 0.4f, joypad.stick_y * 0.4f, (sinf(rotAngle*0.4f) * 0.5f + 0.5f) * 260.0f }}; - t3d_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); + fm_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 14.0f, 240.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&model->modelMatFP[frameIdx], (float[3]){model->scale, model->scale, model->scale}, diff --git a/examples/21_fresnel/main.c b/examples/21_fresnel/main.c index 53fcb48b..3cc9d72a 100644 --- a/examples/21_fresnel/main.c +++ b/examples/21_fresnel/main.c @@ -1,6 +1,5 @@ #include #include -#include #include /** @@ -68,8 +67,8 @@ int main() t3d_init((T3DInitParams){}); T3DViewport viewport = t3d_viewport_create_buffered(FB_COUNT); - T3DVec3 camPos = {{0,10.0f,50.0f}}; - T3DVec3 camTarget = {{0,0,0}}; + fm_vec3_t camPos = {{0,10.0f,50.0f}}; + fm_vec3_t camTarget = {{0,0,0}}; uint8_t colorAmbient[4] = {0xFF, 0xFF, 0xFF, 0x00}; @@ -146,7 +145,7 @@ int main() int currModelIdx = 0; float rotAngle = 0.0f; - T3DVec3 currentPos = {{0,0,0}}; + fm_vec3_t currentPos = {{0,0,0}}; int frameIdx = 0; for(;;) @@ -168,15 +167,15 @@ int main() if(joypad.btn.a)rotAngle += 0.04f; if(joypad.btn.b)rotAngle = 0; - T3DVec3 trargetPos = (T3DVec3){{ + fm_vec3_t trargetPos = (fm_vec3_t){{ joypad.stick_x * 0.4f, joypad.stick_y * 0.4f, 0.0f }}; - t3d_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); + fm_vec3_lerp(¤tPos, ¤tPos, &trargetPos, 0.2f); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 4.0f, 100.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&models->modelMatFP[frameIdx], (float[3]){model->scale, model->scale, model->scale}, @@ -201,7 +200,7 @@ int main() { case LIGHT_TYPE_DIR: // Approx. using a directional light, only works for curved surfaces but is very fast - t3d_light_set_directional(0, (uint8_t[4]){0x00, 0x00, 0x00, 0xFF}, &(T3DVec3){{0, 0, 1}}); + t3d_light_set_directional(0, (uint8_t[4]){0x00, 0x00, 0x00, 0xFF}, &(fm_vec3_t){{0, 0, 1}}); t3d_light_set_count(1); break; case LIGHT_TYPE_POINT: @@ -209,7 +208,7 @@ int main() // Note: point lights exactly at the camera will not work properly, so offset it slightly t3d_light_set_point(0, (uint8_t[4]){0x00, 0x00, 0x00, 0xFF}, - &(T3DVec3){{camPos.x, camPos.y+1, camPos.z+1}}, 1000.0f, false + &(fm_vec3_t){{camPos.x, camPos.y+1, camPos.z+1}}, 1000.0f, false ); t3d_light_set_count(1); break; @@ -218,11 +217,11 @@ int main() // This works since each light source is added together, and the CC inverts it t3d_light_set_point(0, (uint8_t[4]){0x00, 0x00, 0x00, 0xF0}, - &(T3DVec3){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false + &(fm_vec3_t){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false ); t3d_light_set_point(1, (uint8_t[4]){0x00, 0x00, 0x00, 0x90}, - &(T3DVec3){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false + &(fm_vec3_t){{camPos.x+0.075f, camPos.y+1, camPos.z+1}}, 1000.0f, false ); t3d_light_set_count(2); break; diff --git a/examples/22_bigtex/src/main.h b/examples/22_bigtex/src/main.h index a5d01417..2762ea84 100644 --- a/examples/22_bigtex/src/main.h +++ b/examples/22_bigtex/src/main.h @@ -6,7 +6,7 @@ #include #include -#include + #include template diff --git a/examples/22_bigtex/src/render/hdModel.cpp b/examples/22_bigtex/src/render/hdModel.cpp index cba69ad9..41703d51 100644 --- a/examples/22_bigtex/src/render/hdModel.cpp +++ b/examples/22_bigtex/src/render/hdModel.cpp @@ -132,6 +132,6 @@ void HDModel::drawShade() { rspq_block_run(dplDrawShade); } -void HDModel::setPos(const T3DVec3 &pos) { +void HDModel::setPos(const fm_vec3_t &pos) { t3d_mat4fp_set_pos(matFP.getNext(), pos); } diff --git a/examples/22_bigtex/src/render/hdModel.h b/examples/22_bigtex/src/render/hdModel.h index d3c500a3..4aa49d91 100644 --- a/examples/22_bigtex/src/render/hdModel.h +++ b/examples/22_bigtex/src/render/hdModel.h @@ -21,7 +21,7 @@ class HDModel HDModel(const std::string &t3dmPath, Textures& textures); ~HDModel(); - void setPos(const T3DVec3 &pos); + void setPos(const fm_vec3_t &pos); void draw(); void drawShade(); }; \ No newline at end of file diff --git a/examples/22_bigtex/src/render/ringMat.h b/examples/22_bigtex/src/render/ringMat.h index b6bf8927..23fd4689 100644 --- a/examples/22_bigtex/src/render/ringMat.h +++ b/examples/22_bigtex/src/render/ringMat.h @@ -27,7 +27,7 @@ struct RingMat4FP { return get(); } - void fillSRT(const T3DVec3 &scale, const T3DVec3 &rot, const T3DVec3 &trans) { + void fillSRT(const fm_vec3_t &scale, const fm_vec3_t &rot, const fm_vec3_t &trans) { for(uint32_t i=0; i -#include + extern "C" { extern volatile uint32_t *rspq_cur_pointer, *rspq_cur_sentinel; diff --git a/examples/22_bigtex/src/scene/camera.cpp b/examples/22_bigtex/src/scene/camera.cpp index 7ebf968f..96728301 100644 --- a/examples/22_bigtex/src/scene/camera.cpp +++ b/examples/22_bigtex/src/scene/camera.cpp @@ -24,7 +24,7 @@ void Camera::update(float deltaTime) { dir.v[0] = fm_cosf(rotX) * fm_cosf(rotY); dir.v[1] = fm_sinf(rotY); dir.v[2] = fm_sinf(rotX) * fm_cosf(rotY); - t3d_vec3_norm(&dir); + fm_vec3_norm(&dir, &dir); if(joypad.btn.z) { targetRotX += (float)joypad.stick_x * camRotSpeed; @@ -52,7 +52,7 @@ void Camera::update(float deltaTime) { if(camLerpSpeed > 0.0f) { float lerpFactor = 1.0f - powf(camLerpSpeed, deltaTime); - t3d_vec3_lerp(pos, pos, targetPos, lerpFactor); + fm_vec3_lerp(&pos, &pos, &targetPos, lerpFactor); rotX = t3d_lerp(rotX, targetRotX, lerpFactor); rotY = t3d_lerp(rotY, targetRotY, lerpFactor); } else { diff --git a/examples/22_bigtex/src/scene/camera.h b/examples/22_bigtex/src/scene/camera.h index 31e4f24e..49234ed8 100644 --- a/examples/22_bigtex/src/scene/camera.h +++ b/examples/22_bigtex/src/scene/camera.h @@ -10,11 +10,11 @@ class Camera private: T3DViewport viewport{}; - T3DVec3 pos{{0,0,0}}; - T3DVec3 target{{0,0,0}}; - T3DVec3 dir{{1,0,0}}; + fm_vec3_t pos{{0,0,0}}; + fm_vec3_t target{{0,0,0}}; + fm_vec3_t dir{{1,0,0}}; - T3DVec3 targetPos{pos}; + fm_vec3_t targetPos{pos}; float rotX{0}; float rotY{0}; @@ -30,5 +30,5 @@ class Camera void attach(); void setCamLerpSpeed(float speed) { camLerpSpeed = speed; } - const T3DVec3& getPosition() const { return pos; } + const fm_vec3_t& getPosition() const { return pos; } }; \ No newline at end of file diff --git a/examples/22_bigtex/src/scene/scene.cpp b/examples/22_bigtex/src/scene/scene.cpp index fbaba70e..3e25ad40 100644 --- a/examples/22_bigtex/src/scene/scene.cpp +++ b/examples/22_bigtex/src/scene/scene.cpp @@ -57,12 +57,12 @@ void Scene::draw(const Memory::FrameBuffers &buffers, surface_t *surf) rdpq_mode_pop(); - T3DVec3 lightDir{ + fm_vec3_t lightDir{ fm_sinf(lightTimer*0.8f) * 0.75f, 0.75f, fm_cosf(lightTimer*0.8f) * 0.75f }; - t3d_vec3_norm(lightDir); + fm_vec3_norm(&lightDir, &lightDir); switch(state.currSkybox) { case 0: default: diff --git a/examples/23_hdr/main.c b/examples/23_hdr/main.c index 860fb11a..a926a5fe 100644 --- a/examples/23_hdr/main.c +++ b/examples/23_hdr/main.c @@ -154,9 +154,9 @@ int main() t3d_matrix_pop(1); model->userBlock = rspq_block_end(); - T3DVec3 camPos = {{0.0, 0.0, 0.0}}; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camDir = {{0,0,1}}; + fm_vec3_t camPos = {{0.0, 0.0, 0.0}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camDir = {{0,0,1}}; float camRotX = 3.14f; float camRotY = 0.24f; @@ -190,7 +190,7 @@ int main() camDir.v[0] = fm_cosf(camRotX) * fm_cosf(camRotY); camDir.v[1] = fm_sinf(camRotY); camDir.v[2] = fm_sinf(camRotX) * fm_cosf(camRotY); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotX += (float)joypad.stick_x * camRotSpeed; @@ -223,7 +223,7 @@ int main() } t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 2.5f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); t3d_mat4fp_from_srt_euler(&rotMatFP[frameIdx], (float[3]){modelScale, modelScale, modelScale}, diff --git a/examples/23_hdr/skydome.c b/examples/23_hdr/skydome.c index f84135a6..070d7487 100644 --- a/examples/23_hdr/skydome.c +++ b/examples/23_hdr/skydome.c @@ -1,6 +1,6 @@ #include #include -#include + #include #include "skydome.h" @@ -125,7 +125,7 @@ void skydome_draw(skydome_t* skydome){ fm_vec3_dir_from_euler(&lightdir, &euler); t3d_light_set_ambient((uint8_t*)&skydome->sun.ambient); - t3d_light_set_directional(0, (uint8_t*)&skydome->sun.direct, (T3DVec3*)&lightdir); + t3d_light_set_directional(0, (uint8_t*)&skydome->sun.direct, (fm_vec3_t*)&lightdir); t3d_light_set_count(1); T3DObject* obj = t3d_model_get_object_by_index(skydome->__vars.model, 0); @@ -225,9 +225,9 @@ void skydome_draw_lensflare(skydome_t* skydome){ fm_vec3_dir_from_euler(&worldpos, &sunangles); fm_vec3_scale(&worldpos, &worldpos, 99999); - t3d_viewport_calc_viewspace_pos(skydome->__vars.viewport, (T3DVec3*)&viewpos, (T3DVec3*)&worldpos); - T3DVec4 posScreen; - t3d_mat4_mul_vec3(&posScreen, &skydome->__vars.viewport->matCamProj, (T3DVec3*)&worldpos); + t3d_viewport_calc_viewspace_pos(skydome->__vars.viewport, (fm_vec3_t*)&viewpos, (fm_vec3_t*)&worldpos); + fm_vec4_t posScreen; + fm_mat4_mul_vec3(&posScreen, &skydome->__vars.viewport->matCamProj, (fm_vec3_t*)&worldpos); float xpos = viewpos.v[0]; float ypos = viewpos.v[1]; diff --git a/examples/23_hdr/skydome.h b/examples/23_hdr/skydome.h index c2f81bde..14a527e1 100644 --- a/examples/23_hdr/skydome.h +++ b/examples/23_hdr/skydome.h @@ -15,7 +15,7 @@ #include #include - #include + #include /** diff --git a/examples/24_hdr_bloom/src/actors/envSphere.cpp b/examples/24_hdr_bloom/src/actors/envSphere.cpp index 85a312ff..231c4a63 100644 --- a/examples/24_hdr_bloom/src/actors/envSphere.cpp +++ b/examples/24_hdr_bloom/src/actors/envSphere.cpp @@ -62,7 +62,7 @@ namespace Actor pos = {stick.stick_x / 8.0f, stick.stick_y / 8.0f, 0}; - t3d_vec3_lerp(&realPos, &realPos, &pos, 0.15f); + fm_vec3_lerp(&realPos, &realPos, &pos, 0.15f); t3d_mat4fp_from_srt_euler(matFP.getNext(), {BASE_SCALE, BASE_SCALE, BASE_SCALE}, {timer, timer*1.2f, timer*0.7f}, diff --git a/examples/24_hdr_bloom/src/actors/pointGlobe.cpp b/examples/24_hdr_bloom/src/actors/pointGlobe.cpp index d77ccc91..e53d565f 100644 --- a/examples/24_hdr_bloom/src/actors/pointGlobe.cpp +++ b/examples/24_hdr_bloom/src/actors/pointGlobe.cpp @@ -147,7 +147,7 @@ namespace Actor void PointGlobe::update(float deltaTime) { - float camDist = t3d_vec3_distance( + float camDist = fm_vec3_distance( &state.activeScene->getCam().pos, &pos ); diff --git a/examples/24_hdr_bloom/src/camera/camera.cpp b/examples/24_hdr_bloom/src/camera/camera.cpp index 1cad9554..506de665 100644 --- a/examples/24_hdr_bloom/src/camera/camera.cpp +++ b/examples/24_hdr_bloom/src/camera/camera.cpp @@ -18,7 +18,7 @@ void Camera::update(float deltaTime) //needsProjUpdate = false; //} - t3d_viewport_look_at(viewport, pos, target, T3DVec3{{0, 1, 0}}); + t3d_viewport_look_at(viewport, pos, target, fm_vec3_t{{0, 1, 0}}); } void Camera::attach() { diff --git a/examples/24_hdr_bloom/src/camera/camera.h b/examples/24_hdr_bloom/src/camera/camera.h index 6db58c28..8e6d677e 100644 --- a/examples/24_hdr_bloom/src/camera/camera.h +++ b/examples/24_hdr_bloom/src/camera/camera.h @@ -5,13 +5,13 @@ #pragma once #include -#include + struct Camera { T3DViewport viewport{}; - T3DVec3 pos{}; - T3DVec3 target{}; + fm_vec3_t pos{}; + fm_vec3_t target{}; float fov{}; float near{}; float far{}; @@ -23,7 +23,7 @@ struct Camera void update(float deltaTime); void attach(); - void move(T3DVec3 dir) { + void move(fm_vec3_t dir) { target += dir; pos += dir; } @@ -33,7 +33,7 @@ struct Camera [[nodiscard]] fm_vec3_t getDirection() const { auto dir = target - pos; - t3d_vec3_norm(&dir); + fm_vec3_norm(&dir, &dir); return dir; } diff --git a/examples/24_hdr_bloom/src/camera/flyCam.cpp b/examples/24_hdr_bloom/src/camera/flyCam.cpp index b40575a3..ce3d06e6 100644 --- a/examples/24_hdr_bloom/src/camera/flyCam.cpp +++ b/examples/24_hdr_bloom/src/camera/flyCam.cpp @@ -23,11 +23,11 @@ void FlyCam::update(float deltaTime) camRotXCurr = t3d_lerp_angle(camRotXCurr, camRotX, smoothFactor); camRotYCurr = t3d_lerp_angle(camRotYCurr, camRotY, smoothFactor); - T3DVec3 camDir{}; + fm_vec3_t camDir{}; camDir.v[0] = fm_cosf(camRotXCurr) * fm_cosf(camRotYCurr); camDir.v[1] = fm_sinf(camRotYCurr); camDir.v[2] = fm_sinf(camRotXCurr) * fm_cosf(camRotYCurr); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotX += (float)joypad.stick_x * camRotSpeed; @@ -38,7 +38,7 @@ void FlyCam::update(float deltaTime) camPos.v[2] -= camDir.v[0] * (float)joypad.stick_x * -camSpeed; } - t3d_vec3_lerp(cam.pos, cam.pos, camPos, smoothFactor); + fm_vec3_lerp(&cam.pos, &cam.pos, &camPos, smoothFactor); auto actualTarget = cam.pos + camDir; cam.target = actualTarget; } \ No newline at end of file diff --git a/examples/24_hdr_bloom/src/camera/flyCam.h b/examples/24_hdr_bloom/src/camera/flyCam.h index 6591f0dd..35567bdf 100644 --- a/examples/24_hdr_bloom/src/camera/flyCam.h +++ b/examples/24_hdr_bloom/src/camera/flyCam.h @@ -11,7 +11,7 @@ struct FlyCam float camRotX{}; float camRotY{}; - T3DVec3 camPos{}; + fm_vec3_t camPos{}; float camRotXCurr{}; float camRotYCurr{}; diff --git a/examples/24_hdr_bloom/src/memory/matrixManager.h b/examples/24_hdr_bloom/src/memory/matrixManager.h index 201d679a..17c0a07b 100644 --- a/examples/24_hdr_bloom/src/memory/matrixManager.h +++ b/examples/24_hdr_bloom/src/memory/matrixManager.h @@ -39,7 +39,7 @@ struct RingMat4FP { return get(); } - void fillSRT(const T3DVec3 &scale, const T3DVec3 &rot, const T3DVec3 &trans) { + void fillSRT(const fm_vec3_t &scale, const fm_vec3_t &rot, const fm_vec3_t &trans) { for(uint32_t i=0; i -#include + namespace RspFX { diff --git a/examples/99_testscene/main.c b/examples/99_testscene/main.c index 9ace5273..80aad60e 100644 --- a/examples/99_testscene/main.c +++ b/examples/99_testscene/main.c @@ -44,15 +44,15 @@ int main() sprite_t *spriteLogo = sprite_load("rom:/logo.ia8.sprite"); T3DModel *model = t3d_model_load("rom://scene.t3dm"); - T3DMat4 modelMat; // matrix for our model, this is a "normal" float matrix - t3d_mat4_identity(&modelMat); + fm_mat4_t modelMat; // matrix for our model, this is a "normal" float matrix + fm_mat4_identity(&modelMat); // Now allocate a fixed-point matrix, this is what t3d uses internally. T3DMat4FP* modelMatFP = malloc_uncached(sizeof(T3DMat4FP)); - T3DVec3 camPos = {{2.9232f, 67.6248f, 61.1093f}}; - if(testClip)camPos = (T3DVec3){{2.9232f, 37.6248f, 31.1093f}}; - T3DVec3 camTarget = {{0,0,0}}; - T3DVec3 camDir = {{0,0,1}}; + fm_vec3_t camPos = {{2.9232f, 67.6248f, 61.1093f}}; + if(testClip)camPos = (fm_vec3_t){{2.9232f, 37.6248f, 31.1093f}}; + fm_vec3_t camTarget = {{0,0,0}}; + fm_vec3_t camDir = {{0,0,1}}; float camRotX = 1.544792654048f; float camRotY = 4.05f; @@ -61,12 +61,12 @@ int main() //uint8_t colorAmbient[4] = {40, 40, 40, 0xFF}; uint8_t colorDir[4] = {0xFF, 0xFF, 0xFF, 0xFF}; - T3DVec3 lightDirVec = {{0.0f, 1.0f, 1.0f}}; - t3d_vec3_norm(&lightDirVec); + fm_vec3_t lightDirVec = {{0.0f, 1.0f, 1.0f}}; + fm_vec3_norm(&lightDirVec, &lightDirVec); float rotAngle = 0.0f; - T3DVec3 rotAxis = {{1.0f, 2.5f, 0.25f}}; - t3d_vec3_norm(&rotAxis); + fm_vec3_t rotAxis = {{1.0f, 2.5f, 0.25f}}; + fm_vec3_norm(&rotAxis, &rotAxis); double lastTimeMs = 0; float time = 0.0f; @@ -102,7 +102,7 @@ int main() camDir.v[0] = fm_cosf(camRotX) * fm_cosf(camRotY); camDir.v[1] = fm_sinf(camRotY); camDir.v[2] = fm_sinf(camRotX) * fm_cosf(camRotY); - t3d_vec3_norm(&camDir); + fm_vec3_norm(&camDir, &camDir); if(joypad.btn.z) { camRotX += (float)joypad.stick_x * camRotSpeed; @@ -158,7 +158,7 @@ int main() lightDirVec.v[0] = fm_cosf(time * 0.002f); lightDirVec.v[1] = 0.0f;//fm_sinf(time * 0.002f); lightDirVec.v[2] = fm_sinf(time * 0.002f); - t3d_vec3_norm(&lightDirVec); + fm_vec3_norm(&lightDirVec, &lightDirVec); } if(btn.l) { @@ -176,13 +176,13 @@ int main() rotAngle += 0.03f; float modelScale = 0.15f; - t3d_mat4_identity(&modelMat); - //t3d_mat4_rotate(&modelMat, &rotAxis, rotAngle); - t3d_mat4_scale(&modelMat, modelScale, modelScale, modelScale); + fm_mat4_identity(&modelMat); + //fm_mat4_from_axis_angle(&modelMat, &rotAxis, rotAngle); + fm_mat4_scale(&modelMat, &(fm_vec3_t){{modelScale, modelScale, modelScale}}); t3d_mat4_to_fixed(modelMatFP, &modelMat); t3d_viewport_set_projection(&viewport, T3D_DEG_TO_RAD(85.0f), 2.0f, 150.0f); - t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(T3DVec3){{0,1,0}}); + t3d_viewport_look_at(&viewport, &camPos, &camTarget, &(fm_vec3_t){{0,1,0}}); // ----------- DRAW ------------ // rdpq_attach(display_get(), display_get_zbuf()); @@ -204,8 +204,8 @@ int main() t3d_light_set_directional(0, colorDir, &lightDirVec); // optional directional light, can be disabled t3d_light_set_count(1); - /*t3d_light_set_point(0, colorDir, &(T3DVec3){{-10.0f, 10.0f, 0.0f}}, 0.3f, false); // optional point light, can be disabled - t3d_light_set_point(1, colorDir, &(T3DVec3){{10.0f, 10.0f, 0.0f}}, 0.3f, false); // optional point light, can be disabled + /*t3d_light_set_point(0, colorDir, &(fm_vec3_t){{-10.0f, 10.0f, 0.0f}}, 0.3f, false); // optional point light, can be disabled + t3d_light_set_point(1, colorDir, &(fm_vec3_t){{10.0f, 10.0f, 0.0f}}, 0.3f, false); // optional point light, can be disabled t3d_light_set_count(2);*/ // t3d functions can be recorded into a display list: