CScriptSpindleCamera: Brace conditionals where applicable

This commit is contained in:
Lioncash 2020-05-07 11:59:29 -04:00
parent 5cc1cd799a
commit 90e67898e4
1 changed files with 106 additions and 78 deletions

View File

@ -80,8 +80,9 @@ void CScriptSpindleCamera::ProcessInput(const CFinalInput& input, CStateManager&
void CScriptSpindleCamera::Reset(const zeus::CTransform& xf, CStateManager& mgr) { void CScriptSpindleCamera::Reset(const zeus::CTransform& xf, CStateManager& mgr) {
const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr); const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr);
if (!GetActive() || hint == nullptr) if (!GetActive() || hint == nullptr) {
return; return;
}
x33c_24_inResetThink = true; x33c_24_inResetThink = true;
mgr.GetCameraManager()->GetBallCamera()->UpdateLookAtPosition(0.01f, mgr); mgr.GetCameraManager()->GetBallCamera()->UpdateLookAtPosition(0.01f, mgr);
@ -94,46 +95,55 @@ void CScriptSpindleCamera::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId s
} }
float SSpindleProperty::GetValue(float inVar) const { float SSpindleProperty::GetValue(float inVar) const {
if (x4_input == ESpindleInput::Constant) if (x4_input == ESpindleInput::Constant) {
return x8_lowOut; return x8_lowOut;
}
float reflectRange = x14_highIn - x10_lowIn; const float reflectRange = x14_highIn - x10_lowIn;
if (zeus::close_enough(reflectRange, 0.f)) if (zeus::close_enough(reflectRange, 0.f)) {
return x8_lowOut; return x8_lowOut;
}
float reflectedVar = inVar; float reflectedVar = inVar;
if (x0_flags & 0x1 && inVar > x14_highIn) if (x0_flags & 0x1 && inVar > x14_highIn) {
reflectedVar = x14_highIn - (inVar - x14_highIn); reflectedVar = x14_highIn - (inVar - x14_highIn);
if (x0_flags & 0x2 && inVar < x10_lowIn) }
if (x0_flags & 0x2 && inVar < x10_lowIn) {
reflectedVar = x10_lowIn + (x10_lowIn - inVar); reflectedVar = x10_lowIn + (x10_lowIn - inVar);
}
float outRange = xc_highOut - x8_lowOut; const float outRange = xc_highOut - x8_lowOut;
float res = (reflectedVar - x10_lowIn) * outRange / reflectRange + x8_lowOut; const float res = (reflectedVar - x10_lowIn) * outRange / reflectRange + x8_lowOut;
if (x8_lowOut < xc_highOut) if (x8_lowOut < xc_highOut) {
return zeus::clamp(x8_lowOut, res, xc_highOut); return zeus::clamp(x8_lowOut, res, xc_highOut);
else } else {
return zeus::clamp(xc_highOut, res, x8_lowOut); return zeus::clamp(xc_highOut, res, x8_lowOut);
}
} }
void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) { void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr); const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr);
if (!GetActive() || hint == nullptr) if (!GetActive() || hint == nullptr) {
return; return;
}
zeus::CVector3f hintPos = hint->GetTranslation(); zeus::CVector3f hintPos = hint->GetTranslation();
zeus::CVector2f lookAheadPos = mgr.GetCameraManager()->GetBallCamera()->GetLookPosAhead().toVec2f(); zeus::CVector2f lookAheadPos = mgr.GetCameraManager()->GetBallCamera()->GetLookPosAhead().toVec2f();
zeus::CVector3f hintToCamDir = GetTranslation() - hintPos; zeus::CVector3f hintToCamDir = GetTranslation() - hintPos;
hintToCamDir.z() = 0.f; hintToCamDir.z() = 0.f;
zeus::CVector3f ballPos = mgr.GetPlayer().GetBallPosition(); const zeus::CVector3f ballPos = mgr.GetPlayer().GetBallPosition();
zeus::CVector3f hintToBallDir = ballPos - hintPos; zeus::CVector3f hintToBallDir = ballPos - hintPos;
float hintToBallVOff = hintToBallDir.z(); const float hintToBallVOff = hintToBallDir.z();
hintToBallDir.z() = 0.f; hintToBallDir.z() = 0.f;
zeus::CVector3f hintDir = hint->GetTransform().basis[1]; zeus::CVector3f hintDir = hint->GetTransform().basis[1];
hintDir.z() = 0.f; hintDir.z() = 0.f;
if (hintDir.canBeNormalized()) if (hintDir.canBeNormalized()) {
hintDir.normalize(); hintDir.normalize();
else } else {
hintDir = zeus::skForward; hintDir = zeus::skForward;
}
float hintToBallDist = 0.f; float hintToBallDist = 0.f;
if (hintToBallDir.canBeNormalized()) { if (hintToBallDir.canBeNormalized()) {
hintToBallDist = hintToBallDir.magnitude(); hintToBallDist = hintToBallDir.magnitude();
@ -146,9 +156,9 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
x18c_inVars.push_back(0.f); // Zero x18c_inVars.push_back(0.f); // Zero
x18c_inVars.push_back(hintToBallDist); // HintToBallDist x18c_inVars.push_back(hintToBallDist); // HintToBallDist
x18c_inVars.push_back(std::fabs(hintToBallVOff)); // HintToBallVOff x18c_inVars.push_back(std::fabs(hintToBallVOff)); // HintToBallVOff
float hintBallAngle = std::fabs(std::acos(zeus::clamp(-1.f, hintToBallDir.dot(hintDir), 1.f))); const float hintBallAngle = std::fabs(std::acos(zeus::clamp(-1.f, hintToBallDir.dot(hintDir), 1.f)));
x18c_inVars.push_back(hintBallAngle); // HintBallAngle x18c_inVars.push_back(hintBallAngle); // HintBallAngle
float hintBallCross = hintToBallDir.toVec2f().cross(hintDir.toVec2f()); const float hintBallCross = hintToBallDir.toVec2f().cross(hintDir.toVec2f());
if (hintBallCross >= 0.f) { if (hintBallCross >= 0.f) {
x18c_inVars.push_back(hintBallAngle); // HintBallRightAngle x18c_inVars.push_back(hintBallAngle); // HintBallRightAngle
x18c_inVars.push_back(2.f * M_PIF - hintBallAngle); // HintBallLeftAngle x18c_inVars.push_back(2.f * M_PIF - hintBallAngle); // HintBallLeftAngle
@ -157,7 +167,7 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
x18c_inVars.push_back(hintBallAngle); // HintBallLeftAngle x18c_inVars.push_back(hintBallAngle); // HintBallLeftAngle
} }
zeus::CVector3f hintDelta = hint->GetTranslation() - hint->GetOriginalTransform().origin; zeus::CVector3f hintDelta = hint->GetTranslation() - hint->GetOriginalTransform().origin;
float hintDeltaVOff = std::fabs(hintDelta.z()); const float hintDeltaVOff = std::fabs(hintDelta.z());
hintDelta.z() = 0.f; hintDelta.z() = 0.f;
x18c_inVars.push_back(hintDelta.canBeNormalized() ? hintDelta.magnitude() : 0.f); // HintDeltaDist x18c_inVars.push_back(hintDelta.canBeNormalized() ? hintDelta.magnitude() : 0.f); // HintDeltaDist
x18c_inVars.push_back(hintDeltaVOff); // HintDeltaVOff x18c_inVars.push_back(hintDeltaVOff); // HintDeltaVOff
@ -165,21 +175,21 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
if ((x188_flags & 0x2000) && hintToBallDist > if ((x188_flags & 0x2000) && hintToBallDist >
x2f8_deleteHintBallDist.GetValue(GetInVar(x2f8_deleteHintBallDist))) { x2f8_deleteHintBallDist.GetValue(GetInVar(x2f8_deleteHintBallDist))) {
if (hint->GetDelegatedCamera() == GetUniqueId()) if (hint->GetDelegatedCamera() == GetUniqueId()) {
mgr.GetCameraManager()->DeleteCameraHint(hint->GetUniqueId(), mgr); mgr.GetCameraManager()->DeleteCameraHint(hint->GetUniqueId(), mgr);
}
} else { } else {
if ((x188_flags & 0x800) == 0) {
if (!(x188_flags & 0x800))
hintToBallDir = hintDir; hintToBallDir = hintDir;
if (x188_flags & 0x20) { }
if ((x188_flags & 0x20) != 0) {
if (!x32c_outsideClampedAzimuth) { if (!x32c_outsideClampedAzimuth) {
if (hintBallAngle > x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir))) { if (hintBallAngle > x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir))) {
x330_lookDir = hintToBallDir; x330_lookDir = hintToBallDir;
x32c_outsideClampedAzimuth = true; x32c_outsideClampedAzimuth = true;
} }
} else { } else {
float hintCamCross = hintToCamDir.toVec2f().cross(hintDir.toVec2f()); const float hintCamCross = hintToCamDir.toVec2f().cross(hintDir.toVec2f());
if ((hintBallAngle < x310_recoverClampedAzimuthFromHintDir. if ((hintBallAngle < x310_recoverClampedAzimuthFromHintDir.
GetValue(GetInVar(x310_recoverClampedAzimuthFromHintDir)) && hintBallCross * hintCamCross < 0.f) || GetValue(GetInVar(x310_recoverClampedAzimuthFromHintDir)) && hintBallCross * hintCamCross < 0.f) ||
hintBallAngle <= x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir))) { hintBallAngle <= x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir))) {
@ -191,10 +201,11 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
} }
float newHintToCamDist = x1f0_hintToCamDist.GetValue(GetInVar(x1f0_hintToCamDist)); float newHintToCamDist = x1f0_hintToCamDist.GetValue(GetInVar(x1f0_hintToCamDist));
if (x188_flags & 0x40) if ((x188_flags & 0x40) != 0) {
newHintToCamDist = hintToBallDist + newHintToCamDist = hintToBallDist + x208_distOffsetFromBallDist.GetValue(GetInVar(x208_distOffsetFromBallDist));
x208_distOffsetFromBallDist.GetValue(GetInVar(x208_distOffsetFromBallDist)); }
newHintToCamDist = zeus::clamp(x1b0_hintToCamDistMin, newHintToCamDist, x1b4_hintToCamDistMax); newHintToCamDist = zeus::clamp(x1b0_hintToCamDistMin, newHintToCamDist, x1b4_hintToCamDistMax);
zeus::CVector3f newCamPos = GetTranslation(); zeus::CVector3f newCamPos = GetTranslation();
float hintToCamDist = hintToCamDir.magnitude(); float hintToCamDist = hintToCamDir.magnitude();
if (hintToCamDir.canBeNormalized()) { if (hintToCamDir.canBeNormalized()) {
@ -204,86 +215,93 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
hintToCamDist = x1f0_hintToCamDist.GetValue(GetInVar(x1f0_hintToCamDist)); hintToCamDist = x1f0_hintToCamDist.GetValue(GetInVar(x1f0_hintToCamDist));
} }
float hintBallToCamTargetAzimuth = float hintBallToCamTargetAzimuth = x220_hintBallToCamAzimuth.GetValue(GetInVar(x220_hintBallToCamAzimuth));
x220_hintBallToCamAzimuth.GetValue(GetInVar(x220_hintBallToCamAzimuth)); if ((x188_flags & 0x4000) == 0 && hintToCamDir.cross(hintToBallDir).z() >= 0.f) {
if (!(x188_flags & 0x4000) && hintToCamDir.cross(hintToBallDir).z() >= 0.f)
hintBallToCamTargetAzimuth = -hintBallToCamTargetAzimuth; hintBallToCamTargetAzimuth = -hintBallToCamTargetAzimuth;
}
zeus::CQuaternion hintBallToCamTargetAzimuthQuat; zeus::CQuaternion hintBallToCamTargetAzimuthQuat;
hintBallToCamTargetAzimuthQuat.rotateZ(hintBallToCamTargetAzimuth); hintBallToCamTargetAzimuthQuat.rotateZ(hintBallToCamTargetAzimuth);
zeus::CVector3f targetHintToCam = hintBallToCamTargetAzimuthQuat.transform(hintToBallDir); const zeus::CVector3f targetHintToCam = hintBallToCamTargetAzimuthQuat.transform(hintToBallDir);
zeus::CVector3f newHintToCamDir = hintToCamDir; zeus::CVector3f newHintToCamDir = hintToCamDir;
float hintToCamDeltaAngleRange = std::fabs(std::acos(zeus::clamp(-1.f, hintToCamDir.dot(targetHintToCam), 1.f))); const float hintToCamDeltaAngleRange = std::fabs(std::acos(zeus::clamp(-1.f, hintToCamDir.dot(targetHintToCam), 1.f)));
float hintToCamDeltaAngleSpeedFactor = const float hintToCamDeltaAngleSpeedFactor = zeus::clamp(
zeus::clamp(-1.f, hintToCamDeltaAngleRange / -1.f, hintToCamDeltaAngleRange / x2c8_dampingAzimuthSpeed.GetValue(GetInVar(x2c8_dampingAzimuthSpeed)), 1.f);
x2c8_dampingAzimuthSpeed.GetValue(GetInVar(x2c8_dampingAzimuthSpeed)), 1.f);
float targetHintToCamDeltaAngleVel = float targetHintToCamDeltaAngleVel =
x1c0_targetHintToCamDeltaAngleVel.GetValue(GetInVar(x1c0_targetHintToCamDeltaAngleVel)); x1c0_targetHintToCamDeltaAngleVel.GetValue(GetInVar(x1c0_targetHintToCamDeltaAngleVel));
if (x188_flags & 0x100) if ((x188_flags & 0x100) != 0) {
targetHintToCamDeltaAngleVel = zeus::clamp(-targetHintToCamDeltaAngleVel, targetHintToCamDeltaAngleVel = zeus::clamp(
x1d8_deltaAngleScaleWithCamDist.GetValue(GetInVar(x1d8_deltaAngleScaleWithCamDist)) / hintToCamDist, -targetHintToCamDeltaAngleVel,
targetHintToCamDeltaAngleVel); x1d8_deltaAngleScaleWithCamDist.GetValue(GetInVar(x1d8_deltaAngleScaleWithCamDist)) / hintToCamDist,
targetHintToCamDeltaAngleVel);
}
if ((hintToBallDir.cross(hintToCamDir).z() >= 0.f && targetHintToCam.cross(hintToCamDir).z() < 0.f) || if ((hintToBallDir.cross(hintToCamDir).z() >= 0.f && targetHintToCam.cross(hintToCamDir).z() < 0.f) ||
(hintToBallDir.cross(hintToCamDir).z() < 0.f && targetHintToCam.cross(hintToCamDir).z() >= 0.f)) { (hintToBallDir.cross(hintToCamDir).z() < 0.f && targetHintToCam.cross(hintToCamDir).z() >= 0.f)) {
float targetHintToCamDeltaAngleVelRange = const float targetHintToCamDeltaAngleVelRange =
x2e0_targetHintToCamDeltaAngleVelRange.GetValue(GetInVar(x2e0_targetHintToCamDeltaAngleVelRange)); x2e0_targetHintToCamDeltaAngleVelRange.GetValue(GetInVar(x2e0_targetHintToCamDeltaAngleVelRange));
targetHintToCamDeltaAngleVel = zeus::clamp(-targetHintToCamDeltaAngleVelRange, targetHintToCamDeltaAngleVel = zeus::clamp(-targetHintToCamDeltaAngleVelRange, targetHintToCamDeltaAngleVel,
targetHintToCamDeltaAngleVel, targetHintToCamDeltaAngleVelRange); targetHintToCamDeltaAngleVelRange);
} }
zeus::CVector3f camToBall = ballPos - GetTranslation(); zeus::CVector3f camToBall = ballPos - GetTranslation();
camToBall.z() = 0.f; camToBall.z() = 0.f;
float targetHintToCamDeltaAngle = targetHintToCamDeltaAngleVel * dt * hintToCamDeltaAngleSpeedFactor; float targetHintToCamDeltaAngle = targetHintToCamDeltaAngleVel * dt * hintToCamDeltaAngleSpeedFactor;
float camToBallDist = 0.f; float camToBallDist = 0.f;
if (camToBall.canBeNormalized()) if (camToBall.canBeNormalized()) {
camToBallDist = camToBall.magnitude(); camToBallDist = camToBall.magnitude();
}
targetHintToCamDeltaAngle *= (1.f - zeus::clamp(0.f, (camToBallDist - 2.f) * 0.5f, 1.f)) * 10.f + 1.f; targetHintToCamDeltaAngle *= (1.f - zeus::clamp(0.f, (camToBallDist - 2.f) * 0.5f, 1.f)) * 10.f + 1.f;
targetHintToCamDeltaAngle = zeus::clamp(-hintToCamDeltaAngleRange, targetHintToCamDeltaAngle = zeus::clamp(-hintToCamDeltaAngleRange,
targetHintToCamDeltaAngle, hintToCamDeltaAngleRange); targetHintToCamDeltaAngle, hintToCamDeltaAngleRange);
if (std::fabs(zeus::clamp(-1.f, hintToCamDir.dot(targetHintToCam), 1.f)) < 0.99999f) if (std::fabs(zeus::clamp(-1.f, hintToCamDir.dot(targetHintToCam), 1.f)) < 0.99999f) {
newHintToCamDir = zeus::CQuaternion::lookAt(hintToCamDir, targetHintToCam, newHintToCamDir =
targetHintToCamDeltaAngle).transform(hintToCamDir); zeus::CQuaternion::lookAt(hintToCamDir, targetHintToCam, targetHintToCamDeltaAngle).transform(hintToCamDir);
float hintBallToCamAzimuth = std::acos(zeus::clamp(-1.f, hintToBallDir.dot(newHintToCamDir), 1.f)); }
if (x188_flags & 0x10) { const float hintBallToCamAzimuth = std::acos(zeus::clamp(-1.f, hintToBallDir.dot(newHintToCamDir), 1.f));
if (std::fabs(hintBallToCamAzimuth) < if ((x188_flags & 0x10) != 0) {
x220_hintBallToCamAzimuth.GetValue(GetInVar(x220_hintBallToCamAzimuth)) || if (std::fabs(hintBallToCamAzimuth) < x220_hintBallToCamAzimuth.GetValue(GetInVar(x220_hintBallToCamAzimuth)) ||
(x188_flags & 0x8) || x33c_24_inResetThink) (x188_flags & 0x8) != 0 || x33c_24_inResetThink) {
newHintToCamDir = targetHintToCam; newHintToCamDir = targetHintToCam;
}
} }
float maxHintBallToCamAzimuth = x250_maxHintBallToCamAzimuth.GetValue(GetInVar(x250_maxHintBallToCamAzimuth)); const float maxHintBallToCamAzimuth = x250_maxHintBallToCamAzimuth.GetValue(GetInVar(x250_maxHintBallToCamAzimuth));
if (std::fabs(hintBallToCamAzimuth) > maxHintBallToCamAzimuth) { if (std::fabs(hintBallToCamAzimuth) > maxHintBallToCamAzimuth) {
x328_maxAzimuthInterpTimer += dt; x328_maxAzimuthInterpTimer += dt;
if (x328_maxAzimuthInterpTimer < 3.f) { if (x328_maxAzimuthInterpTimer < 3.f) {
float ballToCamAzimuthInterp = zeus::clamp(-1.f, x328_maxAzimuthInterpTimer / 3.f, 1.f); const float ballToCamAzimuthInterp = zeus::clamp(-1.f, x328_maxAzimuthInterpTimer / 3.f, 1.f);
float hintBallToCamAzimuthDelta = std::fabs(maxHintBallToCamAzimuth - hintBallToCamAzimuth); float hintBallToCamAzimuthDelta = std::fabs(maxHintBallToCamAzimuth - hintBallToCamAzimuth);
if (hintToBallDir.cross(newHintToCamDir).z() > 0.f) if (hintToBallDir.cross(newHintToCamDir).z() > 0.f) {
hintBallToCamAzimuthDelta = -hintBallToCamAzimuthDelta; hintBallToCamAzimuthDelta = -hintBallToCamAzimuthDelta;
}
zeus::CQuaternion hintBallToCamAzimuthQuat; zeus::CQuaternion hintBallToCamAzimuthQuat;
hintBallToCamAzimuthQuat.rotateZ(hintBallToCamAzimuthDelta * ballToCamAzimuthInterp); hintBallToCamAzimuthQuat.rotateZ(hintBallToCamAzimuthDelta * ballToCamAzimuthInterp);
newHintToCamDir = hintBallToCamAzimuthQuat.transform(newHintToCamDir); newHintToCamDir = hintBallToCamAzimuthQuat.transform(newHintToCamDir);
} else { } else {
zeus::CQuaternion hintBallToCamAzimuthQuat; zeus::CQuaternion hintBallToCamAzimuthQuat;
if (hintBallToCamTargetAzimuth > 0.f) if (hintBallToCamTargetAzimuth > 0.f) {
hintBallToCamAzimuthQuat.rotateZ(maxHintBallToCamAzimuth); hintBallToCamAzimuthQuat.rotateZ(maxHintBallToCamAzimuth);
else } else {
hintBallToCamAzimuthQuat.rotateZ(-maxHintBallToCamAzimuth); hintBallToCamAzimuthQuat.rotateZ(-maxHintBallToCamAzimuth);
}
newHintToCamDir = hintBallToCamAzimuthQuat.transform(hintToBallDir); newHintToCamDir = hintBallToCamAzimuthQuat.transform(hintToBallDir);
} }
} else { } else {
x328_maxAzimuthInterpTimer = 0.f; x328_maxAzimuthInterpTimer = 0.f;
} }
if (x188_flags & 0x20) { if ((x188_flags & 0x20) != 0) {
zeus::CVector3f hintDir2 = hint->GetTransform().basis[1]; zeus::CVector3f hintDir2 = hint->GetTransform().basis[1];
hintDir2.z() = 0.f; hintDir2.z() = 0.f;
if (hintDir2.canBeNormalized()) { if (hintDir2.canBeNormalized()) {
hintDir2.normalize(); hintDir2.normalize();
float hintCamAzimuth = std::fabs(std::acos(zeus::clamp(-1.f, hintDir2.dot(newHintToCamDir), 1.f))); float hintCamAzimuth = std::fabs(std::acos(zeus::clamp(-1.f, hintDir2.dot(newHintToCamDir), 1.f)));
float hintCamAzimuthRange = const float hintCamAzimuthRange =
x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir)); x2b0_clampedAzimuthFromHintDir.GetValue(GetInVar(x2b0_clampedAzimuthFromHintDir));
hintCamAzimuth = zeus::clamp(-hintCamAzimuthRange, hintCamAzimuth, hintCamAzimuthRange); hintCamAzimuth = zeus::clamp(-hintCamAzimuthRange, hintCamAzimuth, hintCamAzimuthRange);
if (hintDir2.cross(newHintToCamDir).z() < 0.f) if (hintDir2.cross(newHintToCamDir).z() < 0.f) {
hintCamAzimuth = -hintCamAzimuth; hintCamAzimuth = -hintCamAzimuth;
}
zeus::CQuaternion hintCamAzimuthQuat; zeus::CQuaternion hintCamAzimuthQuat;
hintCamAzimuthQuat.rotateZ(hintCamAzimuth); hintCamAzimuthQuat.rotateZ(hintCamAzimuth);
newHintToCamDir = hintCamAzimuthQuat.transform(hintDir2); newHintToCamDir = hintCamAzimuthQuat.transform(hintDir2);
@ -291,49 +309,59 @@ void CScriptSpindleCamera::Think(float dt, CStateManager& mgr) {
} }
newCamPos = hintPos + newHintToCamDir * newHintToCamDist; newCamPos = hintPos + newHintToCamDir * newHintToCamDist;
if (x188_flags & 0x80) if ((x188_flags & 0x80) != 0) {
newCamPos.z() = ballPos.z() + x298_camPosZOffset.GetValue(GetInVar(x298_camPosZOffset)); newCamPos.z() = ballPos.z() + x298_camPosZOffset.GetValue(GetInVar(x298_camPosZOffset));
else } else {
newCamPos.z() = hintPos.z() + x298_camPosZOffset.GetValue(GetInVar(x298_camPosZOffset)); newCamPos.z() = hintPos.z() + x298_camPosZOffset.GetValue(GetInVar(x298_camPosZOffset));
newCamPos.z() = zeus::clamp(x1b8_hintToCamVOffMin, newCamPos.z() - hintPos.z(), x1bc_hintToCamVOffMax) + }
hintPos.z(); newCamPos.z() =
zeus::clamp(x1b8_hintToCamVOffMin, newCamPos.z() - hintPos.z(), x1bc_hintToCamVOffMax) + hintPos.z();
float lookPosZ; float lookPosZ;
if (x188_flags & 0x200) if ((x188_flags & 0x200) != 0) {
lookPosZ = ballPos.z() + x280_lookPosZOffset.GetValue(GetInVar(x280_lookPosZOffset)); lookPosZ = ballPos.z() + x280_lookPosZOffset.GetValue(GetInVar(x280_lookPosZOffset));
else } else {
lookPosZ = hintPos.z() + x280_lookPosZOffset.GetValue(GetInVar(x280_lookPosZOffset)); lookPosZ = hintPos.z() + x280_lookPosZOffset.GetValue(GetInVar(x280_lookPosZOffset));
}
zeus::CVector3f newLookDelta(lookAheadPos - newCamPos.toVec2f(), lookPosZ - newCamPos.z()); zeus::CVector3f newLookDelta(lookAheadPos - newCamPos.toVec2f(), lookPosZ - newCamPos.z());
zeus::CVector3f newLookDirFlat = newLookDelta; zeus::CVector3f newLookDirFlat = newLookDelta;
newLookDirFlat.z() = 0.f; newLookDirFlat.z() = 0.f;
if (newLookDirFlat.canBeNormalized()) { if (newLookDirFlat.canBeNormalized()) {
float newLookDistFlat = newLookDirFlat.magnitude(); const float newLookDistFlat = newLookDirFlat.magnitude();
newLookDirFlat.normalize(); newLookDirFlat.normalize();
float camLookRelAzimuth = -x268_camLookRelAzimuth.GetValue(GetInVar(x268_camLookRelAzimuth)); float camLookRelAzimuth = -x268_camLookRelAzimuth.GetValue(GetInVar(x268_camLookRelAzimuth));
zeus::CVector3f newHintToCamDirFlat = newCamPos - hintPos; zeus::CVector3f newHintToCamDirFlat = newCamPos - hintPos;
newHintToCamDirFlat.z() = 0.f; newHintToCamDirFlat.z() = 0.f;
if (newHintToCamDirFlat.canBeNormalized()) if (newHintToCamDirFlat.canBeNormalized()) {
newHintToCamDirFlat.normalize(); newHintToCamDirFlat.normalize();
else } else {
newHintToCamDirFlat = zeus::skForward; newHintToCamDirFlat = zeus::skForward;
if (newHintToCamDirFlat.cross(hintToBallDir).z() >= 0.f) }
if (newHintToCamDirFlat.cross(hintToBallDir).z() >= 0.f) {
camLookRelAzimuth = -camLookRelAzimuth; camLookRelAzimuth = -camLookRelAzimuth;
if (x188_flags & 0x1000) }
camLookRelAzimuth *= zeus::clamp(-1.f, std::acos(std::fabs( if ((x188_flags & 0x1000) != 0) {
zeus::clamp(-1.f, hintToBallDir.dot(newHintToCamDirFlat), 1.f))) / zeus::degToRad(10.f), 1.f); camLookRelAzimuth *= zeus::clamp(
-1.f,
std::acos(std::fabs(zeus::clamp(-1.f, hintToBallDir.dot(newHintToCamDirFlat), 1.f))) / zeus::degToRad(10.f),
1.f);
}
zeus::CQuaternion azimuthQuat; zeus::CQuaternion azimuthQuat;
azimuthQuat.rotateZ(camLookRelAzimuth); azimuthQuat.rotateZ(camLookRelAzimuth);
lookAheadPos = azimuthQuat.transform(newLookDirFlat).toVec2f() * std::cos(camLookRelAzimuth) * newLookDistFlat + lookAheadPos = azimuthQuat.transform(newLookDirFlat).toVec2f() * std::cos(camLookRelAzimuth) * newLookDistFlat +
newCamPos.toVec2f(); newCamPos.toVec2f();
} }
newLookDelta = zeus::CVector3f(lookAheadPos, lookPosZ) - newCamPos; newLookDelta = zeus::CVector3f(lookAheadPos, lookPosZ) - newCamPos;
if (x188_flags & 0x1) if ((x188_flags & 0x1) != 0) {
newLookDelta = zeus::CVector3f(hintPos.toVec2f() - newCamPos.toVec2f(), newLookDelta.z()); newLookDelta = zeus::CVector3f(hintPos.toVec2f() - newCamPos.toVec2f(), newLookDelta.z());
if (x188_flags & 0x2) }
if ((x188_flags & 0x2) != 0) {
newLookDelta = lookAheadPos - hintPos.toVec2f(); newLookDelta = lookAheadPos - hintPos.toVec2f();
if (newLookDelta.canBeNormalized()) }
if (newLookDelta.canBeNormalized()) {
SetTransform(zeus::lookAt(newCamPos, newCamPos + newLookDelta.normalized())); SetTransform(zeus::lookAt(newCamPos, newCamPos + newLookDelta.normalized()));
}
} }
} }