From b8bfe325a029fe78372df7198cf33d8657f4b9f9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Apr 2014 10:03:26 -0700 Subject: [PATCH] add back code blow away in regex replacements --- interface/src/Physics.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/interface/src/Physics.cpp b/interface/src/Physics.cpp index a9f9f6b17d..30ea829c4e 100644 --- a/interface/src/Physics.cpp +++ b/interface/src/Physics.cpp @@ -8,6 +8,29 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include + +#include "Util.h" +#include "world.h" +#include "Physics.h" + +// +// Applies static friction: maxVelocity is the largest velocity for which there +// there is friction, and strength is the amount of friction force applied to reduce +// velocity. +// +void applyStaticFriction(float deltaTime, glm::vec3& velocity, float maxVelocity, float strength) { + float v = glm::length(velocity); + if (v < maxVelocity) { + velocity *= glm::clamp((1.0f - deltaTime * strength * (1.f - v / maxVelocity)), 0.0f, 1.0f); + } +} + +// +// Applies velocity damping, with a strength value for linear and squared velocity damping +// + void applyDamping(float deltaTime, glm::vec3& velocity, float linearStrength, float squaredStrength) { if (squaredStrength == 0.f) { velocity *= glm::clamp(1.f - deltaTime * linearStrength, 0.f, 1.f); @@ -18,5 +41,4 @@ void applyDamping(float deltaTime, glm::vec3& velocity, float linearStrength, fl void applyDampedSpring(float deltaTime, glm::vec3& velocity, glm::vec3& position, glm::vec3& targetPosition, float k, float damping) { -} - +} \ No newline at end of file