Skip to content

Commit

Permalink
xrGame/ActorCameras: more correct way of comparing floats
Browse files Browse the repository at this point in the history
And a bit of refactoring
Added new console command to change the interpolation (available only in
debug)
  • Loading branch information
Xottab-DUTY committed Sep 26, 2019
1 parent ebf32bb commit 10d27e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/xrGame/ActorCameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,11 @@ void CActor::cam_Lookout(const Fmatrix& xform, float camera_height)
r_torso.roll = 0.f;
}
}
#ifdef DEBUG

BOOL ik_cam_shift = true;
float ik_cam_shift_tolerance = 0.2f;
float ik_cam_shift_speed = 0.01f;
#else
static const BOOL ik_cam_shift = true;
static const float ik_cam_shift_tolerance = 0.2f;
static const float ik_cam_shift_speed = 0.01f;
#endif
float ik_cam_shift_interpolation = 4.f;

void CActor::cam_Update(float dt, float fFOV)
{
Expand Down Expand Up @@ -312,13 +308,14 @@ void CActor::cam_Update(float dt, float fFOV)
current_ik_cam_shift = 0;

// Alex ADD: smooth crouch fix
float HeightInterpolationSpeed = 4.f;

const float targetHeight = CameraHeight();
if (CurrentHeight < 0.0f)
CurrentHeight = CameraHeight();

if (CurrentHeight != CameraHeight())
CurrentHeight = (CurrentHeight * (1.0f - HeightInterpolationSpeed*dt)) + (CameraHeight() * HeightInterpolationSpeed*dt);
CurrentHeight = targetHeight;
else if (!fsimilar(CurrentHeight, targetHeight))
{
const float dti = ik_cam_shift_interpolation * dt;
CurrentHeight = (CurrentHeight * (1.0f - dti)) + (targetHeight * dti);
}

Fvector point = { 0, CurrentHeight + current_ik_cam_shift, 0 };

Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,8 @@ void CCC_RegisterCommands()
CMD4(CCC_Float, "ik_cam_shift_tolerance", &ik_cam_shift_tolerance, 0.f, 2.f);
extern float ik_cam_shift_speed;
CMD4(CCC_Float, "ik_cam_shift_speed", &ik_cam_shift_speed, 0.f, 1.f);
extern float ik_cam_shift_interpolation;
CMD4(CCC_Float, "ik_cam_shift_interpolation", &ik_cam_shift_interpolation, 1.f, 10.f);
extern BOOL dbg_draw_doors;
CMD4(CCC_Integer, "dbg_draw_doors", &dbg_draw_doors, FALSE, TRUE);

Expand Down

0 comments on commit 10d27e4

Please sign in to comment.