[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14051] trunk/blender/source/gameengine/ Physics/Bullet/CcdPhysicsController.cpp: BGE crash when using angV & linV actuator on static objects
Benoit Bolsee
benoit.bolsee at online.be
Mon Mar 10 22:30:42 CET 2008
Revision: 14051
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14051
Author: ben2610
Date: 2008-03-10 22:30:35 +0100 (Mon, 10 Mar 2008)
Log Message:
-----------
BGE crash when using angV & linV actuator on static objects
The error was causing by the KINEMATIC flag not set automatically when the linear or angular velocity was set on static objects. Note that these actuators still won't work on static objects: the crash is fixed but not the actuator; linV and angV only work on dynamic objects. Fixing the linV and angV actuators on static object requires a bit more reflexion. For the time being, use dRot and dLoc on static objects.
Cleaned the code a bit: added systematic check on the physic controller presence before taking action.
Modified Paths:
--------------
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2008-03-10 20:58:53 UTC (rev 14050)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2008-03-10 21:30:35 UTC (rev 14051)
@@ -282,7 +282,7 @@
void CcdPhysicsController::RelativeRotate(const float rotval[9],bool local)
{
- if (m_body )
+ if (m_body)
{
m_body->activate(true);
if (m_body->isStaticObject())
@@ -326,33 +326,39 @@
}
void CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)
{
- m_body->activate(true);
- if (m_body->isStaticObject())
+ if (m_body)
{
- m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ m_body->activate(true);
+ if (m_body->isStaticObject())
+ {
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ }
+
+ m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
+ btTransform xform = m_body->getCenterOfMassTransform();
+ xform.setRotation(btQuaternion(quatImag0,quatImag1,quatImag2,quatReal));
+ m_body->setCenterOfMassTransform(xform);
+ m_bulletMotionState->setWorldTransform(xform);
}
- m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
- btTransform xform = m_body->getCenterOfMassTransform();
- xform.setRotation(btQuaternion(quatImag0,quatImag1,quatImag2,quatReal));
- m_body->setCenterOfMassTransform(xform);
- m_bulletMotionState->setWorldTransform(xform);
-
}
void CcdPhysicsController::setPosition(float posX,float posY,float posZ)
{
- m_body->activate(true);
- if (m_body->isStaticObject())
+ if (m_body)
{
- m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ m_body->activate(true);
+ if (m_body->isStaticObject())
+ {
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ }
+
+ m_MotionState->setWorldPosition(posX,posY,posZ);
+ btTransform xform = m_body->getCenterOfMassTransform();
+ xform.setOrigin(btVector3(posX,posY,posZ));
+ m_body->setCenterOfMassTransform(xform);
+ m_bulletMotionState->setWorldTransform(xform);
}
-
- m_MotionState->setWorldPosition(posX,posY,posZ);
- btTransform xform = m_body->getCenterOfMassTransform();
- xform.setOrigin(btVector3(posX,posY,posZ));
- m_body->setCenterOfMassTransform(xform);
- m_bulletMotionState->setWorldTransform(xform);
}
@@ -396,49 +402,59 @@
{
btVector3 torque(torqueX,torqueY,torqueZ);
btTransform xform = m_body->getCenterOfMassTransform();
- if (torque.length2() > (SIMD_EPSILON*SIMD_EPSILON))
+ if (m_body && torque.length2() > (SIMD_EPSILON*SIMD_EPSILON))
{
m_body->activate();
+ if (m_body->isStaticObject())
+ {
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ }
+ if (local)
+ {
+ torque = xform.getBasis()*torque;
+ }
+ m_body->applyTorque(torque);
}
- if (local)
- {
- torque = xform.getBasis()*torque;
- }
- m_body->applyTorque(torque);
}
void CcdPhysicsController::ApplyForce(float forceX,float forceY,float forceZ,bool local)
{
btVector3 force(forceX,forceY,forceZ);
- if (force.length2() > (SIMD_EPSILON*SIMD_EPSILON))
+ if (m_body && force.length2() > (SIMD_EPSILON*SIMD_EPSILON))
{
m_body->activate();
+ if (m_body->isStaticObject())
+ {
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ }
+ {
+ btTransform xform = m_body->getCenterOfMassTransform();
+ if (local)
+ {
+ force = xform.getBasis()*force;
+ }
+ }
+ m_body->applyCentralForce(force);
}
-
-
- btTransform xform = m_body->getCenterOfMassTransform();
- if (local)
- {
- force = xform.getBasis()*force;
- }
- m_body->applyCentralForce(force);
}
void CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local)
{
btVector3 angvel(ang_velX,ang_velY,ang_velZ);
- if (angvel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
+ if (m_body && angvel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
{
m_body->activate(true);
- }
-
- {
- btTransform xform = m_body->getCenterOfMassTransform();
- if (local)
+ if (m_body->isStaticObject())
{
- angvel = xform.getBasis()*angvel;
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
}
-
+ {
+ btTransform xform = m_body->getCenterOfMassTransform();
+ if (local)
+ {
+ angvel = xform.getBasis()*angvel;
+ }
+ }
m_body->setAngularVelocity(angvel);
}
@@ -447,17 +463,21 @@
{
btVector3 linVel(lin_velX,lin_velY,lin_velZ);
- if (linVel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
+ if (m_body && linVel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
{
m_body->activate(true);
- }
-
- {
- btTransform xform = m_body->getCenterOfMassTransform();
- if (local)
+ if (m_body->isStaticObject())
{
- linVel = xform.getBasis()*linVel;
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
}
+
+ {
+ btTransform xform = m_body->getCenterOfMassTransform();
+ if (local)
+ {
+ linVel = xform.getBasis()*linVel;
+ }
+ }
m_body->setLinearVelocity(linVel);
}
}
@@ -465,14 +485,16 @@
{
btVector3 impulse(impulseX,impulseY,impulseZ);
- if (impulse.length2() > (SIMD_EPSILON*SIMD_EPSILON))
+ if (m_body && impulse.length2() > (SIMD_EPSILON*SIMD_EPSILON))
{
m_body->activate();
+ if (m_body->isStaticObject())
+ {
+ m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ }
btVector3 pos(attachX,attachY,attachZ);
- m_body->activate();
-
m_body->applyImpulse(impulse,pos);
}
More information about the Bf-blender-cvs
mailing list