Puppy Camera for 2.1 (#554)

This commit is contained in:
Fazana
2023-06-09 16:13:57 +01:00
committed by GitHub
parent 4c9a91c2be
commit 5764ae0ece
6 changed files with 441 additions and 231 deletions

View File

@@ -0,0 +1,29 @@
#include "game/puppycam2.h"
///This is the bit that defines where the angles happen. They're basically environment boxes that dictate camera behaviour.
///Permaswap is a boolean that simply determines wether or not when the camera changes at this point it stays changed. 0 means it resets when you leave, and 1 means it stays changed.
///The camera position fields accept "32767" as an ignore flag.
///The script supports anything that does not take an argument. It's reccomended to keep the scripts in puppycam_scripts.inc.c for the sake of cleanliness.
///If you do not wish to use a script in the angle, then just leave the field as 0.
// #define PUPPYCAM_SAMPLES
struct newcam_hardpos newcam_fixedcam[] =
{
#ifdef PUPPYCAM_SAMPLES
// Example Scripts
{/*Level ID*/ 16,/*Area ID*/ 1,/*Permaswap*/ 0,/*Mode*/ NC_MODE_FIXED_NOMOVE,/*Script*/ 0, //Standard params.
/*X begin*/ -540,/*Y begin*/ 800,/*Z begin*/ -3500, //Where the activation box begins
/*X end*/ 540,/*Y end*/ 2000,/*Z end*/ -1500, //Where the activation box ends.
/*Cam X*/ 0,/*Cam Y*/ 1500,/*Cam Z*/ -1000, //The position the camera gets placed for NC_MODE_FIXED and NC_MODE_FIXED_NOMOVE
/*Look X*/ 0,/*Look Y*/ 800,/*Look Z*/ -2500}, //The position the camera looks at for NC_MODE_FIXED_NOMOVE
///Another example angle. This activates a script that slowly rotates the camera around the area.
{/*Level ID*/ 16,/*Area ID*/ 1,/*Permaswap*/ 0,/*Mode*/ NC_MODE_NOROTATE,/*Script*/ 0, //Standard params.
/*X begin*/ 5716,/*Y begin*/ 400,/*Z begin*/ -859, //Where the activation box begins
/*X end*/ 6908,/*Y end*/ 1000,/*Z end*/ 62, //Where the activation box ends.
/*Cam X*/ 32767,/*Cam Y*/ 32767,/*Cam Z*/ 32767, //The position the camera gets placed for NC_MODE_FIXED and NC_MODE_FIXED_NOMOVE
/*Look X*/ 32767,/*Look Y*/ 32767,/*Look Z*/ 32767}, //The position the camera looks at for NC_MODE_FIXED_NOMOVE
#endif
};

View File

@@ -4,62 +4,56 @@
#include "text_menu_strings.h"
#if defined(PUPPYCAM)
#define NC_CAMX_EN _("Camera X Sensitivity")
#define NC_CAMY_EN _("Camera Y Sensitivity")
#define NC_INVERTX_EN _("Invert X Axis")
#define NC_INVERTY_EN _("Invert Y Axis")
#define NC_CAMC_EN _("Camera Centre Speed")
#define NC_ANALOGUE_EN _("Analogue Camera")
#define NC_SCHEME_EN _("Control Scheme")
#define OPTION_ENABLED_EN _("Enabled")
#define OPTION_DISABLED_EN _("Disabled")
#define OPTION_SCHEME1_EN _("Double Tap")
#define OPTION_SCHEME2_EN _("Single Press")
#define OPTION_SCHEME3_EN _("Classic")
#define OPTION_LANGUAGE_EN _("Language")
#define NC_WIDE_EN _("Widescreen")
#define NC_HIGHLIGHT_L _(">")
#define NC_HIGHLIGHT_R _("<")
#define NC_BUTTON_EN _("[R]: Options")
#define NC_BUTTON2_EN _("[R]: Return")
#define NC_OPTION_EN _("OPTIONS")
#define NC_CAMX_EN _("Camera Sensitivity")
#define NC_INVERTX_EN _("Invert Camera")
#define NC_CAMC_EN _("Camera Auto Turn")
#define NC_ANALOGUE_EN _("Analogue Camera")
#define NC_SCHEME_EN _("Control Scheme")
#define OPTION_ENABLED_EN _("Enabled")
#define OPTION_DISABLED_EN _("Disabled")
#define OPTION_SCHEME1_EN _("Double Tap")
#define OPTION_SCHEME2_EN _("Single Press")
#define OPTION_SCHEME3_EN _("Classic")
#define OPTION_LANGUAGE_EN _("Language")
#define NC_WIDE_EN _("Widescreen")
#define NC_HIGHLIGHT_L _(">")
#define NC_HIGHLIGHT_R _("<")
#define NC_BUTTON_EN _("[R]: Options")
#define NC_BUTTON2_EN _("[R]: Return")
#define NC_OPTION_EN _("OPTIONS")
#if MULTILANG
#define NC_CAMX_FR _("Sensibilite sur l'axe X")
#define NC_CAMY_FR _("Sensibilite sur l'axe Y")
#define NC_INVERTX_FR _("Invertir Axe X")
#define NC_INVERTY_FR _("Invertir Axe Y")
#define NC_CAMC_FR _("Vitesse de Centrage")
#define NC_ANALOGUE_FR _("Camera Analogue")
#define NC_SCHEME_FR _("Control Scheme")
#define OPTION_ENABLED_FR _("Active")
#define OPTION_DISABLED_FR _("Desactive")
#define OPTION_SCHEME1_FR _("Double Tap")
#define OPTION_SCHEME2_FR _("Single Press")
#define OPTION_SCHEME3_FR _("Classic")
#define OPTION_LANGUAGE_FR _("Language")
#define NC_WIDE_FR _("Widescreen")
#define NC_BUTTON_FR _("[R]: Options")
#define NC_BUTTON2_FR _("[R]: Retournez")
#define NC_OPTION_FR _("OPTIONS")
#define NC_CAMX_FR _("Sensibilite")
#define NC_INVERTX_FR _("Camera invertir")
#define NC_CAMC_FR _("Vitesse de Centrage")
#define NC_ANALOGUE_FR _("Camera Analogue")
#define NC_SCHEME_FR _("Control Scheme")
#define OPTION_ENABLED_FR _("Active")
#define OPTION_DISABLED_FR _("Desactive")
#define OPTION_SCHEME1_FR _("Double Tap")
#define OPTION_SCHEME2_FR _("Single Press")
#define OPTION_SCHEME3_FR _("Classic")
#define OPTION_LANGUAGE_FR _("Language")
#define NC_WIDE_FR _("Widescreen")
#define NC_BUTTON_FR _("[R]: Options")
#define NC_BUTTON2_FR _("[R]: Retournez")
#define NC_OPTION_FR _("OPTIONS")
#define NC_CAMX_DE _("Camera X Sensitivity")
#define NC_CAMY_DE _("Camera Y Sensitivity")
#define NC_INVERTY_DE _("Invert Y Axis")
#define NC_INVERTX_DE _("Invert X Axis")
#define NC_CAMC_DE _("Camera Centre Speed")
#define NC_ANALOGUE_DE _("Analogue Camera")
#define NC_SCHEME_DE _("Control Scheme")
#define OPTION_ENABLED_DE _("Enabled")
#define OPTION_DISABLED_DE _("Disabled")
#define OPTION_SCHEME1_DE _("Double Tap")
#define OPTION_SCHEME2_DE _("Single Press")
#define OPTION_SCHEME3_DE _("Classic")
#define OPTION_LANGUAGE_DE _("Language")
#define NC_WIDE_DE _("Widescreen")
#define NC_BUTTON_DE _("[R]: Options")
#define NC_BUTTON2_DE _("[R]: Return")
#define NC_OPTION_DE _("OPTIONS")
#define NC_CAMX_DE _("Camera Sensitivity")
#define NC_INVERTX_DE _("Invert Camera")
#define NC_CAMC_DE _("Camera Centre Speed")
#define NC_ANALOGUE_DE _("Analogue Camera")
#define NC_SCHEME_DE _("Control Scheme")
#define OPTION_ENABLED_DE _("Enabled")
#define OPTION_DISABLED_DE _("Disabled")
#define OPTION_SCHEME1_DE _("Double Tap")
#define OPTION_SCHEME2_DE _("Single Press")
#define OPTION_SCHEME3_DE _("Classic")
#define OPTION_LANGUAGE_DE _("Language")
#define NC_WIDE_DE _("Widescreen")
#define NC_BUTTON_DE _("[R]: Options")
#define NC_BUTTON2_DE _("[R]: Return")
#define NC_OPTION_DE _("OPTIONS")
#endif
#endif

View File

@@ -1277,7 +1277,6 @@ s32 anim_spline_poll(Vec3f result) {
* RAYCASTING *
**************************************************/
#define RAY_OFFSET 30.0f /* How many units to extrapolate surfaces when testing for a raycast */
#define RAY_STEPS 4 /* How many steps to do when casting rays, default to quartersteps. */
/**
@@ -1299,14 +1298,6 @@ s32 ray_surface_intersect(Vec3f orig, Vec3f dir, f32 dir_length, struct Surface
vec3s_to_vec3f(v0, surface->vertex1);
vec3s_to_vec3f(v1, surface->vertex2);
vec3s_to_vec3f(v2, surface->vertex3);
// Get surface normal and extend it by RAY_OFFSET.
Vec3f norm;
surface_normal_to_vec3f(norm, surface);
vec3_mul_val(norm, RAY_OFFSET);
// Move the face forward by RAY_OFFSET.
vec3f_add(v0, norm);
vec3f_add(v1, norm);
vec3f_add(v2, norm);
// Make 'e1' (edge 1) the vector from vertex 0 to vertex 1.
Vec3f e1;
vec3f_diff(e1, v1, v0);
@@ -1406,7 +1397,7 @@ void find_surface_on_ray_cell(s32 cellX, s32 cellZ, Vec3f orig, Vec3f normalized
}
}
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, s32 flags) {
f32 find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, s32 flags) {
Vec3f normalized_dir;
f32 step;
s32 i;
@@ -1434,7 +1425,7 @@ void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Ve
// Don't do DDA if straight down
if ((normalized_dir[1] >= NEAR_ONE) || (normalized_dir[1] <= -NEAR_ONE)) {
find_surface_on_ray_cell(cellX, cellZ, orig, normalized_dir, dir_length, hit_surface, hit_pos, &max_length, flags);
return;
return max_length;
}
// Get cells we cross using DDA
@@ -1465,6 +1456,7 @@ void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Ve
find_surface_on_ray_cell(cellPrevX, cellZ, orig, normalized_dir, dir_length, hit_surface, hit_pos, &max_length, flags);
}
}
return max_length;
}
// Constructs a float in registers, which can be faster than gcc's default of loading a float from rodata.

View File

@@ -606,6 +606,10 @@ f32 atan2f(f32 a, f32 b);
void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c);
void anim_spline_init(Vec4s *keyFrames);
s32 anim_spline_poll(Vec3f result);
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, s32 flags);
f32 find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, s32 flags);
ALWAYS_INLINE f32 remap(f32 x, f32 fromA, f32 toA, f32 fromB, f32 toB) {
return (x - fromA) / (toA - fromA) * (toB - fromB) + fromB;
}
#endif // MATH_UTIL_H

File diff suppressed because it is too large Load Diff

View File

@@ -47,11 +47,9 @@ struct gPuppyOptions
{
s16 analogue;
s16 sensitivityX;
s16 sensitivityY;
s16 invertX;
s16 invertY;
s16 turnAggression;
s16 inputType;
s16 turnHelper;
};
struct gPuppyStruct
@@ -63,13 +61,12 @@ struct gPuppyStruct
s16 pitchTarget; // Vertical Direction that pitch tries to be.
f32 pitchAcceleration; // Vertical Direction that sets pitchTarget.
s16 zoom; // How far the camera is currently zoomed out
u8 zoomSet; // The current setting of which zoompoint to set the target to.
s16 zoomTarget; // The value that zoom tries to be.
s16 zoomPoints[3]; // An array containing distances.
s16 targetFloorHeight; // Mario's current floor height
s16 lastTargetFloorHeight; // Mirror's mario's floor height when his velocity is not above 0.
Vec3s pos; // Where the camera is
Vec3s focus; // Where the camera's looking
Vec3f pos; // Where the camera is
Vec3f focus; // Where the camera's looking
Vec3s pan; // An offset of the camera's focus
s32 intendedFlags; // The flagset the camera tries to be when it's not held hostage.
s32 flags; // Behaviour flags that affect different properties of the camera's behaviour
@@ -90,7 +87,7 @@ struct gPuppyStruct
s16 edgePitch; // Pitch adjustment that's applied when stood near an edge. All pitch adjustment is clamped.
s16 moveZoom; // A small zoom value that's added on top of the regular zoom when moving. It's pretty subtle, but gives the feeling of a bit of speed.
u8 mode3Flags; // A flagset for classic mode.
u8 moveFlagAdd; // A bit that multiplies movement rate of axes when moving, to centre them faster.
u8 movementPitchVel; // A bit that multiplies movement rate of axes when moving, to centre them faster.
s16 targetDist[2]; // Used with secondary view targets to smooth out the between status.
s16 intendedTerrainPitch; // The pitch that the game wants the game to tilt towards, following the terrain.
s16 terrainPitch; // The pitch the game tilts towards, when following terrain inclines.
@@ -122,9 +119,9 @@ struct sPuppyAngles
//Structurally, it's exactly the same as CutsceneSplinePoint
struct sPuppySpline
{
Vec3s pos; // The vector pos of the spline index itself.
s8 index; // The index of the spline. Ends with -1
u8 speed; // The amount of frames it takes to get through this index.
Vec3s pos; // The vector pos of the spline index itself.
};
//A bounding volume for activating puppycamera scripts and angles.
@@ -198,4 +195,61 @@ extern s32 puppycam_move_spline(struct sPuppySpline splinePos[], struct sPuppySp
#endif
/**
* Backwards compatability additions from Puppycam 1.
* This adds support for the original volume format, so you can directly import them in
* without having to make any further changes.
* Naturally, because it's the old format, they will be severely more limited in flexibility.
*/
#define NC_FLAG_XTURN PUPPYCAM_BEHAVIOUR_YAW_ROTATION
#define NC_FLAG_YTURN PUPPYCAM_BEHAVIOUR_PITCH_ROTATION
#define NC_FLAG_ZOOM 0 // Stub
#define NC_FLAG_8D PUPPYCAM_BEHAVIOUR_INPUT_8DIR
#define NC_FLAG_4D PUPPYCAM_BEHAVIOUR_INPUT_4DIR
#define NC_FLAG_2D PUPPYCAM_BEHAVIOUR_INPUT_2D
#define NC_FLAG_FOCUSX PUPPYCAM_BEHAVIOUR_X_MOVEMENT
#define NC_FLAG_FOCUSY PUPPYCAM_BEHAVIOUR_Y_MOVEMENT
#define NC_FLAG_FOCUSZ PUPPYCAM_BEHAVIOUR_Z_MOVEMENT
#define NC_FLAG_POSX PUPPYCAM_BEHAVIOUR_X_MOVEMENT
#define NC_FLAG_POSY PUPPYCAM_BEHAVIOUR_Y_MOVEMENT
#define NC_FLAG_POSZ PUPPYCAM_BEHAVIOUR_Z_MOVEMENT
#define NC_FLAG_COLLISION PUPPYCAM_BEHAVIOUR_COLLISION
#define NC_FLAG_SLIDECORRECT 0 // Stub
#define NC_MODE_NORMAL 1
#define NC_MODE_SLIDE 2
#define NC_MODE_FIXED 3
#define NC_MODE_2D 4
#define NC_MODE_8D 5
#define NC_MODE_FIXED_NOMOVE 6
#define NC_MODE_FIXED_NOTURN 7
#define NC_MODE_NOROTATE 8
enum PuppyCamInput {
INPUT_DOUBLE_TAP,
INPUT_SINGLE_PRESS,
INPUT_CLASSIC
};
struct newcam_hardpos {
u8 newcam_hard_levelID;
u8 newcam_hard_areaID;
u8 newcam_hard_permaswap;
u16 newcam_hard_modeset;
void *newcam_hard_script;
s16 newcam_hard_X1;
s16 newcam_hard_Y1;
s16 newcam_hard_Z1;
s16 newcam_hard_X2;
s16 newcam_hard_Y2;
s16 newcam_hard_Z2;
s16 newcam_hard_camX;
s16 newcam_hard_camY;
s16 newcam_hard_camZ;
s16 newcam_hard_lookX;
s16 newcam_hard_lookY;
s16 newcam_hard_lookZ;
};
extern struct newcam_hardpos newcam_fixedcam[];
#endif // PUPPYCAM2_H