avoid crash and apply force for soft bodies.
copy normals for soft body vertices, to get proper lighting
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "PHY_IPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "BulletSoftBody/btSoftBody.h"
|
||||
|
||||
|
||||
KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna)
|
||||
@@ -148,8 +149,12 @@ void KX_BulletPhysicsController::setScaling(const MT_Vector3& scaling)
|
||||
}
|
||||
MT_Scalar KX_BulletPhysicsController::GetMass()
|
||||
{
|
||||
|
||||
MT_Scalar invmass = GetRigidBody()->getInvMass();
|
||||
if (GetSoftBody())
|
||||
return GetSoftBody()->getTotalMass();
|
||||
|
||||
MT_Scalar invmass = 0.f;
|
||||
if (GetRigidBody())
|
||||
invmass = GetRigidBody()->getInvMass();
|
||||
if (invmass)
|
||||
return 1.f/invmass;
|
||||
return 0.f;
|
||||
@@ -167,7 +172,7 @@ void KX_BulletPhysicsController::setRigidBody(bool rigid)
|
||||
void KX_BulletPhysicsController::SuspendDynamics(bool ghost)
|
||||
{
|
||||
btRigidBody *body = GetRigidBody();
|
||||
if (body->getActivationState() != DISABLE_SIMULATION)
|
||||
if (body && body->getActivationState() != DISABLE_SIMULATION)
|
||||
{
|
||||
btBroadphaseProxy* handle = body->getBroadphaseHandle();
|
||||
m_savedCollisionFlags = body->getCollisionFlags();
|
||||
@@ -186,7 +191,7 @@ void KX_BulletPhysicsController::SuspendDynamics(bool ghost)
|
||||
void KX_BulletPhysicsController::RestoreDynamics()
|
||||
{
|
||||
btRigidBody *body = GetRigidBody();
|
||||
if (body->getActivationState() == DISABLE_SIMULATION)
|
||||
if (body && body->getActivationState() == DISABLE_SIMULATION)
|
||||
{
|
||||
GetPhysicsEnvironment()->updateCcdPhysicsController(this,
|
||||
m_savedMass,
|
||||
@@ -241,18 +246,22 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
|
||||
|
||||
void KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
|
||||
{
|
||||
GetRigidBody()->activate(true);
|
||||
if (GetRigidBody())
|
||||
GetRigidBody()->activate(true);
|
||||
|
||||
if (!m_bDyna)
|
||||
{
|
||||
GetRigidBody()->setCollisionFlags(GetRigidBody()->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
GetCollisionObject()->setCollisionFlags(GetRigidBody()->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
} else
|
||||
{
|
||||
if (!nondynaonly)
|
||||
{
|
||||
btTransform worldTrans;
|
||||
GetRigidBody()->getMotionState()->getWorldTransform(worldTrans);
|
||||
GetRigidBody()->setCenterOfMassTransform(worldTrans);
|
||||
if (GetRigidBody())
|
||||
{
|
||||
GetRigidBody()->getMotionState()->getWorldTransform(worldTrans);
|
||||
GetRigidBody()->setCenterOfMassTransform(worldTrans);
|
||||
}
|
||||
|
||||
/*
|
||||
scaling?
|
||||
|
||||
@@ -727,6 +727,13 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
|
||||
nodes[v.getSoftBodyIndex()].m_x.getY(),
|
||||
nodes[v.getSoftBodyIndex()].m_x.getZ());
|
||||
v.SetXYZ(pt);
|
||||
|
||||
MT_Vector3 normal (
|
||||
nodes[v.getSoftBodyIndex()].m_n.getX(),
|
||||
nodes[v.getSoftBodyIndex()].m_n.getY(),
|
||||
nodes[v.getSoftBodyIndex()].m_n.getZ());
|
||||
v.SetNormal(normal);
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -862,15 +862,20 @@ void CcdPhysicsController::ApplyForce(float forceX,float forceY,float forceZ,bo
|
||||
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
}
|
||||
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
{
|
||||
btTransform xform = body->getCenterOfMassTransform();
|
||||
btTransform xform = m_object->getWorldTransform();
|
||||
|
||||
if (local)
|
||||
{
|
||||
force = xform.getBasis()*force;
|
||||
}
|
||||
body->applyCentralForce(force);
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
body->applyCentralForce(force);
|
||||
btSoftBody* soft = GetSoftBody();
|
||||
if (soft)
|
||||
soft->addForce(force);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -884,15 +889,16 @@ void CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,flo
|
||||
{
|
||||
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
}
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
{
|
||||
btTransform xform = body->getCenterOfMassTransform();
|
||||
btTransform xform = m_object->getWorldTransform();
|
||||
if (local)
|
||||
{
|
||||
angvel = xform.getBasis()*angvel;
|
||||
}
|
||||
body->setAngularVelocity(angvel);
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
body->setAngularVelocity(angvel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -908,15 +914,17 @@ void CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
|
||||
{
|
||||
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
}
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
|
||||
{
|
||||
btTransform xform = m_object->getWorldTransform();
|
||||
if (local)
|
||||
{
|
||||
linVel = xform.getBasis()*linVel;
|
||||
}
|
||||
body->setLinearVelocity(linVel);
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
body->setLinearVelocity(linVel);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -936,6 +944,7 @@ void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attac
|
||||
btRigidBody* body = GetRigidBody();
|
||||
if (body)
|
||||
body->applyImpulse(impulse,pos);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user