Local view weapon no longer disturbing while aiming

This commit is contained in:
yvt 2013-08-26 17:17:25 +09:00
parent a8451adb17
commit 0824bffd19
3 changed files with 26 additions and 0 deletions

View File

@ -595,6 +595,24 @@ namespace spades {
if(dt > 0.f)
viewWeaponOffset *= powf(.02f, dt);
if(player->GetTool() == Player::ToolWeapon &&
player->GetWeaponInput().secondary) {
if(dt > 0.f)
viewWeaponOffset *= powf(.01f, dt);
const float limitX = .01f;
const float limitY = .01f;
if(viewWeaponOffset.x < -limitX)
viewWeaponOffset.x = Mix(viewWeaponOffset.x, -limitX, .5f);
if(viewWeaponOffset.x > limitX)
viewWeaponOffset.x = Mix(viewWeaponOffset.x, limitX, .5f);
if(viewWeaponOffset.z < 0.f)
viewWeaponOffset.z = Mix(viewWeaponOffset.z, 0.f, .5f);
if(viewWeaponOffset.z > limitY)
viewWeaponOffset.z = Mix(viewWeaponOffset.z, limitY, .5f);
}
}else{
viewWeaponOffset = MakeVector3(0,0,0);
}

View File

@ -473,6 +473,12 @@ namespace spades {
return v * v * (3.f - 2.f * v);
}
float Mix(float a, float b, float frac) {
return a + (b - a) * frac;
}
Vector2 Mix(Vector2 a, Vector2 b, float frac) {
return a + (b - a) * frac;
}
Vector3 Mix(Vector3 a, Vector3 b, float frac) {
return a + (b - a) * frac;
}

View File

@ -665,6 +665,8 @@ namespace spades {
vec.resize(vec.size() - 1);
}
float Mix(float a, float b, float frac);
Vector2 Mix(Vector2 a, Vector2 b, float frac);
Vector3 Mix(Vector3 a, Vector3 b, float frac);
/** @return true if any portion of the box is in the positive side of plane. */