mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 06:13:45 -07:00
wip free cam
This commit is contained in:
parent
8a565f910a
commit
3cc9b79dcd
6 changed files with 236 additions and 26 deletions
|
@ -44,6 +44,9 @@ namespace Ship {
|
|||
|
||||
pad->gyro_x = wGyroX;
|
||||
pad->gyro_y = wGyroY;
|
||||
|
||||
pad->cam_x = wCamX;
|
||||
pad->cam_y = wCamY;
|
||||
}
|
||||
|
||||
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {
|
||||
|
|
|
@ -13,33 +13,35 @@
|
|||
namespace Ship {
|
||||
class Controller {
|
||||
|
||||
public:
|
||||
Controller(int32_t dwControllerNumber);
|
||||
public:
|
||||
Controller(int32_t dwControllerNumber);
|
||||
|
||||
void Read(OSContPad* pad);
|
||||
virtual void ReadFromSource() = 0;
|
||||
virtual void WriteToSource(ControllerCallback* controller) = 0;
|
||||
bool isRumbling;
|
||||
void Read(OSContPad* pad);
|
||||
virtual void ReadFromSource() = 0;
|
||||
virtual void WriteToSource(ControllerCallback* controller) = 0;
|
||||
bool isRumbling;
|
||||
|
||||
void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode);
|
||||
std::shared_ptr<ControllerAttachment> GetAttachment() { return Attachment; }
|
||||
int32_t GetControllerNumber() { return dwControllerNumber; }
|
||||
void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode);
|
||||
std::shared_ptr<ControllerAttachment> GetAttachment() { return Attachment; }
|
||||
int32_t GetControllerNumber() { return dwControllerNumber; }
|
||||
|
||||
protected:
|
||||
int32_t dwPressedButtons;
|
||||
std::map<int32_t, int32_t> ButtonMapping;
|
||||
int8_t wStickX;
|
||||
int8_t wStickY;
|
||||
float wGyroX;
|
||||
float wGyroY;
|
||||
|
||||
virtual std::string GetControllerType() = 0;
|
||||
virtual std::string GetConfSection() = 0;
|
||||
virtual std::string GetBindingConfSection() = 0;
|
||||
void LoadBinding();
|
||||
protected:
|
||||
int32_t dwPressedButtons;
|
||||
std::map<int32_t, int32_t> ButtonMapping;
|
||||
int8_t wStickX;
|
||||
int8_t wStickY;
|
||||
float wGyroX;
|
||||
float wGyroY;
|
||||
float wCamX;
|
||||
float wCamY;
|
||||
|
||||
private:
|
||||
std::shared_ptr<ControllerAttachment> Attachment;
|
||||
int32_t dwControllerNumber;
|
||||
virtual std::string GetControllerType() = 0;
|
||||
virtual std::string GetConfSection() = 0;
|
||||
virtual std::string GetBindingConfSection() = 0;
|
||||
void LoadBinding();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ControllerAttachment> Attachment;
|
||||
int32_t dwControllerNumber;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -114,6 +114,8 @@ typedef struct {
|
|||
/* 0x04 */ u8 err_no;
|
||||
/* 0x05 */ f32 gyro_x;
|
||||
/* 0x09 */ f32 gyro_y;
|
||||
/* 0x0D */ f32 cam_x;
|
||||
/* 0x11 */ f32 cam_y;
|
||||
} OSContPad; // size = 0x0D
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -180,6 +180,16 @@ namespace Ship {
|
|||
}
|
||||
}
|
||||
|
||||
wCamX = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTX) / 25;
|
||||
wCamY = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTY) / 25;
|
||||
|
||||
if (abs(wCamX) <= 255) {
|
||||
wCamX = 0;
|
||||
}
|
||||
if (abs(wCamY) <= 255) {
|
||||
wCamY = 0;
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(Cont, SDL_SENSOR_GYRO))
|
||||
{
|
||||
float gyroData[3];
|
||||
|
@ -357,7 +367,7 @@ namespace Ship {
|
|||
Conf[ConfSection][STR(BTN_CRIGHT)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT));
|
||||
Conf[ConfSection][STR(BTN_CLEFT)] = std::to_string(-(SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT));
|
||||
Conf[ConfSection][STR(BTN_CDOWN)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTY + AXIS_SCANCODE_BIT));
|
||||
Conf[ConfSection][STR(BTN_CUP)] = std::to_string(-(SDL_CONTROLLER_AXIS_RIGHTY + AXIS_SCANCODE_BIT));
|
||||
Conf[ConfSection][STR(BTN_CUP)] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSTICK);
|
||||
//Conf[ConfSection][STR(BTN_CRIGHT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_X);
|
||||
//Conf[ConfSection][STR(BTN_CLEFT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_Y);
|
||||
//Conf[ConfSection][STR(BTN_CDOWN + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||||
|
|
|
@ -120,6 +120,8 @@ typedef struct {
|
|||
/* 0x04 */ uint8_t err_no;
|
||||
/* 0x05 */ float gyro_x;
|
||||
/* 0x09 */ float gyro_y;
|
||||
/* 0x0D */ float cam_x;
|
||||
/* 0x11 */ float cam_y;
|
||||
} OSContPad; // size = 0x0D
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -1408,7 +1408,198 @@ s32 Camera_Noop(Camera* camera) {
|
|||
return true;
|
||||
}
|
||||
|
||||
s32 Camera_Free(Camera* camera) {
|
||||
Vec3f* eye = &camera->eye;
|
||||
Vec3f* at = &camera->at;
|
||||
Vec3f* eyeNext = &camera->eyeNext;
|
||||
f32 spA0;
|
||||
f32 sp9C;
|
||||
f32 sp98;
|
||||
f32 sp94;
|
||||
Vec3f sp88;
|
||||
s16 wiggleAdj;
|
||||
s16 t;
|
||||
VecSph eyeAdjustment;
|
||||
VecSph atEyeGeo;
|
||||
VecSph atEyeNextGeo;
|
||||
PosRot* playerPosRot = &camera->playerPosRot;
|
||||
Normal1* norm1 = (Normal1*)camera->paramData;
|
||||
Normal1Anim* anim = &norm1->anim;
|
||||
f32 playerHeight;
|
||||
f32 rate = 0.1f;
|
||||
|
||||
osSyncPrintf("\nCam Val X: %d\n", D_8015BD7C->state.input[0].cur.cam_x);
|
||||
|
||||
playerHeight = Player_GetHeight(camera->player);
|
||||
if (RELOAD_PARAMS) {
|
||||
CameraModeValue* values = sCameraSettings[camera->setting].cameraModes[camera->mode].values;
|
||||
f32 yNormal = (1.0f + PCT(R_CAM_YOFFSET_NORM) - PCT(R_CAM_YOFFSET_NORM) * (68.0f / playerHeight));
|
||||
sp94 = yNormal * PCT(playerHeight);
|
||||
|
||||
norm1->yOffset = NEXTSETTING * sp94;
|
||||
norm1->distMin = NEXTSETTING * sp94;
|
||||
norm1->distMax = NEXTSETTING * sp94;
|
||||
norm1->pitchTarget = DEGF_TO_BINANG(NEXTSETTING);
|
||||
norm1->unk_0C = NEXTSETTING;
|
||||
norm1->unk_10 = NEXTSETTING;
|
||||
norm1->unk_14 = NEXTPCT;
|
||||
norm1->fovTarget = NEXTSETTING;
|
||||
norm1->atLERPScaleMax = NEXTPCT;
|
||||
norm1->interfaceFlags = NEXTSETTING;
|
||||
}
|
||||
|
||||
if (R_RELOAD_CAM_PARAMS) {
|
||||
Camera_CopyPREGToModeValues(camera);
|
||||
}
|
||||
|
||||
sCameraInterfaceFlags = norm1->interfaceFlags;
|
||||
|
||||
OLib_Vec3fDiffToVecSphGeo(&atEyeGeo, at, eye);
|
||||
OLib_Vec3fDiffToVecSphGeo(&atEyeNextGeo, at, eyeNext);
|
||||
|
||||
switch (camera->animState) {
|
||||
case 0x14:
|
||||
camera->yawUpdateRateInv = OREG(27);
|
||||
camera->pitchUpdateRateInv = OREG(27);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
camera->animState = 1;
|
||||
sUpdateCameraDirection = 1;
|
||||
|
||||
if (anim->unk_28 != 0) {
|
||||
anim->unk_28--;
|
||||
}
|
||||
|
||||
spA0 = camera->speedRatio * PCT(OREG(25));
|
||||
sp9C = camera->speedRatio * PCT(OREG(26));
|
||||
sp98 = anim->swing.unk_18 != 0 ? PCT(OREG(25)) : spA0;
|
||||
|
||||
sp94 = (camera->xzSpeed - anim->unk_20) * (0.333333f);
|
||||
if (sp94 > 1.0f) {
|
||||
sp94 = 1.0f;
|
||||
}
|
||||
if (sp94 > -1.0f) {
|
||||
sp94 = -1.0f;
|
||||
}
|
||||
|
||||
anim->unk_20 = camera->xzSpeed;
|
||||
|
||||
|
||||
camera->yawUpdateRateInv =
|
||||
Camera_LERPCeilF(anim->swing.swingUpdateRate + (f32)(anim->swing.swingUpdateRateTimer * 2),
|
||||
camera->yawUpdateRateInv, sp98, rate);
|
||||
camera->pitchUpdateRateInv =
|
||||
Camera_LERPCeilF((f32)R_CAM_DEFA_PHI_UPDRATE + (f32)(anim->swing.swingUpdateRateTimer * 2),
|
||||
camera->pitchUpdateRateInv, sp9C, rate);
|
||||
|
||||
camera->pitchUpdateRateInv = Camera_LERPCeilF(R_CAM_DEFA_PHI_UPDRATE, camera->pitchUpdateRateInv, sp9C, rate);
|
||||
camera->xzOffsetUpdateRate = Camera_LERPCeilF(PCT(OREG(2)), camera->xzOffsetUpdateRate, spA0, rate);
|
||||
camera->yOffsetUpdateRate = Camera_LERPCeilF(PCT(OREG(3)), camera->yOffsetUpdateRate, sp9C, rate);
|
||||
camera->fovUpdateRate = Camera_LERPCeilF(PCT(OREG(4)), camera->yOffsetUpdateRate, camera->speedRatio * 0.05f, rate);
|
||||
|
||||
if (norm1->interfaceFlags & 1) {
|
||||
t = func_80044ADC(camera, BINANG_ROT180(atEyeGeo.yaw), 0);
|
||||
sp9C = ((1.0f / norm1->unk_10) * 0.5f) * (1.0f - camera->speedRatio);
|
||||
anim->slopePitchAdj = Camera_LERPCeilS(t, anim->slopePitchAdj, ((1.0f / norm1->unk_10) * 0.5f) + sp9C, 0xF);
|
||||
} else {
|
||||
anim->slopePitchAdj = 0;
|
||||
if (camera->playerGroundY == camera->playerPosRot.pos.y) {
|
||||
anim->yOffset = camera->playerPosRot.pos.y;
|
||||
}
|
||||
}
|
||||
|
||||
spA0 = ((anim->swing.unk_18 != 0) && (norm1->yOffset > -40.0f))
|
||||
? (sp9C = Math_SinS(anim->swing.unk_14), ((-40.0f * sp9C) + (norm1->yOffset * (1.0f - sp9C))))
|
||||
: norm1->yOffset;
|
||||
|
||||
if (norm1->interfaceFlags & 0x80) {
|
||||
func_800458D4(camera, &atEyeNextGeo, spA0, &anim->yOffset, norm1->interfaceFlags & 1);
|
||||
} else if (norm1->interfaceFlags & 0x20) {
|
||||
func_80045B08(camera, &atEyeNextGeo, spA0, anim->slopePitchAdj);
|
||||
} else {
|
||||
Camera_CalcAtDefault(camera, &atEyeNextGeo, spA0, norm1->interfaceFlags & 1);
|
||||
}
|
||||
|
||||
OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, at, eyeNext);
|
||||
|
||||
camera->dist = eyeAdjustment.r =
|
||||
Camera_ClampDist(camera, eyeAdjustment.r, norm1->distMin, norm1->distMax, anim->unk_28);
|
||||
|
||||
// rotate yaw to follow player.
|
||||
float newCamX = -D_8015BD7C->state.input[0].cur.cam_x;
|
||||
float newCamY = D_8015BD7C->state.input[0].cur.cam_y;
|
||||
eyeAdjustment.yaw += newCamX;
|
||||
eyeAdjustment.pitch += newCamY;
|
||||
|
||||
// set eyeAdjustment pitch from 79.65 degrees to -85 degrees
|
||||
if (eyeAdjustment.pitch > 0x38A4) {
|
||||
eyeAdjustment.pitch = 0x38A4;
|
||||
}
|
||||
if (eyeAdjustment.pitch < -0x3C8C) {
|
||||
eyeAdjustment.pitch = -0x3C8C;
|
||||
}
|
||||
|
||||
Camera_Vec3fVecSphGeoAdd(eyeNext, at, &eyeAdjustment);
|
||||
if ((camera->status == CAM_STAT_ACTIVE) && (!(norm1->interfaceFlags & 0x10))) {
|
||||
anim->swingYawTarget = BINANG_ROT180(camera->playerPosRot.rot.y);
|
||||
if (anim->startSwingTimer > 0) {
|
||||
func_80046E20(camera, &eyeAdjustment, norm1->distMin, norm1->unk_0C, &sp98, &anim->swing);
|
||||
} else {
|
||||
sp88 = *eyeNext;
|
||||
anim->swing.swingUpdateRate = camera->yawUpdateRateInv = norm1->unk_0C * 2.0f;
|
||||
if (Camera_BGCheck(camera, at, &sp88)) {
|
||||
anim->swingYawTarget = atEyeNextGeo.yaw;
|
||||
anim->startSwingTimer = -1;
|
||||
} else {
|
||||
*eye = *eyeNext;
|
||||
}
|
||||
anim->swing.unk_18 = 0;
|
||||
}
|
||||
|
||||
if (anim->swing.unk_18 != 0) {
|
||||
camera->inputDir.y =
|
||||
Camera_LERPCeilS(camera->inputDir.y + BINANG_SUB(BINANG_ROT180(anim->swing.unk_16), camera->inputDir.y),
|
||||
camera->inputDir.y, 1.0f - (0.99f * sp98), 0xA);
|
||||
}
|
||||
|
||||
if (norm1->interfaceFlags & 4) {
|
||||
camera->inputDir.x = -atEyeGeo.pitch;
|
||||
camera->inputDir.y = BINANG_ROT180(atEyeGeo.yaw);
|
||||
camera->inputDir.z = 0;
|
||||
} else {
|
||||
OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, eye, at);
|
||||
camera->inputDir.x = eyeAdjustment.pitch;
|
||||
camera->inputDir.y = eyeAdjustment.yaw;
|
||||
camera->inputDir.z = 0;
|
||||
}
|
||||
|
||||
// crit wiggle
|
||||
if (gSaveContext.health <= 16 && ((camera->globalCtx->state.frames % 256) == 0)) {
|
||||
wiggleAdj = Rand_ZeroOne() * 10000.0f;
|
||||
camera->inputDir.y = wiggleAdj + camera->inputDir.y;
|
||||
}
|
||||
} else {
|
||||
anim->swing.swingUpdateRate = norm1->unk_0C;
|
||||
anim->swing.unk_18 = 0;
|
||||
sUpdateCameraDirection = 0;
|
||||
*eye = *eyeNext;
|
||||
}
|
||||
|
||||
spA0 = (gSaveContext.health <= 16 ? 0.8f : 1.0f);
|
||||
camera->fov = Camera_LERPCeilF(norm1->fovTarget * spA0, camera->fov, camera->fovUpdateRate, 1.0f);
|
||||
camera->roll = Camera_LERPCeilS(0, camera->roll, 0.5f, 0xA);
|
||||
camera->atLERPStepScale = Camera_ClampLERPScale(camera, norm1->atLERPScaleMax);
|
||||
return 1;
|
||||
}
|
||||
|
||||
s32 Camera_Normal1(Camera* camera) {
|
||||
if (true) {
|
||||
Camera_Free(camera);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vec3f* eye = &camera->eye;
|
||||
Vec3f* at = &camera->at;
|
||||
Vec3f* eyeNext = &camera->eyeNext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue