Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some new freecam features #71

Merged
merged 8 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/libpm-jp.a
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pm_fioDeserializeState = 0x8002B450;
pm_fioReadFlash = 0x8002B828;
pm_fioWriteFlash = 0x8002B908;
pm_setCurtainScaleGoal = 0x8002BE9C;
pm_update_cameras = 0x8002D090;
pm_update_camera_zone_interp = 0x80031124;
pm_setCurtainDrawCallback = 0x8002BEC4;
pm_setCurtainFadeGoal = 0x8002BED4;
pm_setGameMode = 0x80033180;
Expand Down
2 changes: 2 additions & 0 deletions lib/libpm-us.a
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pm_fioWriteFlash = 0x8002B948;
pm_setCurtainScaleGoal = 0x8002BEDC;
pm_setCurtainDrawCallback = 0x8002BF04;
pm_setCurtainFadeGoal = 0x8002BF14;
pm_update_cameras = 0x8002D400;
pm_update_camera_zone_interp = 0x80031494;
pm_setGameMode = 0x800334F0;
pm_get_npc_safe = 0x8003AB48;
pm_func_800554A4 = 0x800554A4;
Expand Down
29 changes: 21 additions & 8 deletions src/fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "sys/resource.h"
#include "util/geometry.h"
#include "util/watchlist.h"
#include <math.h>
#include <n64.h>
#include <startup.h>
#include <stdlib.h>
Expand Down Expand Up @@ -378,21 +379,33 @@ void fpDrawLog(struct GfxFont *font, s32 cellWidth, s32 cellHeight, u8 menuAlpha
void fpCamUpdate(void) {
if (fp.freeCam) {
if (!fp.camEnabledBefore) {
fp.camPos.x = pm_gCameras->lookAt_eye.x;
fp.camPos.y = pm_gCameras->lookAt_eye.y;
fp.camPos.z = pm_gCameras->lookAt_eye.z;
fp.cam.eye = pm_gCameras[pm_gCurrentCameraID].lookAt_eye;
fp.cam.pitch = pm_gCameras[pm_gCurrentCameraID].currentPitch;
fp.cam.yaw = pm_gCameras[pm_gCurrentCameraID].currentYaw;
fp.camEnabledBefore = TRUE;
} else {
fpUpdateCam();
}
Vec3f *cameraAt = &pm_gCameras->lookAt_obj;
Vec3f *cameraEye = &pm_gCameras->lookAt_eye;

*cameraEye = fp.camPos;
Vec3f *cameraAt = &pm_gCameras[pm_gCurrentCameraID].lookAt_obj;
Vec3f *cameraEye = &pm_gCameras[pm_gCurrentCameraID].lookAt_eye;

*cameraEye = fp.cam.eye;

if (fp.resetCam) {
pm_gCameras[pm_gCurrentCameraID].currentYaw = fp.cam.yaw;
fp.cam.pitch = (fp.cam.obj.y - cameraEye->y) * -1.0 /
sqrtf(SQ(fp.cam.obj.x - cameraEye->x) + SQ(fp.cam.obj.y - cameraEye->y) +
SQ(fp.cam.obj.z - cameraEye->z));
fp.cam.yaw = (fp.cam.obj.x - cameraEye->x) * -1.0 /
sqrtf(SQ(fp.cam.obj.x - cameraEye->x) + SQ(fp.cam.obj.y - cameraEye->y) +
SQ(fp.cam.obj.z - cameraEye->z));
fp.resetCam = FALSE;
}

Vec3f vf;
vec3fPy(&vf, fp.camPitch, fp.camYaw);
vec3fPy(&vf, fp.cam.pitch, fp.cam.yaw);
vec3fAdd(cameraAt, cameraEye, &vf);
pm_gCameras[pm_gCurrentCameraID].moveSpeed = 100;
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ struct LogEntry {
s32 age;
};

typedef struct {
Vec3f eye;
Vec3f obj;
f32 pitch;
f32 yaw;
} FpCam;

typedef struct {
bool ready;
struct Menu *mainMenu;
Expand Down Expand Up @@ -49,12 +56,13 @@ typedef struct {
enum CamBhv camBhv;
s16 camDistMin;
s16 camDistMax;
f32 camPitch;
f32 camYaw;
Vec3f camPos;
FpCam cam;
bool resetCam;
pm_Controller inputMask;
bool camEnabledBefore;
pm_Camera savedCam;
s8 freeCamMoveSpeed;
s8 freeCamPanSpeed;
} FpCtxt;

extern FpCtxt fp;
Expand All @@ -68,6 +76,8 @@ s32 fpImportFile(const char *path, void *data);
void fpSetInputMask(u16 pad, u8 x, u8 y);
void fpUpdateCam(void);
void fpSaveSettingsProc(struct MenuItem *item, void *data);
void setFreeCamMoveSpeed(s8 s);
void setFreeCamPanSpeed(s8 s);

struct Menu *createWarpsMenu(void);
struct Menu *createCheatsMenu(void);
Expand Down
70 changes: 53 additions & 17 deletions src/fp/fp_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static s32 enableCamProc(struct MenuItem *item, enum MenuCallbackReason reason,
} else if (reason == MENU_CALLBACK_SWITCH_OFF) {
fp.freeCam = FALSE;
pm_gCameras[pm_gCurrentCameraID].updateMode = 3;
pm_gCameras[pm_gCurrentCameraID].moveSpeed = 1;
setCamInputMask();
} else if (reason == MENU_CALLBACK_THINK) {
menuCheckboxSet(item, fp.freeCam);
Expand All @@ -39,11 +40,16 @@ static s32 lockCamProc(struct MenuItem *item, enum MenuCallbackReason reason, vo
}

static void resetCamProc(struct MenuItem *item, void *data) {
fp.camYaw = 0.f;
fp.camPitch = 0.f;
fp.camPos.x = 0.f;
fp.camPos.y = 0.f;
fp.camPos.z = 0.f;
pm_Camera cam = pm_gCameras[pm_gCurrentCameraID];
pm_gCameras[pm_gCurrentCameraID].targetPos = pm_gPlayerStatus.position;
pm_gCameras[pm_gCurrentCameraID].updateMode = 3;
pm_update_cameras();
fp.cam.eye = pm_gCameras[pm_gCurrentCameraID].lookAt_eye;
fp.cam.obj = pm_gCameras[pm_gCurrentCameraID].lookAt_obj;
fp.cam.pitch = pm_gCameras[pm_gCurrentCameraID].currentPitch;
fp.cam.yaw = pm_gCameras[pm_gCurrentCameraID].currentYaw;
pm_gCameras[pm_gCurrentCameraID] = cam;
fp.resetCam = TRUE;
}

static s32 camBhvProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
Expand Down Expand Up @@ -79,28 +85,58 @@ static s32 camDistMaxProc(struct MenuItem *item, enum MenuCallbackReason reason,
return 0;
}

static s32 camMoveSpeedProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
if (reason == MENU_CALLBACK_CHANGED) {
fp.freeCamMoveSpeed = menuIntinputGets(item);
setFreeCamMoveSpeed(fp.freeCamMoveSpeed);
} else if (reason == MENU_CALLBACK_THINK) {
if (menuIntinputGets(item) != fp.freeCamMoveSpeed) {
menuIntinputSet(item, fp.freeCamMoveSpeed);
}
}
return 0;
}

static s32 camPanSpeedProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
if (reason == MENU_CALLBACK_CHANGED) {
fp.freeCamPanSpeed = menuIntinputGets(item);
setFreeCamPanSpeed(fp.freeCamPanSpeed);
} else if (reason == MENU_CALLBACK_THINK) {
if (menuIntinputGets(item) != fp.freeCamPanSpeed) {
menuIntinputSet(item, fp.freeCamPanSpeed);
}
}
return 0;
}

struct Menu *createCameraMenu(void) {
static struct Menu menu;

int y = 0;

/* initialize menu */
menuInit(&menu, MENU_NOVALUE, MENU_NOVALUE, MENU_NOVALUE);
menu.selector = menuAddSubmenu(&menu, 0, 0, NULL, "return");
menu.selector = menuAddSubmenu(&menu, 0, y++, NULL, "return");

menuAddStatic(&menu, 0, 1, "enable", 0xC0C0C0);
menuAddCheckbox(&menu, 16, 1, enableCamProc, NULL);
menuAddStatic(&menu, 0, 2, "lock", 0xC0C0C0);
menuAddCheckbox(&menu, 16, 2, lockCamProc, NULL);
menuAddStatic(&menu, 0, 4, "behavior", 0xC0C0C0);
menuAddOption(&menu, 16, 4,
menuAddStatic(&menu, 0, y, "enable", 0xC0C0C0);
menuAddCheckbox(&menu, 16, y++, enableCamProc, NULL);
menuAddStatic(&menu, 0, y, "lock", 0xC0C0C0);
menuAddCheckbox(&menu, 16, y++, lockCamProc, NULL);
menuAddStatic(&menu, 0, ++y, "behavior", 0xC0C0C0);
menuAddOption(&menu, 16, y++,
"manual\0"
"birdseye follow\0"
"radial follow\0",
camBhvProc, NULL);
menuAddStatic(&menu, 0, 5, "distance min", 0xC0C0C0);
menuAddIntinput(&menu, 16, 5, -10, 5, camDistMinProc, NULL);
menuAddStatic(&menu, 0, 6, "distance max", 0xC0C0C0);
menuAddIntinput(&menu, 16, 6, -10, 5, camDistMaxProc, NULL);
menuAddButton(&menu, 16, 7, "reset", resetCamProc, NULL);
menuAddStatic(&menu, 0, y, "distance min", 0xC0C0C0);
menuAddIntinput(&menu, 16, y++, -10, 5, camDistMinProc, NULL);
menuAddStatic(&menu, 0, y, "distance max", 0xC0C0C0);
menuAddIntinput(&menu, 16, y++, -10, 5, camDistMaxProc, NULL);
menuAddStatic(&menu, 0, y, "move speed", 0xC0C0C0);
menuAddIntinput(&menu, 16, y++, -10, 2, camMoveSpeedProc, NULL);
menuAddStatic(&menu, 0, y, "pan speed", 0xC0C0C0);
menuAddIntinput(&menu, 16, y++, -10, 2, camPanSpeedProc, NULL);
menuAddButton(&menu, 16, y++, "reset", resetCamProc, NULL);

return &menu;
}
2 changes: 2 additions & 0 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

#define ARRAY_LENGTH(arr) (s32)(sizeof(arr) / sizeof(arr[0]))

#define SQ(x) ((x) * (x))

#endif // MACROS_H
2 changes: 2 additions & 0 deletions src/pm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,8 @@ void pm_fioWriteFlash(s32 slot, void *buffer, u32 size);
void pm_setCurtainScaleGoal(f32 goal);
void pm_setCurtainDrawCallback(void *callback);
void pm_setCurtainFadeGoal(f32 goal);
void pm_update_cameras(void);
void pm_update_camera_zone_interp(pm_Camera *camera);
void pm_setGameMode(s32 mode);
pm_Npc *pm_get_npc_safe(s32 npcID);
s32 pm_func_800554A4(s32);
Expand Down
Loading