2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2022-10-15 06:16:37 +00:00
|
|
|
#include "quake.h"
|
2020-10-03 15:22:44 +00:00
|
|
|
#include "vt.h"
|
2020-03-29 01:24:39 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
typedef struct {
|
|
|
|
/* 0x00 */ s16 index;
|
|
|
|
/* 0x02 */ s16 duration;
|
|
|
|
/* 0x04 */ Camera* cam;
|
|
|
|
/* 0x08 */ u32 type;
|
|
|
|
/* 0x0C */ s16 y;
|
|
|
|
/* 0x0E */ s16 x;
|
|
|
|
/* 0x10 */ s16 fov;
|
|
|
|
/* 0x12 */ s16 upPitchOffset;
|
|
|
|
/* 0x14 */ Vec3s orientation; // alters the orientation of the xy perturbation. Only x (pitch) and y (yaw) are used
|
|
|
|
/* 0x1A */ s16 speed;
|
|
|
|
/* 0x1C */ s16 isRelativeToScreen; // is the quake relative to the screen or on world coordinates
|
|
|
|
/* 0x1E */ s16 timer;
|
|
|
|
/* 0x20 */ s16 camId;
|
|
|
|
} QuakeRequest; // size = 0x24
|
|
|
|
|
|
|
|
QuakeRequest sQuakeRequests[4];
|
|
|
|
s16 sQuakeUnused = 1;
|
2020-03-29 01:24:39 +00:00
|
|
|
s16 sQuakeRequestCount = 0;
|
2020-04-16 18:08:23 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Vec3f* Quake_VecSphGeoAddToVec3f(Vec3f* dst, Vec3f* a, VecSph* sph) {
|
|
|
|
Vec3f vec;
|
|
|
|
Vec3f b;
|
2020-03-29 01:24:39 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
OLib_VecSphGeoToVec3f(&b, sph);
|
|
|
|
vec.x = a->x + b.x;
|
|
|
|
vec.y = a->y + b.y;
|
|
|
|
vec.z = a->z + b.z;
|
|
|
|
|
|
|
|
*dst = vec;
|
2020-03-29 01:24:39 +00:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quake_UpdateShakeInfo(QuakeRequest* req, ShakeInfo* shake, f32 y, f32 x) {
|
2022-10-15 06:16:37 +00:00
|
|
|
Vec3f* at = &req->cam->at;
|
|
|
|
Vec3f* eye = &req->cam->eye;
|
|
|
|
Vec3f offset;
|
|
|
|
VecSph sph;
|
|
|
|
VecSph eyeToAtSph;
|
|
|
|
|
|
|
|
if (req->isRelativeToScreen) {
|
|
|
|
offset.x = 0;
|
|
|
|
offset.y = 0;
|
|
|
|
offset.z = 0;
|
|
|
|
OLib_Vec3fDiffToVecSphGeo(&eyeToAtSph, eye, at);
|
|
|
|
|
|
|
|
// y shake
|
|
|
|
sph.r = req->y * y;
|
|
|
|
// point unit vector up, then add on `req->orientation`
|
|
|
|
sph.pitch = eyeToAtSph.pitch + req->orientation.x + 0x4000;
|
|
|
|
sph.yaw = eyeToAtSph.yaw + req->orientation.y;
|
|
|
|
// apply y shake
|
|
|
|
Quake_VecSphGeoAddToVec3f(&offset, &offset, &sph);
|
|
|
|
|
|
|
|
// x shake
|
|
|
|
sph.r = req->x * x;
|
|
|
|
// point unit vector left, then add on `req->orientation`
|
|
|
|
sph.pitch = eyeToAtSph.pitch + req->orientation.x;
|
|
|
|
sph.yaw = eyeToAtSph.yaw + req->orientation.y + 0x4000;
|
|
|
|
// apply x shake
|
|
|
|
Quake_VecSphGeoAddToVec3f(&offset, &offset, &sph);
|
2020-03-29 01:24:39 +00:00
|
|
|
} else {
|
2022-10-15 06:16:37 +00:00
|
|
|
offset.x = 0;
|
|
|
|
offset.y = req->y * y;
|
|
|
|
offset.z = 0;
|
|
|
|
sph.r = req->x * x;
|
|
|
|
sph.pitch = req->orientation.x;
|
|
|
|
sph.yaw = req->orientation.y;
|
|
|
|
Quake_VecSphGeoAddToVec3f(&offset, &offset, &sph);
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
shake->atOffset = shake->eyeOffset = offset;
|
|
|
|
shake->upYawOffset = 0x8000 * y;
|
|
|
|
shake->upPitchOffset = req->upPitchOffset * y;
|
|
|
|
shake->fovOffset = req->fov * y;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType1(QuakeRequest* req, ShakeInfo* shake) {
|
2020-07-30 19:50:18 +00:00
|
|
|
s32 pad;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
if (req->timer > 0) {
|
|
|
|
f32 xyOffset = Math_SinS(req->speed * req->timer);
|
2021-11-30 23:40:42 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, Rand_ZeroOne() * xyOffset);
|
|
|
|
req->timer--;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType5(QuakeRequest* req, ShakeInfo* shake) {
|
|
|
|
if (req->timer > 0) {
|
|
|
|
f32 xyOffset = Math_SinS(req->speed * req->timer);
|
2021-11-30 23:40:42 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, xyOffset);
|
|
|
|
req->timer--;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType6(QuakeRequest* req, ShakeInfo* shake) {
|
2020-07-30 19:50:18 +00:00
|
|
|
s32 pad;
|
2022-10-15 06:16:37 +00:00
|
|
|
f32 xyOffset;
|
|
|
|
|
|
|
|
req->timer--;
|
|
|
|
xyOffset = Math_SinS(req->speed * ((req->timer & 0xF) + 500));
|
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, Rand_ZeroOne() * xyOffset);
|
2020-03-29 01:24:39 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
// Not returning the timer ensures quake type 6 continues indefinitely until manually removed
|
2020-03-29 01:24:39 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType3(QuakeRequest* req, ShakeInfo* shake) {
|
|
|
|
if (req->timer > 0) {
|
|
|
|
f32 xyOffset = Math_SinS(req->speed * req->timer) * ((f32)req->timer / req->duration);
|
2021-11-30 23:40:42 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, xyOffset);
|
|
|
|
req->timer--;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType2(QuakeRequest* req, ShakeInfo* shake) {
|
|
|
|
if (req->timer > 0) {
|
|
|
|
f32 xyOffset = Rand_ZeroOne();
|
2021-11-30 23:40:42 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, Rand_ZeroOne() * xyOffset);
|
|
|
|
req->timer--;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_CallbackType4(QuakeRequest* req, ShakeInfo* shake) {
|
|
|
|
if (req->timer > 0) {
|
|
|
|
f32 xyOffset = Rand_ZeroOne() * ((f32)req->timer / req->duration);
|
2021-11-30 23:40:42 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
Quake_UpdateShakeInfo(req, shake, xyOffset, Rand_ZeroOne() * xyOffset);
|
|
|
|
req->timer--;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
s16 Quake_GetFreeIndex(void) {
|
2020-03-29 01:24:39 +00:00
|
|
|
s32 i;
|
2022-10-15 06:16:37 +00:00
|
|
|
s32 index;
|
|
|
|
s32 timerMin = 0x10000; // UINT16_MAX + 1
|
2020-03-29 01:24:39 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sQuakeRequests); i++) {
|
|
|
|
if (sQuakeRequests[i].type == QUAKE_TYPE_NONE) {
|
|
|
|
index = i;
|
|
|
|
timerMin = 0x20000; // Magic Number to indicate there was an unused quake index
|
2020-03-29 01:24:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
if (timerMin > sQuakeRequests[i].timer) {
|
|
|
|
timerMin = sQuakeRequests[i].timer;
|
|
|
|
index = i;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
if (timerMin != 0x20000) {
|
|
|
|
osSyncPrintf(VT_COL(YELLOW, BLACK) "quake: too many request %d is changed new one !!\n" VT_RST, index);
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
return index;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
QuakeRequest* Quake_RequestImpl(Camera* camera, u32 type) {
|
|
|
|
s16 index = Quake_GetFreeIndex();
|
|
|
|
QuakeRequest* req = &sQuakeRequests[index];
|
2020-03-29 01:24:39 +00:00
|
|
|
|
2022-05-01 22:06:35 +00:00
|
|
|
__osMemset(req, 0, sizeof(QuakeRequest));
|
2022-10-15 06:16:37 +00:00
|
|
|
|
2022-05-12 18:35:31 +00:00
|
|
|
req->cam = camera;
|
2022-10-15 06:16:37 +00:00
|
|
|
req->camId = camera->camId;
|
|
|
|
req->type = type;
|
|
|
|
req->isRelativeToScreen = true;
|
|
|
|
|
|
|
|
// Add a unique random identifier to the upper bits of the index
|
|
|
|
// The `~3` assumes there are only 4 requests
|
|
|
|
req->index = index + ((s16)(Rand_ZeroOne() * 0x10000) & ~3);
|
|
|
|
|
2020-03-29 01:24:39 +00:00
|
|
|
sQuakeRequestCount++;
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quake_Remove(QuakeRequest* req) {
|
2022-10-15 06:16:37 +00:00
|
|
|
req->type = QUAKE_TYPE_NONE;
|
|
|
|
req->timer = -1;
|
2020-03-29 01:24:39 +00:00
|
|
|
sQuakeRequestCount--;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
QuakeRequest* Quake_GetRequest(s16 index) {
|
|
|
|
QuakeRequest* req = &sQuakeRequests[index & 3];
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
if (req->type == QUAKE_TYPE_NONE) {
|
2020-03-29 01:24:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
if (index != req->index) {
|
2020-03-29 01:24:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
#define QUAKE_SPEED (1 << 0)
|
|
|
|
#define QUAKE_Y_OFFSET (1 << 1)
|
|
|
|
#define QUAKE_X_OFFSET (1 << 2)
|
|
|
|
#define QUAKE_FOV (1 << 3)
|
|
|
|
#define QUAKE_ROLL (1 << 4)
|
|
|
|
#define QUAKE_ORIENTATION_PITCH (1 << 5)
|
|
|
|
#define QUAKE_ORIENTATION_YAW (1 << 6)
|
|
|
|
#define QUAKE_ORIENTATION_ROLL (1 << 7)
|
|
|
|
#define QUAKE_DURATION (1 << 8)
|
|
|
|
#define QUAKE_IS_RELATIVE_TO_SCREEN (1 << 9)
|
|
|
|
|
|
|
|
QuakeRequest* Quake_SetValue(s16 index, s16 valueType, s16 value) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2020-03-29 01:24:39 +00:00
|
|
|
|
|
|
|
if (req == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
|
|
|
|
switch (valueType) {
|
|
|
|
case QUAKE_SPEED:
|
|
|
|
req->speed = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_Y_OFFSET:
|
|
|
|
req->y = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_X_OFFSET:
|
|
|
|
req->x = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_FOV:
|
|
|
|
req->fov = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_ROLL:
|
|
|
|
req->upPitchOffset = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_ORIENTATION_PITCH:
|
|
|
|
req->orientation.x = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_ORIENTATION_YAW:
|
|
|
|
req->orientation.y = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_ORIENTATION_ROLL:
|
|
|
|
req->orientation.z = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_DURATION:
|
|
|
|
req->timer = value;
|
|
|
|
req->duration = req->timer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUAKE_IS_RELATIVE_TO_SCREEN:
|
|
|
|
req->isRelativeToScreen = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! @bug UB: missing return. "req" is in v0 at this point, but doing an
|
|
|
|
//! explicit return uses an additional register.
|
|
|
|
#ifdef AVOID_UB
|
|
|
|
return req;
|
|
|
|
#endif
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
/**
|
|
|
|
* @param index
|
|
|
|
* @param speed For periodic types only, the angular frequency of the sine wave (binang / frame)
|
|
|
|
* @return true if successfully applied, false if the request does not exist
|
|
|
|
*/
|
|
|
|
u32 Quake_SetSpeed(s16 index, s16 speed) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2022-10-15 06:16:37 +00:00
|
|
|
req->speed = speed;
|
2020-03-29 01:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
/**
|
|
|
|
* @param index quake request index to apply
|
|
|
|
* @param duration Number of frames to apply the quake
|
|
|
|
* @return true if successfully applied, false if the request does not exist
|
|
|
|
*/
|
|
|
|
u32 Quake_SetDuration(s16 index, s16 duration) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2022-10-15 06:16:37 +00:00
|
|
|
req->duration = req->timer = duration;
|
2020-03-29 01:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
/**
|
|
|
|
* @param index quake request index to get
|
|
|
|
* @return Number of frames until the quake is finished
|
|
|
|
*/
|
|
|
|
s16 Quake_GetTimeLeft(s16 index) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2022-10-15 06:16:37 +00:00
|
|
|
return req->timer;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
/**
|
|
|
|
* @param index quake request index to apply
|
|
|
|
* @param y Apply up/down shake
|
|
|
|
* @param x Apply left/right shake
|
|
|
|
* @param fov Apply zooming in/out shake (binang)
|
|
|
|
* @param roll Apply rolling shake (binang)
|
|
|
|
* @return true if successfully applied, false if the request does not exist
|
|
|
|
*/
|
|
|
|
u32 Quake_SetPerturbations(s16 index, s16 y, s16 x, s16 fov, s16 roll) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2020-03-29 01:24:39 +00:00
|
|
|
req->y = y;
|
|
|
|
req->x = x;
|
2022-10-15 06:16:37 +00:00
|
|
|
req->fov = fov;
|
|
|
|
// Visual roll is indirectly achieved by offsetting the pitch in calculating the camera "Up" vector
|
|
|
|
req->upPitchOffset = roll;
|
2020-03-29 01:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
/**
|
|
|
|
* @param index quake request index to apply
|
|
|
|
* @param isRelativeToScreen Is the quake applied relative to the screen or in absolute world coordinates
|
|
|
|
* @param orientation orient the x/y shake to a different direction
|
|
|
|
* @return true if successfully applied, false if the request does not exist
|
|
|
|
*/
|
|
|
|
u32 Quake_SetOrientation(s16 index, s16 isRelativeToScreen, Vec3s orientation) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2022-10-15 06:16:37 +00:00
|
|
|
req->isRelativeToScreen = isRelativeToScreen;
|
|
|
|
req->orientation = orientation;
|
2020-03-29 01:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void Quake_Init(void) {
|
2020-03-29 01:24:39 +00:00
|
|
|
s16 i;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sQuakeRequests); i++) {
|
|
|
|
sQuakeRequests[i].type = QUAKE_TYPE_NONE;
|
|
|
|
sQuakeRequests[i].timer = 0;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
sQuakeUnused = 1;
|
2020-03-29 01:24:39 +00:00
|
|
|
sQuakeRequestCount = 0;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 Quake_Request(Camera* camera, u32 type) {
|
|
|
|
return Quake_RequestImpl(camera, type)->index;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
u32 Quake_RemoveRequest(s16 index) {
|
|
|
|
QuakeRequest* req = Quake_GetRequest(index);
|
2021-02-14 00:49:40 +00:00
|
|
|
|
|
|
|
if (req != NULL) {
|
2020-03-29 01:24:39 +00:00
|
|
|
Quake_Remove(req);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
s16 (*sQuakeCallbacks[])(QuakeRequest*, ShakeInfo*) = {
|
|
|
|
NULL, // QUAKE_TYPE_NONE
|
|
|
|
Quake_CallbackType1, // QUAKE_TYPE_1
|
|
|
|
Quake_CallbackType2, // QUAKE_TYPE_2
|
|
|
|
Quake_CallbackType3, // QUAKE_TYPE_3
|
|
|
|
Quake_CallbackType4, // QUAKE_TYPE_4
|
|
|
|
Quake_CallbackType5, // QUAKE_TYPE_5
|
|
|
|
Quake_CallbackType6, // QUAKE_TYPE_6
|
|
|
|
};
|
|
|
|
|
|
|
|
s16 Quake_Update(Camera* camera, ShakeInfo* camShake) {
|
|
|
|
f32 maxCurr;
|
|
|
|
f32 maxNext;
|
2020-03-29 01:24:39 +00:00
|
|
|
ShakeInfo shake;
|
2022-10-15 06:16:37 +00:00
|
|
|
QuakeRequest* req;
|
2020-03-29 01:24:39 +00:00
|
|
|
f32 absSpeedDiv;
|
2022-10-15 06:16:37 +00:00
|
|
|
s16* camId;
|
|
|
|
s32 index;
|
|
|
|
s32 numQuakesApplied;
|
|
|
|
u32 isDifferentCamId;
|
|
|
|
Vec3f zeroVec;
|
|
|
|
PlayState* play = camera->play;
|
|
|
|
|
|
|
|
zeroVec.x = 0.0f;
|
|
|
|
zeroVec.y = 0.0f;
|
|
|
|
zeroVec.z = 0.0f;
|
|
|
|
|
|
|
|
camShake->upPitchOffset = 0;
|
|
|
|
camShake->upYawOffset = 0;
|
|
|
|
camShake->fovOffset = 0;
|
|
|
|
|
|
|
|
camShake->atOffset.x = 0.0f;
|
|
|
|
camShake->atOffset.y = 0.0f;
|
|
|
|
camShake->atOffset.z = 0.0f;
|
|
|
|
|
|
|
|
camShake->eyeOffset.x = 0.0f;
|
|
|
|
camShake->eyeOffset.y = 0.0f;
|
|
|
|
camShake->eyeOffset.z = 0.0f;
|
|
|
|
|
|
|
|
camShake->maxOffset = 0.0f;
|
2020-03-29 01:24:39 +00:00
|
|
|
|
|
|
|
if (sQuakeRequestCount == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-15 06:16:37 +00:00
|
|
|
numQuakesApplied = 0;
|
|
|
|
for (index = 0; index < ARRAY_COUNT(sQuakeRequests); index++) {
|
|
|
|
req = &sQuakeRequests[index];
|
|
|
|
if (req->type == QUAKE_TYPE_NONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (play->cameraPtrs[req->camId] == NULL) {
|
|
|
|
osSyncPrintf(VT_COL(YELLOW, BLACK) "quake: stopped! 'coz camera [%d] killed!!\n" VT_RST, req->camId);
|
|
|
|
Quake_Remove(req);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
camId = &camera->camId;
|
|
|
|
isDifferentCamId = req->cam->camId != *camId;
|
|
|
|
absSpeedDiv = (f32)ABS(req->speed) / 0x8000;
|
|
|
|
|
|
|
|
if (sQuakeCallbacks[req->type](req, &shake) == 0) {
|
|
|
|
// Quake has reached the end of its timer.
|
|
|
|
Quake_Remove(req);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDifferentCamId) {
|
|
|
|
// Quake is attached to a different camId
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fabsf(camShake->atOffset.x) < fabsf(shake.atOffset.x)) {
|
|
|
|
camShake->atOffset.x = shake.atOffset.x;
|
|
|
|
}
|
|
|
|
if (fabsf(camShake->atOffset.y) < fabsf(shake.atOffset.y)) {
|
|
|
|
camShake->atOffset.y = shake.atOffset.y;
|
|
|
|
}
|
|
|
|
if (fabsf(camShake->atOffset.z) < fabsf(shake.atOffset.z)) {
|
|
|
|
camShake->atOffset.z = shake.atOffset.z;
|
|
|
|
}
|
|
|
|
if (fabsf(camShake->eyeOffset.x) < fabsf(shake.eyeOffset.x)) {
|
|
|
|
camShake->eyeOffset.x = shake.eyeOffset.x;
|
|
|
|
}
|
|
|
|
if (fabsf(camShake->eyeOffset.y) < fabsf(shake.eyeOffset.y)) {
|
|
|
|
camShake->eyeOffset.y = shake.eyeOffset.y;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
if (fabsf(camShake->eyeOffset.z) < fabsf(shake.eyeOffset.z)) {
|
|
|
|
camShake->eyeOffset.z = shake.eyeOffset.z;
|
|
|
|
}
|
|
|
|
if (camShake->upPitchOffset < shake.upPitchOffset) {
|
|
|
|
camShake->upPitchOffset = shake.upPitchOffset;
|
|
|
|
camShake->upYawOffset = shake.upYawOffset;
|
|
|
|
}
|
|
|
|
if (camShake->fovOffset < shake.fovOffset) {
|
|
|
|
camShake->fovOffset = shake.fovOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxCurr = OLib_Vec3fDist(&shake.atOffset, &zeroVec) * absSpeedDiv;
|
|
|
|
maxNext = OLib_Vec3fDist(&shake.eyeOffset, &zeroVec) * absSpeedDiv;
|
|
|
|
maxCurr = CLAMP_MIN(maxCurr, maxNext);
|
|
|
|
|
|
|
|
maxNext = camShake->upPitchOffset * (1.0f / 200.0f) * absSpeedDiv;
|
|
|
|
maxCurr = CLAMP_MIN(maxCurr, maxNext);
|
|
|
|
|
|
|
|
maxNext = camShake->fovOffset * (1.0f / 200.0f) * absSpeedDiv;
|
|
|
|
maxCurr = CLAMP_MIN(maxCurr, maxNext);
|
|
|
|
|
|
|
|
if (camShake->maxOffset < maxCurr) {
|
|
|
|
camShake->maxOffset = maxCurr;
|
|
|
|
}
|
|
|
|
|
|
|
|
numQuakesApplied++;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|
2022-10-15 06:16:37 +00:00
|
|
|
return numQuakesApplied;
|
2020-03-29 01:24:39 +00:00
|
|
|
}
|