Fix inverted tilting pyramids when platform displacement 2 is disabled (#397)

This commit is contained in:
Arceveti
2022-06-28 06:30:49 -07:00
committed by GitHub
parent e5af0e8ca5
commit 1691e48326
2 changed files with 24 additions and 18 deletions

View File

@@ -1043,7 +1043,6 @@
#define /*0x0F4*/ oTiltingPyramidNormalX OBJECT_FIELD_F32(O_TILTING_PYRAMID_NORMAL_X_INDEX)
#define /*0x0F8*/ oTiltingPyramidNormalY OBJECT_FIELD_F32(O_TILTING_PYRAMID_NORMAL_Y_INDEX)
#define /*0x0FC*/ oTiltingPyramidNormalZ OBJECT_FIELD_F32(O_TILTING_PYRAMID_NORMAL_Z_INDEX)
#define /*0x10C*/ oTiltingPyramidMarioOnPlatform OBJECT_FIELD_S32(0x21)
/* Toad Message */
#define /*0x108*/ oToadMessageDialogId OBJECT_FIELD_U32(0x20)

View File

@@ -8,9 +8,8 @@
* Initialize the object's transform matrix with Y being up.
*/
void bhv_platform_normals_init(void) {
Mat4 *transform = &o->transform;
vec3f_set(&o->oTiltingPyramidNormalVec, 0.0f, 1.0f, 0.0f);
mtxf_align_terrain_normal(*transform, &o->oTiltingPyramidNormalVec, &o->oPosVec, 0);
mtxf_align_terrain_normal(o->transform, &o->oTiltingPyramidNormalVec, &o->oPosVec, 0);
}
/**
@@ -20,24 +19,32 @@ void bhv_platform_normals_init(void) {
void bhv_tilting_inverted_pyramid_loop(void) {
#ifndef PLATFORM_DISPLACEMENT_2
Vec3f posBeforeRotation, posAfterRotation;
// Mario's position
Vec3f m;
Vec3f marioPos, dist;
#endif
Vec3f targetNormal;
Mat4 *transform = &o->transform;
s32 marioOnPlatform = (gMarioObject->platform == o);
if (gMarioObject->platform == o) {
vec3_diff(targetNormal, &gMarioObject->oPosVec, &o->oPosVec);
if (marioOnPlatform) {
#ifndef PLATFORM_DISPLACEMENT_2
vec3f_copy(m, gMarioStates[0].pos);
linear_mtxf_mul_vec3f(*transform, posBeforeRotation, targetNormal);
// Target the normal in Mario's direction
vec3_diff(dist, gMarioStates[0].pos, &o->oPosVec);
// Get Mario's position before the rotation
vec3f_copy(marioPos, gMarioStates[0].pos);
linear_mtxf_mul_vec3f(*transform, posBeforeRotation, dist);
targetNormal[0] = dist[0];
targetNormal[2] = dist[2];
#else // PLATFORM_DISPLACEMENT_2
targetNormal[0] = gMarioStates[0].pos[0] - o->oPosX;
targetNormal[2] = gMarioStates[0].pos[2] - o->oPosZ;
#endif
targetNormal[1] = 500.0f;
vec3f_normalize(targetNormal);
o->oTiltingPyramidMarioOnPlatform = TRUE;
} else {
// Target normal is directly upwards when Mario is not on the platform.
vec3f_set(targetNormal, 0.0f, 1.0f, 0.0f);
o->oTiltingPyramidMarioOnPlatform = FALSE;
}
// Approach the normals by 0.01f towards the new goal, then create a transform matrix and orient the object.
@@ -45,16 +52,16 @@ void bhv_tilting_inverted_pyramid_loop(void) {
approach_f32_symmetric_bool(&o->oTiltingPyramidNormalX, targetNormal[0], 0.01f);
approach_f32_symmetric_bool(&o->oTiltingPyramidNormalY, targetNormal[1], 0.01f);
approach_f32_symmetric_bool(&o->oTiltingPyramidNormalZ, targetNormal[2], 0.01f);
mtxf_align_terrain_normal(*transform, &o->oTiltingPyramidNormalVec, &o->oPosVec, 0);
mtxf_align_terrain_normal(*transform, &o->oTiltingPyramidNormalVec, &o->oPosVec, 0x0);
#ifndef PLATFORM_DISPLACEMENT_2
// If Mario is on the platform, adjust his position for the platform tilt.
if (o->oTiltingPyramidMarioOnPlatform) {
linear_mtxf_mul_vec3f(*transform, posAfterRotation, targetNormal);
m[0] += posAfterRotation[0] - posBeforeRotation[0];
m[1] += posAfterRotation[1] - posBeforeRotation[1];
m[2] += posAfterRotation[2] - posBeforeRotation[2];
vec3f_copy(gMarioStates[0].pos, m);
if (marioOnPlatform) {
linear_mtxf_mul_vec3f(*transform, posAfterRotation, dist);
marioPos[0] += posAfterRotation[0] - posBeforeRotation[0];
marioPos[1] += posAfterRotation[1] - posBeforeRotation[1];
marioPos[2] += posAfterRotation[2] - posBeforeRotation[2];
vec3f_copy(gMarioStates[0].pos, marioPos);
}
#endif