From bddc9af3b66b3c2c0f85efc359a206544ccb7471 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 18 Apr 2026 00:32:50 -0500 Subject: [PATCH] "Improved" Dolphin matricies slightly --- src/dusk/engine/engine.c | 34 +++++++++---------- .../display/shader/shaderdolphin.c | 19 ++++++----- .../display/shader/shaderdolphin.h | 8 ++--- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index 55181161..ef8ea68a 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -130,24 +130,24 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { entityCameraSetZFar(cam, camCam, 100.0f); // Floor - // entityid_t floorEnt = entityManagerAdd(); - // componentid_t floorPos = entityAddComponent(floorEnt, COMPONENT_TYPE_POSITION); - // componentid_t floorMesh = entityAddComponent(floorEnt, COMPONENT_TYPE_MESH); - // componentid_t floorMat = entityAddComponent(floorEnt, COMPONENT_TYPE_MATERIAL); - // componentid_t floorPhys = entityAddComponent(floorEnt, COMPONENT_TYPE_PHYSICS); + entityid_t floorEnt = entityManagerAdd(); + componentid_t floorPos = entityAddComponent(floorEnt, COMPONENT_TYPE_POSITION); + componentid_t floorMesh = entityAddComponent(floorEnt, COMPONENT_TYPE_MESH); + componentid_t floorMat = entityAddComponent(floorEnt, COMPONENT_TYPE_MATERIAL); + componentid_t floorPhys = entityAddComponent(floorEnt, COMPONENT_TYPE_PHYSICS); - // entityPositionSetPosition(floorEnt, floorPos, (vec3){ -5.0f, 0.0f, -5.0f }); - // entityPositionSetScale(floorEnt, floorPos, (vec3){ 10.0f, 1.0f, 10.0f }); - // entityMeshSetMesh(floorEnt, floorMesh, &PLANE_MESH_SIMPLE); - // entityMaterialGetShaderMaterial(floorEnt, floorMat)->unlit.color = COLOR_GREEN; + entityPositionSetPosition(floorEnt, floorPos, (vec3){ -5.0f, 0.0f, -5.0f }); + entityPositionSetScale(floorEnt, floorPos, (vec3){ 10.0f, 1.0f, 10.0f }); + entityMeshSetMesh(floorEnt, floorMesh, &PLANE_MESH_SIMPLE); + entityMaterialGetShaderMaterial(floorEnt, floorMat)->unlit.color = COLOR_GREEN; - // entityphysics_t *floorPhysData = entityPhysicsGet(floorEnt, floorPhys); - // floorPhysData->type = PHYSICS_BODY_STATIC; - // floorPhysData->shape.type = PHYSICS_SHAPE_PLANE; - // floorPhysData->shape.data.plane.normal[0] = 0.0f; - // floorPhysData->shape.data.plane.normal[1] = 1.0f; - // floorPhysData->shape.data.plane.normal[2] = 0.0f; - // floorPhysData->shape.data.plane.distance = 0.0f; + entityphysics_t *floorPhysData = entityPhysicsGet(floorEnt, floorPhys); + floorPhysData->type = PHYSICS_BODY_STATIC; + floorPhysData->shape.type = PHYSICS_SHAPE_PLANE; + floorPhysData->shape.data.plane.normal[0] = 0.0f; + floorPhysData->shape.data.plane.normal[1] = 1.0f; + floorPhysData->shape.data.plane.normal[2] = 0.0f; + floorPhysData->shape.data.plane.distance = 0.0f; // Box phBoxEnt = entityManagerAdd(); @@ -158,7 +158,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { entityMeshSetMesh(phBoxEnt, boxMesh, &CUBE_MESH_SIMPLE); entityMaterialGetShaderMaterial(phBoxEnt, boxMat)->unlit.color = COLOR_RED; - entityPositionSetPosition(phBoxEnt, boxPos, (vec3){ 0.0f, 0.0f, 0.0f }); + entityPositionSetPosition(phBoxEnt, boxPos, (vec3){ 0.0f, 1.0f, 0.0f }); /* Run the init script. */ scriptcontext_t ctx; diff --git a/src/duskdolphin/display/shader/shaderdolphin.c b/src/duskdolphin/display/shader/shaderdolphin.c index f51b1f81..2a406eed 100644 --- a/src/duskdolphin/display/shader/shaderdolphin.c +++ b/src/duskdolphin/display/shader/shaderdolphin.c @@ -228,13 +228,14 @@ errorret_t shaderUpdateMVPDolphin() { // Set Model/View Matrix if(mvDirt) { - // guMtxConcat( - // SHADER_BOUND->matrixView, - // SHADER_BOUND->matrixModel, - // SHADER_BOUND->matrixModelView - // ); - // GX_LoadPosMtxImm(SHADER_BOUND->matrixModelView, GX_PNMTX0); - GX_LoadPosMtxImm(SHADER_BOUND->matrixView, GX_PNMTX0); + guMtxIdentity(SHADER_BOUND->matrixModel); + guMtxTransApply(SHADER_BOUND->matrixModel, SHADER_BOUND->matrixModel, 0.0F, 1.0F, 0.0F); + guMtxConcat( + SHADER_BOUND->matrixModel, + SHADER_BOUND->matrixView, + SHADER_BOUND->matrixModelView + ); + GX_LoadPosMtxImm(SHADER_BOUND->matrixModelView, GX_PNMTX0); } SHADER_BOUND->dirtyMatrix = 0; @@ -256,7 +257,9 @@ void shaderMat4ToMtx(const mat4 inGlmMatrix, Mtx outGXMatrix) { assertNotNull(inGlmMatrix, "Input matrix cannot be null"); assertNotNull(outGXMatrix, "Output matrix cannot be null"); - for(int row = 0; row < 4; ++row) {// Can perhaps be 3. + guMtxIdentity(outGXMatrix); + + for(int row = 0; row < 3; ++row) { for(int col = 0; col < 4; ++col) { outGXMatrix[row][col] = inGlmMatrix[col][row]; } diff --git a/src/duskdolphin/display/shader/shaderdolphin.h b/src/duskdolphin/display/shader/shaderdolphin.h index 69b3f58a..31183275 100644 --- a/src/duskdolphin/display/shader/shaderdolphin.h +++ b/src/duskdolphin/display/shader/shaderdolphin.h @@ -26,10 +26,10 @@ typedef struct shaderdolphin_s { mat4 model; bool_t isProjectionPerspective; - Mtx44 matrixProjection; - Mtx matrixView; - Mtx matrixModel; - Mtx matrixModelView; + alignas(32) Mtx44 matrixProjection; + alignas(32) Mtx matrixView; + alignas(32) Mtx matrixModel; + alignas(32) Mtx matrixModelView; uint_fast8_t dirtyMatrix; } shaderdolphin_t;