diff --git a/assets/materials/static.skm.yaml b/assets/materials/static.skm.yaml index dcf4667..eae68ed 100644 --- a/assets/materials/static.skm.yaml +++ b/assets/materials/static.skm.yaml @@ -313,7 +313,7 @@ materials: fmt: G_IM_FMT_RGBA siz: G_IM_SIZ_32b - gDPSetRenderMode: G_RM_ZB_XLU_SURF + # gDPSetRenderMode: G_RM_ZB_XLU_SURF gDPSetCombineMode: color: ["0", "0", "0", "TEXEL0"] diff --git a/assets/models/grav_flare.blend b/assets/models/grav_flare.blend index d2a5d7f..5db7d9b 100644 Binary files a/assets/models/grav_flare.blend and b/assets/models/grav_flare.blend differ diff --git a/src/scene/ball.c b/src/scene/ball.c index 6abb331..6a8b2d9 100644 --- a/src/scene/ball.c +++ b/src/scene/ball.c @@ -7,6 +7,7 @@ #include "../physics/collision_box.h" #include "../build/assets/models/grav_flare.h" +#include "../build/assets/models/cube/cube.h" #include "../build/assets/materials/static.h" #define BALL_RADIUS 0.1f @@ -42,9 +43,11 @@ void ballInitInactive(struct Ball* ball) { } void ballInit(struct Ball* ball, struct Vector3* position, struct Vector3* velocity, short startingRoom) { - // collisionObjectInit(&ball->collisionObject, &gBallCollider, &ball->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE | COLLISION_LAYERS_BLOCK_BALL); + collisionObjectInit(&ball->collisionObject, &gBallCollider, &ball->rigidBody, 1.0f, 0); - // collisionSceneAddDynamicObject(&ball->collisionObject); + collisionSceneAddDynamicObject(&ball->collisionObject); + + ball->rigidBody.flags |= RigidBodyDisableGravity; ball->rigidBody.velocity = *velocity; ball->rigidBody.transform.position = *position; @@ -59,6 +62,10 @@ void ballInit(struct Ball* ball, struct Vector3* position, struct Vector3* veloc dynamicSceneSetRoomFlags(ball->dynamicId, ROOM_FLAG_FROM_INDEX(startingRoom)); } +void ballTurnOnCollision(struct Ball* ball) { + ball->collisionObject.collisionLayers |= COLLISION_LAYERS_BLOCK_BALL; +} + void ballUpdate(struct Ball* ball) { if (ball->targetSpeed == 0.0f) { return; @@ -79,4 +86,8 @@ void ballUpdate(struct Ball* ball) { int ballIsActive(struct Ball* ball) { return ball->targetSpeed != 0.0f; +} + +int ballIsCollisionOn(struct Ball* ball) { + return ball->collisionObject.collisionLayers != 0; } \ No newline at end of file diff --git a/src/scene/ball.h b/src/scene/ball.h index ffc4c56..b696a35 100644 --- a/src/scene/ball.h +++ b/src/scene/ball.h @@ -12,8 +12,10 @@ struct Ball { void ballInitInactive(struct Ball* ball); void ballInit(struct Ball* ball, struct Vector3* position, struct Vector3* velocity, short startingRoom); +void ballTurnOnCollision(struct Ball* ball); void ballUpdate(struct Ball* ball); int ballIsActive(struct Ball* ball); +int ballIsCollisionOn(struct Ball* ball); #endif \ No newline at end of file diff --git a/src/scene/ball_launcher.c b/src/scene/ball_launcher.c index aa967b7..52b0063 100644 --- a/src/scene/ball_launcher.c +++ b/src/scene/ball_launcher.c @@ -85,8 +85,21 @@ void ballLauncherUpdate(struct BallLauncher* launcher) { if (!ballIsActive(&launcher->currentBall) && signalsRead(launcher->signalIndex)) { struct Vector3 initialVelocity; quatMultVector(&launcher->rigidBody.transform.rotation, &gUp, &initialVelocity); - vector3Scale(&initialVelocity, &initialVelocity, BALL_VELOCITY); + vector3Scale(&initialVelocity, &initialVelocity, -BALL_VELOCITY); ballInit(&launcher->currentBall, &launcher->rigidBody.transform.position, &initialVelocity, launcher->rigidBody.currentRoom); } + + if (ballIsActive(&launcher->currentBall) && !ballIsCollisionOn(&launcher->currentBall)) { + struct Simplex simplex; + if (!gjkCheckForOverlap( + &simplex, + &launcher->collisionObject, + minkowsiSumAgainstObject, + &launcher->currentBall.collisionObject, + minkowsiSumAgainstObject, + &launcher->currentBall.rigidBody.velocity)) { + ballTurnOnCollision(&launcher->currentBall); + } + } } \ No newline at end of file