BGE physics: get/set linear and angular damping
This patch adds the following R/W properties and method to `KX_GameObject`: - `linearDamping` -- get/set linear damping - `angluarDamping` -- get/set angular damping - `setDamping(linear, angular)` -- set both simultaneously These allow runtime changes to the same properties that are accessible at design time in Blender's UI via `game.damping` and `game.rotation_damping`. The names of the properties were chosen to mirror the internal names of the BGE physics engine, as these are (AFAIK) also the commonly used names in physics literature. Reviewers: campbellbarton Projects: #game_physics Differential Revision: https://developer.blender.org/D936
This commit is contained in:
@@ -207,6 +207,11 @@ btRigidBody* CcdPhysicsController::GetRigidBody()
|
||||
{
|
||||
return btRigidBody::upcast(m_object);
|
||||
}
|
||||
const btRigidBody* CcdPhysicsController::GetRigidBody() const
|
||||
{
|
||||
return btRigidBody::upcast(m_object);
|
||||
}
|
||||
|
||||
btCollisionObject* CcdPhysicsController::GetCollisionObject()
|
||||
{
|
||||
return m_object;
|
||||
@@ -1354,6 +1359,42 @@ void CcdPhysicsController::Jump()
|
||||
void CcdPhysicsController::SetActive(bool active)
|
||||
{
|
||||
}
|
||||
|
||||
float CcdPhysicsController::GetLinearDamping() const
|
||||
{
|
||||
const btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
return body->getLinearDamping();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float CcdPhysicsController::GetAngularDamping() const
|
||||
{
|
||||
const btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
return body->getAngularDamping();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CcdPhysicsController::SetLinearDamping(float damping)
|
||||
{
|
||||
SetDamping(damping, GetAngularDamping());
|
||||
}
|
||||
|
||||
void CcdPhysicsController::SetAngularDamping(float damping)
|
||||
{
|
||||
SetDamping(GetLinearDamping(), damping);
|
||||
}
|
||||
|
||||
void CcdPhysicsController::SetDamping(float linear, float angular)
|
||||
{
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (!body) return;
|
||||
|
||||
body->setDamping(linear, angular);
|
||||
}
|
||||
|
||||
|
||||
// reading out information from physics
|
||||
MT_Vector3 CcdPhysicsController::GetLinearVelocity()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user