Work on ball launcher
This commit is contained in:
parent
65523d12fb
commit
77e4066259
|
@ -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"]
|
||||
|
|
Binary file not shown.
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue