Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-14 16:34:39 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-14 16:34:39 +0400
commit3511f8ef9fe6a2a6491fbae3a44a407f280a19e0 (patch)
tree886dfd87cd3b9b05245f8e900f2e98c82ff376a2 /source/gameengine/Physics
parent1bc31fc7f901334f0ed20317985b2a84d51714ca (diff)
BGE Physics
Clamp objects min/max velocity. Accessed with bullet physics from the advanced button with dynamic and rigid body objects. - useful for preventing unstable physics in cases where objects move too fast. - can add linear velocity with the motion actuator to give smooth motion transitions, without moving too fast. - minimum velocity means objects don't stop moving. - python scripts can adjust these values speedup or throttle velocity in the existing direction. Also made copy properties from an object with no properties work (in case you want to clear all props)
Diffstat (limited to 'source/gameengine/Physics')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp14
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h23
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsController.h6
-rw-r--r--source/gameengine/Physics/common/PHY_Pro.h6
4 files changed, 45 insertions, 4 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index 2283968801f..0b9da8f46d3 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -584,7 +584,19 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time)
if (body && !body->isStaticObject())
{
-
+
+ if ((m_cci.m_clamp_vel_max>0.0) || (m_cci.m_clamp_vel_min>0.0))
+ {
+ const btVector3& linvel = body->getLinearVelocity();
+ float len= linvel.length();
+
+ if((m_cci.m_clamp_vel_max>0.0) && (len > m_cci.m_clamp_vel_max))
+ body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_max / len));
+
+ else if ((m_cci.m_clamp_vel_min>0.0) && btFuzzyZero(len)==0 && (len < m_cci.m_clamp_vel_min))
+ body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len));
+ }
+
const btVector3& worldPos = body->getCenterOfMassPosition();
m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 245cde2baaa..c7638b36728 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -214,6 +214,8 @@ struct CcdConstructionInfo
m_gravity(0,0,0),
m_scaling(1.f,1.f,1.f),
m_mass(0.f),
+ m_clamp_vel_min(-1.f),
+ m_clamp_vel_max(-1.f),
m_restitution(0.1f),
m_friction(0.5f),
m_linearDamping(0.1f),
@@ -239,6 +241,8 @@ struct CcdConstructionInfo
btVector3 m_gravity;
btVector3 m_scaling;
btScalar m_mass;
+ btScalar m_clamp_vel_min;
+ btScalar m_clamp_vel_max;
btScalar m_restitution;
btScalar m_friction;
btScalar m_linearDamping;
@@ -479,7 +483,24 @@ class CcdPhysicsController : public PHY_IPhysicsController
}
m_cci.m_radius = margin;
}
-
+
+ // velocity clamping
+ virtual void SetLinVelocityMin(float val)
+ {
+ m_cci.m_clamp_vel_min= val;
+ }
+ virtual float GetLinVelocityMin() const
+ {
+ return m_cci.m_clamp_vel_min;
+ }
+ virtual void SetLinVelocityMax(float val)
+ {
+ m_cci.m_clamp_vel_max= val;
+ }
+ virtual float GetLinVelocityMax() const
+ {
+ return m_cci.m_clamp_vel_max;
+ }
bool wantsSleeping();
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h
index 6cba6fa88af..770426b48db 100644
--- a/source/gameengine/Physics/common/PHY_IPhysicsController.h
+++ b/source/gameengine/Physics/common/PHY_IPhysicsController.h
@@ -90,6 +90,12 @@ class PHY_IPhysicsController : public PHY_IController
virtual float GetMargin() const=0;
virtual float GetRadius() const=0;
virtual void SetRadius(float margin) = 0;
+
+ virtual float GetLinVelocityMin() const=0;
+ virtual void SetLinVelocityMin(float val) = 0;
+ virtual float GetLinVelocityMax() const=0;
+ virtual void SetLinVelocityMax(float val) = 0;
+
PHY__Vector3 GetWorldPosition(PHY__Vector3& localpos);
};
diff --git a/source/gameengine/Physics/common/PHY_Pro.h b/source/gameengine/Physics/common/PHY_Pro.h
index 32e63ac2f6d..0249fc3118a 100644
--- a/source/gameengine/Physics/common/PHY_Pro.h
+++ b/source/gameengine/Physics/common/PHY_Pro.h
@@ -35,9 +35,11 @@
struct PHY_ShapeProps {
MT_Scalar m_mass; // Total mass
MT_Scalar m_inertia; // Inertia, should be a tensor some time
- MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum
- MT_Scalar m_ang_drag; // Angular drag
+ MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum, inverted and called dampening in blenders UI
+ MT_Scalar m_ang_drag; // Angular drag, inverted and called dampening in blenders UI
MT_Scalar m_friction_scaling[3]; // Scaling for anisotropic friction. Component in range [0, 1]
+ MT_Scalar m_clamp_vel_min; // Clamp the minimum velocity, this ensures an object moves at a minimum speed unless its stationary
+ MT_Scalar m_clamp_vel_max; // Clamp max velocity
bool m_do_anisotropic; // Should I do anisotropic friction?
bool m_do_fh; // Should the object have a linear Fh spring?
bool m_do_rot_fh; // Should the object have an angular Fh spring?