BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.

A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
  * Actor option: the collisioning object must have the Actor flag set to be detected
  * property/material: as specified in the collision sensors attached to it
  Broadphase filtering is important for performance reason: the collision points
  will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it

Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it

Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.

The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
  to the suface by increasing the margin in the Advanced Settings panel.
  The margin applies on both sides of the surface.

Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
  because of the Scenegraph optimizations and they can have multiple collision sensors
  on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
  on the sensor object, it is removed from the simulation and consume no CPU.

Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
  "warning btCollisionDispatcher::needsCollision: static-static collision!"
  In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.

Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
  sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.

Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
  several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
This commit is contained in:
Benoit Bolsee 2009-05-17 12:51:51 +00:00
parent 96aa60cee3
commit 3ea1c1b4b6
43 changed files with 465 additions and 302 deletions

@ -440,6 +440,7 @@ extern Object workob;
#define OB_COLLISION 65536 #define OB_COLLISION 65536
#define OB_SOFT_BODY 0x20000 #define OB_SOFT_BODY 0x20000
#define OB_OCCLUDER 0x40000 #define OB_OCCLUDER 0x40000
#define OB_SENSOR 0x80000
/* ob->gameflag2 */ /* ob->gameflag2 */
#define OB_NEVER_DO_ACTIVITY_CULLING 1 #define OB_NEVER_DO_ACTIVITY_CULLING 1
@ -459,6 +460,7 @@ extern Object workob;
#define OB_BODY_TYPE_RIGID 3 #define OB_BODY_TYPE_RIGID 3
#define OB_BODY_TYPE_SOFT 4 #define OB_BODY_TYPE_SOFT 4
#define OB_BODY_TYPE_OCCLUDER 5 #define OB_BODY_TYPE_OCCLUDER 5
#define OB_BODY_TYPE_SENSOR 6
/* ob->scavisflag */ /* ob->scavisflag */
#define OB_VIS_SENS 1 #define OB_VIS_SENS 1

@ -3562,7 +3562,7 @@ static int Object_setRBMass( BPy_Object * self, PyObject * args )
/* this is too low level, possible to add helper methods */ /* this is too low level, possible to add helper methods */
#define GAMEFLAG_MASK ( OB_OCCLUDER | OB_COLLISION | OB_DYNAMIC | OB_CHILD | OB_ACTOR | OB_DO_FH | \ #define GAMEFLAG_MASK ( OB_OCCLUDER | OB_COLLISION | OB_DYNAMIC | OB_CHILD | OB_ACTOR | OB_DO_FH | \
OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | \ OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | OB_SENSOR | \
OB_BOUNDS | OB_COLLISION_RESPONSE | OB_SECTOR | OB_PROP | \ OB_BOUNDS | OB_COLLISION_RESPONSE | OB_SECTOR | OB_PROP | \
OB_MAINACTOR ) OB_MAINACTOR )
@ -5544,6 +5544,7 @@ static PyObject *M_Object_RBFlagsDict( void )
BPy_constant *d = ( BPy_constant * ) M; BPy_constant *d = ( BPy_constant * ) M;
PyConstant_Insert( d, "OCCLUDER", PyInt_FromLong( OB_OCCLUDER ) ); PyConstant_Insert( d, "OCCLUDER", PyInt_FromLong( OB_OCCLUDER ) );
PyConstant_Insert( d, "COLLISION", PyInt_FromLong( OB_COLLISION ) ); PyConstant_Insert( d, "COLLISION", PyInt_FromLong( OB_COLLISION ) );
PyConstant_Insert( d, "SENSOR", PyInt_FromLong( OB_SENSOR ) );
PyConstant_Insert( d, "DYNAMIC", PyInt_FromLong( OB_DYNAMIC ) ); PyConstant_Insert( d, "DYNAMIC", PyInt_FromLong( OB_DYNAMIC ) );
PyConstant_Insert( d, "CHILD", PyInt_FromLong( OB_CHILD ) ); PyConstant_Insert( d, "CHILD", PyInt_FromLong( OB_CHILD ) );
PyConstant_Insert( d, "ACTOR", PyInt_FromLong( OB_ACTOR ) ); PyConstant_Insert( d, "ACTOR", PyInt_FromLong( OB_ACTOR ) );

@ -3064,29 +3064,33 @@ static void check_body_type(void *arg1_but, void *arg2_object)
Object *ob = arg2_object; Object *ob = arg2_object;
switch (ob->body_type) { switch (ob->body_type) {
case OB_BODY_TYPE_SENSOR:
ob->gameflag |= OB_SENSOR|OB_COLLISION|OB_GHOST;
ob->gameflag &= ~(OB_OCCLUDER|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
break;
case OB_BODY_TYPE_OCCLUDER: case OB_BODY_TYPE_OCCLUDER:
ob->gameflag |= OB_OCCLUDER; ob->gameflag |= OB_OCCLUDER;
ob->gameflag &= ~(OB_COLLISION|OB_DYNAMIC); ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC);
break; break;
case OB_BODY_TYPE_NO_COLLISION: case OB_BODY_TYPE_NO_COLLISION:
ob->gameflag &= ~(OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC); ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
break; break;
case OB_BODY_TYPE_STATIC: case OB_BODY_TYPE_STATIC:
ob->gameflag |= OB_COLLISION; ob->gameflag |= OB_COLLISION;
ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER); ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
break; break;
case OB_BODY_TYPE_DYNAMIC: case OB_BODY_TYPE_DYNAMIC:
ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR; ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR;
ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER); ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
break; break;
case OB_BODY_TYPE_RIGID: case OB_BODY_TYPE_RIGID:
ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR; ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR;
ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER); ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
break; break;
default: default:
case OB_BODY_TYPE_SOFT: case OB_BODY_TYPE_SOFT:
ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR; ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR;
ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER); ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR);
/* assume triangle mesh, if no bounds chosen for soft body */ /* assume triangle mesh, if no bounds chosen for soft body */
if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH)) if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
@ -3271,17 +3275,31 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
static void buttons_bullet(uiBlock *block, Object *ob) static void buttons_bullet(uiBlock *block, Object *ob)
{ {
uiBut *but; uiBut *but;
char *tip;
/* determine the body_type setting based on flags */ /* determine the body_type setting based on flags */
if (!(ob->gameflag & OB_COLLISION)) if (!(ob->gameflag & OB_COLLISION)) {
ob->body_type = (ob->gameflag & OB_OCCLUDER) ? OB_BODY_TYPE_OCCLUDER : OB_BODY_TYPE_NO_COLLISION; if (ob->gameflag & OB_OCCLUDER) {
else if (!(ob->gameflag & OB_DYNAMIC)) tip = "Occluder";
ob->body_type = OB_BODY_TYPE_OCCLUDER;
} else {
tip = "Disable colision for this object";
ob->body_type = OB_BODY_TYPE_NO_COLLISION;
}
} else if (ob->gameflag & OB_SENSOR) {
tip = "Collision Sensor, detects static and dynamic objects but not the other collision sensor objects";
ob->body_type = OB_BODY_TYPE_SENSOR;
} else if (!(ob->gameflag & OB_DYNAMIC)) {
tip = "Static";
ob->body_type = OB_BODY_TYPE_STATIC; ob->body_type = OB_BODY_TYPE_STATIC;
else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY))) } else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY))) {
tip = "Dynamic";
ob->body_type = OB_BODY_TYPE_DYNAMIC; ob->body_type = OB_BODY_TYPE_DYNAMIC;
else if (ob->gameflag & OB_RIGID_BODY) } else if (ob->gameflag & OB_RIGID_BODY) {
tip = "Rigid body";
ob->body_type = OB_BODY_TYPE_RIGID; ob->body_type = OB_BODY_TYPE_RIGID;
else { } else {
tip = "Soft body";
ob->body_type = OB_BODY_TYPE_SOFT; ob->body_type = OB_BODY_TYPE_SOFT;
/* create the structure here because we display soft body buttons in the main panel */ /* create the structure here because we display soft body buttons in the main panel */
if (!ob->bsoft) if (!ob->bsoft)
@ -3292,28 +3310,36 @@ static void buttons_bullet(uiBlock *block, Object *ob)
//only enable game soft body if Blender Soft Body exists //only enable game soft body if Blender Soft Body exists
but = uiDefButS(block, MENU, REDRAWVIEW3D, but = uiDefButS(block, MENU, REDRAWVIEW3D,
"Object type%t|Occluder%x5|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4", "Object type%t|Occluder%x5|No collision%x0|Sensor%x6|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4",
10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation"); 10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, tip);
uiButSetFunc(but, check_body_type, but, ob); uiButSetFunc(but, check_body_type, but, ob);
if (ob->gameflag & OB_COLLISION) { if (ob->gameflag & OB_COLLISION) {
uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor", if (ob->gameflag & OB_SENSOR) {
110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0, uiBlockEndAlign(block);
"Objects that are detected by the Near and Radar sensor"); uiDefBlockBut(block, advanced_bullet_menu, ob,
"Advanced Settings",
210, 205, 140, 19, "Display collision advanced settings");
uiBlockBeginAlign(block);
} else {
uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor",
110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0,
"Objects that are detected by the Near and Radar sensor and the collision sensor objects");
uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost",
160,205,50,19, 160,205,50,19,
&ob->gameflag, 0, 0, 0, 0, &ob->gameflag, 0, 0, 0, 0,
"Objects that don't restitute collisions (like a ghost)"); "Objects that don't restitute collisions (like a ghost)");
//uiBlockSetCol(block, TH_BUT_SETTING1); //uiBlockSetCol(block, TH_BUT_SETTING1);
uiDefBlockBut(block, advanced_bullet_menu, ob, uiDefBlockBut(block, advanced_bullet_menu, ob,
"Advanced Settings", "Advanced Settings",
210, 205, 140, 19, "Display collision advanced settings"); 210, 205, 140, 19, "Display collision advanced settings");
//uiBlockSetCol(block, TH_BUT_SETTING2); //uiBlockSetCol(block, TH_BUT_SETTING2);
}
if(ob->gameflag & OB_DYNAMIC) { if(ob->gameflag & OB_DYNAMIC) {
@ -3394,7 +3420,7 @@ static void buttons_bullet(uiBlock *block, Object *ob)
/* In Bullet, anisotripic friction can be applied to static objects as well, just not soft bodies */ /* In Bullet, anisotripic friction can be applied to static objects as well, just not soft bodies */
if (!(ob->gameflag & OB_SOFT_BODY)) if (!(ob->gameflag & (OB_SOFT_BODY|OB_SENSOR)))
{ {
uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic",
230, 145, 120, 19, 230, 145, 120, 19,

@ -1413,6 +1413,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0; objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0; objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0; objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
objprop.m_sensor = (blenderobject->gameflag & OB_SENSOR) != 0;
if (objprop.m_softbody) if (objprop.m_softbody)
{ {

@ -91,6 +91,15 @@ protected:
std::vector<class SCA_IController*> m_linkedcontrollers; std::vector<class SCA_IController*> m_linkedcontrollers;
public: public:
enum sensortype {
NONE = 0,
TOUCH,
NEAR,
RADAR,
// to be updated as needed
};
SCA_ISensor(SCA_IObject* gameobj, SCA_ISensor(SCA_IObject* gameobj,
class SCA_EventManager* eventmgr, class SCA_EventManager* eventmgr,
PyTypeObject* T );; PyTypeObject* T );;
@ -138,6 +147,8 @@ public:
virtual double GetNumber(); virtual double GetNumber();
virtual sensortype GetSensorType() { return NONE; }
/** Stop sensing for a while. */ /** Stop sensing for a while. */
void Suspend(); void Suspend();

@ -17,8 +17,8 @@
#include "BulletSoftBody/btSoftBody.h" #include "BulletSoftBody/btSoftBody.h"
KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound) KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool sensor, bool compound)
: KX_IPhysicsController(dyna,compound,(PHY_IPhysicsController*)this), : KX_IPhysicsController(dyna,sensor,compound,(PHY_IPhysicsController*)this),
CcdPhysicsController(ci), CcdPhysicsController(ci),
m_savedCollisionFlags(0), m_savedCollisionFlags(0),
m_savedCollisionFilterGroup(0), m_savedCollisionFilterGroup(0),
@ -174,6 +174,20 @@ void KX_BulletPhysicsController::setScaling(const MT_Vector3& scaling)
{ {
CcdPhysicsController::setScaling(scaling.x(),scaling.y(),scaling.z()); CcdPhysicsController::setScaling(scaling.x(),scaling.y(),scaling.z());
} }
void KX_BulletPhysicsController::SetTransform()
{
btVector3 pos;
btVector3 scale;
float ori[12];
m_MotionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
m_MotionState->getWorldScaling(scale.m_floats[0],scale.m_floats[1],scale.m_floats[2]);
m_MotionState->getWorldOrientation(ori);
btMatrix3x3 rot(ori[0], ori[4], ori[8],
ori[1], ori[5], ori[9],
ori[2], ori[6], ori[10]);
CcdPhysicsController::forceWorldTransform(rot, pos);
}
MT_Scalar KX_BulletPhysicsController::GetMass() MT_Scalar KX_BulletPhysicsController::GetMass()
{ {
if (GetSoftBody()) if (GetSoftBody())
@ -262,7 +276,7 @@ void KX_BulletPhysicsController::AddCompoundChild(KX_IPhysicsController* chil
// add to parent compound shapeinfo // add to parent compound shapeinfo
GetShapeInfo()->AddShape(proxyShapeInfo); GetShapeInfo()->AddShape(proxyShapeInfo);
// create new bullet collision shape from the object shapeinfo and set scaling // create new bullet collision shape from the object shapeinfo and set scaling
btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(); btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin());
newChildShape->setLocalScaling(relativeScale); newChildShape->setLocalScaling(relativeScale);
// add bullet collision shape to parent compound collision shape // add bullet collision shape to parent compound collision shape
compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape); compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape);
@ -359,7 +373,7 @@ void KX_BulletPhysicsController::SetMass(MT_Scalar newmass)
void KX_BulletPhysicsController::SuspendDynamics(bool ghost) void KX_BulletPhysicsController::SuspendDynamics(bool ghost)
{ {
btRigidBody *body = GetRigidBody(); btRigidBody *body = GetRigidBody();
if (body && !m_suspended) if (body && !m_suspended && !IsSensor())
{ {
btBroadphaseProxy* handle = body->getBroadphaseHandle(); btBroadphaseProxy* handle = body->getBroadphaseHandle();
m_savedCollisionFlags = body->getCollisionFlags(); m_savedCollisionFlags = body->getCollisionFlags();
@ -445,7 +459,7 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
void KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly) void KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
{ {
if (!m_bDyna) if (!m_bDyna && !m_bSensor)
{ {
btCollisionObject* object = GetRigidBody(); btCollisionObject* object = GetRigidBody();
object->setActivationState(ACTIVE_TAG); object->setActivationState(ACTIVE_TAG);

@ -19,7 +19,7 @@ private:
public: public:
KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound); KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool sensor, bool compound);
virtual ~KX_BulletPhysicsController (); virtual ~KX_BulletPhysicsController ();
/////////////////////////////////// ///////////////////////////////////
@ -42,6 +42,7 @@ public:
virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setOrientation(const MT_Matrix3x3& orn);
virtual void setPosition(const MT_Point3& pos); virtual void setPosition(const MT_Point3& pos);
virtual void setScaling(const MT_Vector3& scaling); virtual void setScaling(const MT_Vector3& scaling);
virtual void SetTransform();
virtual MT_Scalar GetMass(); virtual MT_Scalar GetMass();
virtual void SetMass(MT_Scalar newmass); virtual void SetMass(MT_Scalar newmass);
virtual MT_Vector3 GetLocalInertia(); virtual MT_Vector3 GetLocalInertia();

@ -50,8 +50,8 @@ struct KX_ClientObjectInfo
STATIC, STATIC,
ACTOR, ACTOR,
RESERVED1, RESERVED1,
RADAR, SENSOR,
NEAR OBSENSOR
} m_type; } m_type;
KX_GameObject* m_gameobject; KX_GameObject* m_gameobject;
void* m_auxilary_info; void* m_auxilary_info;
@ -84,6 +84,7 @@ public:
} }
bool isActor() { return m_type <= ACTOR; } bool isActor() { return m_type <= ACTOR; }
bool isSensor() { return m_type >= SENSOR && m_type <= OBSENSOR; }
}; };
#endif //__KX_CLIENTOBJECT_INFO_H #endif //__KX_CLIENTOBJECT_INFO_H

@ -83,6 +83,7 @@ struct KX_ObjectProperties
bool m_ghost; bool m_ghost;
class KX_GameObject* m_dynamic_parent; class KX_GameObject* m_dynamic_parent;
bool m_isactor; bool m_isactor;
bool m_sensor;
bool m_concave; bool m_concave;
bool m_isdeformable; bool m_isdeformable;
bool m_disableSleeping; bool m_disableSleeping;

@ -808,12 +808,12 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
bool isbulletdyna = false; bool isbulletdyna = false;
bool isbulletsensor = false;
CcdConstructionInfo ci; CcdConstructionInfo ci;
class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode()); class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo(); class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
if (!objprop->m_dyna) if (!objprop->m_dyna)
{ {
ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT; ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
@ -832,6 +832,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_margin = objprop->m_margin; ci.m_margin = objprop->m_margin;
shapeInfo->m_radius = objprop->m_radius; shapeInfo->m_radius = objprop->m_radius;
isbulletdyna = objprop->m_dyna; isbulletdyna = objprop->m_dyna;
isbulletsensor = objprop->m_sensor;
ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f); ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
@ -851,7 +852,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
//bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1); //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
shapeInfo->m_shapeType = PHY_SHAPE_SPHERE; shapeInfo->m_shapeType = PHY_SHAPE_SPHERE;
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
break; break;
}; };
case KX_BOUNDBOX: case KX_BOUNDBOX:
@ -864,7 +865,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
shapeInfo->m_halfExtend /= 2.0; shapeInfo->m_halfExtend /= 2.0;
shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute(); shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute();
shapeInfo->m_shapeType = PHY_SHAPE_BOX; shapeInfo->m_shapeType = PHY_SHAPE_BOX;
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
break; break;
}; };
case KX_BOUNDCYLINDER: case KX_BOUNDCYLINDER:
@ -875,7 +876,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
objprop->m_boundobject.c.m_height * 0.5f objprop->m_boundobject.c.m_height * 0.5f
); );
shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER; shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER;
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
break; break;
} }
@ -884,18 +885,18 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
shapeInfo->m_radius = objprop->m_boundobject.c.m_radius; shapeInfo->m_radius = objprop->m_boundobject.c.m_radius;
shapeInfo->m_height = objprop->m_boundobject.c.m_height; shapeInfo->m_height = objprop->m_boundobject.c.m_height;
shapeInfo->m_shapeType = PHY_SHAPE_CONE; shapeInfo->m_shapeType = PHY_SHAPE_CONE;
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
break; break;
} }
case KX_BOUNDPOLYTOPE: case KX_BOUNDPOLYTOPE:
{ {
shapeInfo->SetMesh(meshobj, dm,true,false); shapeInfo->SetMesh(meshobj, dm,true,false);
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
break; break;
} }
case KX_BOUNDMESH: case KX_BOUNDMESH:
{ {
bool useGimpact = (ci.m_mass && !objprop->m_softbody); bool useGimpact = ((ci.m_mass || isbulletsensor) && !objprop->m_softbody);
// mesh shapes can be shared, check first if we already have a shape on that mesh // mesh shapes can be shared, check first if we already have a shape on that mesh
class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false,useGimpact); class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false,useGimpact);
@ -915,7 +916,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
} }
bm = shapeInfo->CreateBulletShape(); bm = shapeInfo->CreateBulletShape(ci.m_margin);
//should we compute inertia for dynamic shape? //should we compute inertia for dynamic shape?
//bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
@ -933,7 +934,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
return; return;
} }
bm->setMargin(ci.m_margin); //bm->setMargin(ci.m_margin);
if (objprop->m_isCompoundChild) if (objprop->m_isCompoundChild)
@ -1103,26 +1104,39 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_soft_numclusteriterations= objprop->m_soft_numclusteriterations; /* number of iterations to refine collision clusters*/ ci.m_soft_numclusteriterations= objprop->m_soft_numclusteriterations; /* number of iterations to refine collision clusters*/
//////////////////// ////////////////////
ci.m_collisionFilterGroup =
ci.m_collisionFilterGroup = (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : short(CcdConstructionInfo::StaticFilter); (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) :
ci.m_collisionFilterMask = (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter); (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) :
short(CcdConstructionInfo::StaticFilter);
ci.m_collisionFilterMask =
(isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) :
(isbulletdyna) ? short(CcdConstructionInfo::AllFilter) :
short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody; ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody;
ci.m_bSoft = objprop->m_softbody; ci.m_bSoft = objprop->m_softbody;
ci.m_bSensor = isbulletsensor;
MT_Vector3 scaling = gameobj->NodeGetWorldScaling(); MT_Vector3 scaling = gameobj->NodeGetWorldScaling();
ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]); ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]);
KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,objprop->m_hasCompoundChildren); KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,isbulletsensor,objprop->m_hasCompoundChildren);
// shapeInfo is reference counted, decrement now as we don't use it anymore // shapeInfo is reference counted, decrement now as we don't use it anymore
if (shapeInfo) if (shapeInfo)
shapeInfo->Release(); shapeInfo->Release();
if (objprop->m_in_active_layer) gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
if (isbulletsensor)
{
// use a different callback function for sensor object,
// bullet will not synchronize, we must do it explicitely
SG_Callbacks& callbacks = gameobj->GetSGNode()->GetCallBackFunctions();
callbacks.m_updatefunc = KX_GameObject::SynchronizeTransformFunc;
// make sensor object invisible by default
gameobj->SetVisible(false, false);
}
// don't add automatically sensor object, they are added when a collision sensor is registered
else if (objprop->m_in_active_layer)
{ {
env->addCcdPhysicsController( physicscontroller); env->addCcdPhysicsController( physicscontroller);
} }
gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
physicscontroller->setNewClientInfo(gameobj->getClientInfo()); physicscontroller->setNewClientInfo(gameobj->getClientInfo());
{ {
btRigidBody* rbody = physicscontroller->GetRigidBody(); btRigidBody* rbody = physicscontroller->GetRigidBody();
@ -1181,7 +1195,9 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
} }
bool isActor = objprop->m_isactor; bool isActor = objprop->m_isactor;
gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC); gameobj->getClientInfo()->m_type =
(isbulletsensor) ? KX_ClientObjectInfo::OBSENSOR :
(isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
// store materialname in auxinfo, needed for touchsensors // store materialname in auxinfo, needed for touchsensors
if (meshobj) if (meshobj)
{ {

@ -332,7 +332,7 @@ void KX_GameObject::ProcessReplica()
} }
static void setGraphicController_recursive(SG_Node* node, bool v) static void setGraphicController_recursive(SG_Node* node)
{ {
NodeList& children = node->GetSGChildren(); NodeList& children = node->GetSGChildren();
@ -341,24 +341,24 @@ static void setGraphicController_recursive(SG_Node* node, bool v)
SG_Node* childnode = (*childit); SG_Node* childnode = (*childit);
KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject()); KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
if (clientgameobj != NULL) // This is a GameObject if (clientgameobj != NULL) // This is a GameObject
clientgameobj->ActivateGraphicController(v, false); clientgameobj->ActivateGraphicController(false);
// if the childobj is NULL then this may be an inverse parent link // if the childobj is NULL then this may be an inverse parent link
// so a non recursive search should still look down this node. // so a non recursive search should still look down this node.
setGraphicController_recursive(childnode, v); setGraphicController_recursive(childnode);
} }
} }
void KX_GameObject::ActivateGraphicController(bool active, bool recurse) void KX_GameObject::ActivateGraphicController(bool recurse)
{ {
if (m_pGraphicController) if (m_pGraphicController)
{ {
m_pGraphicController->Activate(active); m_pGraphicController->Activate(m_bVisible);
} }
if (recurse) if (recurse)
{ {
setGraphicController_recursive(GetSGNode(), active); setGraphicController_recursive(GetSGNode());
} }
} }
@ -538,6 +538,20 @@ void KX_GameObject::UpdateTransformFunc(SG_IObject* node, void* gameobj, void* s
((KX_GameObject*)gameobj)->UpdateTransform(); ((KX_GameObject*)gameobj)->UpdateTransform();
} }
void KX_GameObject::SynchronizeTransform()
{
// only used for sensor object, do full synchronization as bullet doesn't do it
if (m_pPhysicsController1)
m_pPhysicsController1->SetTransform();
if (m_pGraphicController)
m_pGraphicController->SetGraphicTransform();
}
void KX_GameObject::SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene)
{
((KX_GameObject*)gameobj)->SynchronizeTransform();
}
void KX_GameObject::SetDebugColor(unsigned int bgra) void KX_GameObject::SetDebugColor(unsigned int bgra)
{ {

@ -384,7 +384,7 @@ public:
/* /*
* @add/remove the graphic controller to the physic system * @add/remove the graphic controller to the physic system
*/ */
void ActivateGraphicController(bool active, bool recurse); void ActivateGraphicController(bool recurse);
/** /**
* @section Coordinate system manipulation functions * @section Coordinate system manipulation functions
@ -559,6 +559,13 @@ public:
static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene); static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
/**
* only used for sensor objects
*/
void SynchronizeTransform();
static void SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene);
/** /**
* Function to set IPO option at start of IPO * Function to set IPO option at start of IPO
*/ */

@ -35,9 +35,10 @@
#include "PHY_DynamicTypes.h" #include "PHY_DynamicTypes.h"
KX_IPhysicsController::KX_IPhysicsController(bool dyna, bool compound, void* userdata) KX_IPhysicsController::KX_IPhysicsController(bool dyna, bool sensor, bool compound, void* userdata)
: m_bDyna(dyna), : m_bDyna(dyna),
m_bSensor(sensor),
m_bCompound(compound), m_bCompound(compound),
m_suspendDynamics(false), m_suspendDynamics(false),
m_userdata(userdata) m_userdata(userdata)

@ -49,11 +49,12 @@ class KX_IPhysicsController : public SG_Controller
{ {
protected: protected:
bool m_bDyna; bool m_bDyna;
bool m_bSensor;
bool m_bCompound; bool m_bCompound;
bool m_suspendDynamics; bool m_suspendDynamics;
void* m_userdata; void* m_userdata;
public: public:
KX_IPhysicsController(bool dyna,bool compound, void* userdata); KX_IPhysicsController(bool dyna,bool sensor,bool compound, void* userdata);
virtual ~KX_IPhysicsController(); virtual ~KX_IPhysicsController();
@ -74,6 +75,7 @@ public:
virtual void getOrientation(MT_Quaternion& orn)=0; virtual void getOrientation(MT_Quaternion& orn)=0;
virtual void setOrientation(const MT_Matrix3x3& orn)=0; virtual void setOrientation(const MT_Matrix3x3& orn)=0;
virtual void SetTransform()=0;
//virtual void setOrientation(const MT_Quaternion& orn)=0; //virtual void setOrientation(const MT_Quaternion& orn)=0;
virtual void setPosition(const MT_Point3& pos)=0; virtual void setPosition(const MT_Point3& pos)=0;
virtual void setScaling(const MT_Vector3& scaling)=0; virtual void setScaling(const MT_Vector3& scaling)=0;
@ -100,10 +102,18 @@ public:
m_bDyna = isDynamic; m_bDyna = isDynamic;
} }
void SetSensor(bool isSensor) {
m_bSensor = isSensor;
}
bool IsDyna(void) { bool IsDyna(void) {
return m_bDyna; return m_bDyna;
} }
bool IsSensor(void) {
return m_bSensor;
}
bool IsCompound(void) { bool IsCompound(void) {
return m_bCompound; return m_bCompound;
} }

@ -73,6 +73,11 @@ void KX_MotionState::getWorldOrientation(float* ori)
mat.getValue(ori); mat.getValue(ori);
} }
void KX_MotionState::setWorldOrientation(const float* ori)
{
m_node->SetLocalOrientation(ori);
}
void KX_MotionState::setWorldPosition(float posX,float posY,float posZ) void KX_MotionState::setWorldPosition(float posX,float posY,float posZ)
{ {
m_node->SetLocalPosition(MT_Point3(posX,posY,posZ)); m_node->SetLocalPosition(MT_Point3(posX,posY,posZ));

@ -45,6 +45,7 @@ public:
virtual void setWorldPosition(float posX,float posY,float posZ); virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal); virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void getWorldOrientation(float* ori); virtual void getWorldOrientation(float* ori);
virtual void setWorldOrientation(const float* ori);
virtual void calculateWorldTransformations(); virtual void calculateWorldTransformations();
}; };

@ -36,6 +36,7 @@
#include "KX_Scene.h" // needed to create a replica #include "KX_Scene.h" // needed to create a replica
#include "PHY_IPhysicsEnvironment.h" #include "PHY_IPhysicsEnvironment.h"
#include "PHY_IPhysicsController.h" #include "PHY_IPhysicsController.h"
#include "PHY_IMotionState.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
@ -62,7 +63,7 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
{ {
gameobj->getClientInfo()->m_sensors.remove(this); gameobj->getClientInfo()->m_sensors.remove(this);
m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR); m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::SENSOR);
m_client_info->m_sensors.push_back(this); m_client_info->m_sensors.push_back(this);
//DT_ShapeHandle shape = (DT_ShapeHandle) vshape; //DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
@ -81,28 +82,14 @@ void KX_NearSensor::SynchronizeTransform()
// not linked to the parent object, must synchronize it. // not linked to the parent object, must synchronize it.
if (m_physCtrl) if (m_physCtrl)
{ {
PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
KX_GameObject* parent = ((KX_GameObject*)GetParent()); KX_GameObject* parent = ((KX_GameObject*)GetParent());
MT_Vector3 pos = parent->NodeGetWorldPosition(); const MT_Point3& pos = parent->NodeGetWorldPosition();
MT_Quaternion orn = parent->NodeGetWorldOrientation().getRotation(); float ori[12];
m_physCtrl->setPosition(pos.x(),pos.y(),pos.z()); parent->NodeGetWorldOrientation().getValue(ori);
m_physCtrl->setOrientation(orn.x(),orn.y(),orn.z(),orn.w()); motionState->setWorldPosition(pos[0], pos[1], pos[2]);
m_physCtrl->calcXform(); motionState->setWorldOrientation(ori);
} m_physCtrl->WriteMotionStateToDynamics(true);
}
void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman)
{
if (m_physCtrl)
{
touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
}
}
void KX_NearSensor::UnregisterSumo(KX_TouchEventManager* touchman)
{
if (m_physCtrl)
{
touchman->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
} }
} }
@ -117,7 +104,7 @@ void KX_NearSensor::ProcessReplica()
{ {
KX_TouchSensor::ProcessReplica(); KX_TouchSensor::ProcessReplica();
m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR); m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::SENSOR);
if (m_physCtrl) if (m_physCtrl)
{ {
@ -134,11 +121,11 @@ void KX_NearSensor::ProcessReplica()
void KX_NearSensor::ReParent(SCA_IObject* parent) void KX_NearSensor::ReParent(SCA_IObject* parent)
{ {
SCA_ISensor::ReParent(parent);
m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent); m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent);
m_client_info->m_sensors.push_back(this); m_client_info->m_sensors.push_back(this);
//Synchronize here with the actual parent. //Synchronize here with the actual parent.
SynchronizeTransform(); SynchronizeTransform();
SCA_ISensor::ReParent(parent);
} }

@ -77,8 +77,8 @@ public:
virtual bool NewHandleCollision(void* obj1,void* obj2, virtual bool NewHandleCollision(void* obj1,void* obj2,
const PHY_CollData * coll_data); const PHY_CollData * coll_data);
virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2); virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2);
virtual void RegisterSumo(KX_TouchEventManager *touchman); virtual bool BroadPhaseSensorFilterCollision(void*obj1,void*obj2) { return false; };
virtual void UnregisterSumo(KX_TouchEventManager* touchman); virtual sensortype GetSensorType() { return NEAR; }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */

@ -70,6 +70,7 @@ public:
virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setOrientation(const MT_Matrix3x3& orn);
virtual void setPosition(const MT_Point3& pos); virtual void setPosition(const MT_Point3& pos);
virtual void setScaling(const MT_Vector3& scaling); virtual void setScaling(const MT_Vector3& scaling);
virtual void SetTransform() {}
virtual MT_Scalar GetMass(); virtual MT_Scalar GetMass();
virtual MT_Vector3 getReactionForce(); virtual MT_Vector3 getReactionForce();
virtual void setRigidBody(bool rigid); virtual void setRigidBody(bool rigid);

@ -30,6 +30,7 @@
#include "KX_GameObject.h" #include "KX_GameObject.h"
#include "KX_PyMath.h" #include "KX_PyMath.h"
#include "PHY_IPhysicsController.h" #include "PHY_IPhysicsController.h"
#include "PHY_IMotionState.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
@ -66,7 +67,7 @@ KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr,
m_coneheight(coneheight), m_coneheight(coneheight),
m_axis(axis) m_axis(axis)
{ {
m_client_info->m_type = KX_ClientObjectInfo::RADAR; m_client_info->m_type = KX_ClientObjectInfo::SENSOR;
//m_client_info->m_clientobject = gameobj; //m_client_info->m_clientobject = gameobj;
//m_client_info->m_auxilary_info = NULL; //m_client_info->m_auxilary_info = NULL;
//sumoObj->setClientObject(&m_client_info); //sumoObj->setClientObject(&m_client_info);
@ -84,12 +85,6 @@ CValue* KX_RadarSensor::GetReplica()
return replica; return replica;
} }
void KX_RadarSensor::ProcessReplica()
{
KX_NearSensor::ProcessReplica();
m_client_info->m_type = KX_ClientObjectInfo::RADAR;
}
/** /**
* Transforms the collision object. A cone is not correctly centered * Transforms the collision object. A cone is not correctly centered
* for usage. */ * for usage. */
@ -169,11 +164,13 @@ void KX_RadarSensor::SynchronizeTransform()
if (m_physCtrl) if (m_physCtrl)
{ {
MT_Quaternion orn = trans.getRotation(); PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
MT_Point3 pos = trans.getOrigin(); const MT_Point3& pos = trans.getOrigin();
m_physCtrl->setPosition(pos[0],pos[1],pos[2]); float ori[12];
m_physCtrl->setOrientation(orn[0],orn[1],orn[2],orn[3]); trans.getBasis().getValue(ori);
m_physCtrl->calcXform(); motionState->setWorldPosition(pos[0], pos[1], pos[2]);
motionState->setWorldOrientation(ori);
m_physCtrl->WriteMotionStateToDynamics(true);
} }
} }

@ -76,7 +76,6 @@ public:
virtual ~KX_RadarSensor(); virtual ~KX_RadarSensor();
virtual void SynchronizeTransform(); virtual void SynchronizeTransform();
virtual CValue* GetReplica(); virtual CValue* GetReplica();
virtual void ProcessReplica();
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
@ -93,6 +92,7 @@ public:
virtual PyObject* py_getattro(PyObject *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual PyObject* py_getattro_dict(); virtual PyObject* py_getattro_dict();
virtual int py_setattro(PyObject *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
virtual sensortype GetSensorType() { return RADAR; }
//Deprecated -----> //Deprecated ----->
KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin);

@ -737,7 +737,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox()); replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox());
replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius()); replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius());
// we can now add the graphic controller to the physic engine // we can now add the graphic controller to the physic engine
replica->ActivateGraphicController(true,true); replica->ActivateGraphicController(true);
// done with replica // done with replica
replica->Release(); replica->Release();
@ -850,7 +850,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox()); replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius()); replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
// the size is correct, we can add the graphic controller to the physic engine // the size is correct, we can add the graphic controller to the physic engine
replica->ActivateGraphicController(true,true); replica->ActivateGraphicController(true);
// now replicate logic // now replicate logic
vector<KX_GameObject*>::iterator git; vector<KX_GameObject*>::iterator git;

@ -53,7 +53,7 @@ public:
class SM_Object* sumoObj, class SM_Object* sumoObj,
class PHY_IMotionState* motionstate class PHY_IMotionState* motionstate
,bool dyna) ,bool dyna)
: KX_IPhysicsController(dyna,false,NULL) , : KX_IPhysicsController(dyna,false,false,NULL) ,
SumoPhysicsController(sumoScene,/*solidscene,*/sumoObj,motionstate,dyna) SumoPhysicsController(sumoScene,/*solidscene,*/sumoObj,motionstate,dyna)
{ {
}; };
@ -83,6 +83,7 @@ public:
virtual void getOrientation(MT_Quaternion& orn); virtual void getOrientation(MT_Quaternion& orn);
virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setOrientation(const MT_Matrix3x3& orn);
virtual void SetTransform() {}
virtual void setPosition(const MT_Point3& pos); virtual void setPosition(const MT_Point3& pos);
virtual void setScaling(const MT_Vector3& scaling); virtual void setScaling(const MT_Vector3& scaling);

@ -85,14 +85,34 @@ bool KX_TouchEventManager::newBroadphaseResponse(void *client_data,
PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1); PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1);
KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL; KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL;
// This call back should only be called for controllers of Near and Radar sensor // This call back should only be called for controllers of Near and Radar sensor
if (info && if (!info)
info->m_sensors.size() == 1 && return true;
(info->m_type == KX_ClientObjectInfo::NEAR ||
info->m_type == KX_ClientObjectInfo::RADAR)) switch (info->m_type)
{ {
// only one sensor for this type of object case KX_ClientObjectInfo::SENSOR:
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin()); if (info->m_sensors.size() == 1)
return touchsensor->BroadPhaseFilterCollision(object1,object2); {
// only one sensor for this type of object
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
return touchsensor->BroadPhaseFilterCollision(object1,object2);
}
break;
case KX_ClientObjectInfo::OBSENSOR:
// this object may have multiple collision sensors,
// check is any of them is interested in this object
for(std::list<SCA_ISensor*>::iterator it = info->m_sensors.begin();
it != info->m_sensors.end();
++it)
{
if ((*it)->GetSensorType() == SCA_ISensor::TOUCH)
{
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*it);
if (touchsensor->BroadPhaseSensorFilterCollision(object1, object2))
return true;
}
}
return false;
} }
return true; return true;
} }

@ -173,21 +173,67 @@ void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman)
{ {
if (m_physCtrl) if (m_physCtrl)
{ {
touchman->GetPhysicsEnvironment()->requestCollisionCallback(m_physCtrl); if (touchman->GetPhysicsEnvironment()->requestCollisionCallback(m_physCtrl))
// collision {
// Deprecated KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->getNewClientInfo());
if (client_info->isSensor())
touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
}
} }
} }
void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman) void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman)
{ {
if (m_physCtrl) if (m_physCtrl)
{ {
touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl); if (touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl))
{
// no more sensor on the controller, can remove it if it is a sensor object
KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->getNewClientInfo());
if (client_info->isSensor())
touchman->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
}
} }
} }
// this function is called only for sensor objects
// return true if the controller can collide with the object
bool KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2)
{
assert(obj1==m_physCtrl && obj2);
KX_GameObject* myobj = (KX_GameObject*)GetParent();
KX_GameObject* myparent = myobj->GetParent();
KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(((PHY_IPhysicsController*)obj2)->getNewClientInfo());
KX_GameObject* otherobj = ( client_info ? client_info->m_gameobject : NULL);
// first, decrement refcount as GetParent() increases it
if (myparent)
myparent->Release();
// we can only check on persistent characteristic: m_link and m_suspended are not
// good candidate because they are transient. That must be handled at another level
if (!otherobj ||
otherobj == myparent || // don't interact with our parent
client_info->m_type != KX_ClientObjectInfo::ACTOR) // only with actor objects
return false;
bool found = m_touchedpropname.IsEmpty();
if (!found)
{
if (m_bFindMaterial)
{
if (client_info->m_auxilary_info)
{
found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info));
}
} else
{
found = (otherobj->GetProperty(m_touchedpropname) != NULL);
}
}
return found;
}
bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata) bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata)
{ {
// KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; // KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr;

@ -103,7 +103,8 @@ public:
// obj1 = sensor physical controller, obj2 = physical controller of second object // obj1 = sensor physical controller, obj2 = physical controller of second object
// return value = true if collision should be checked on pair of object // return value = true if collision should be checked on pair of object
virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; } virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
virtual bool BroadPhaseSensorFilterCollision(void*obj1,void*obj2);
virtual sensortype GetSensorType() { return TOUCH; }
virtual bool IsPositiveTrigger() { virtual bool IsPositiveTrigger() {

@ -379,7 +379,10 @@ bool ODEPhysicsController::SynchronizeMotionStates(float time)
return false; //it update the worldpos return false; //it update the worldpos
} }
PHY_IMotionState* ODEPhysicsController::GetMotionState()
{
return m_MotionState;
}
// kinematic methods // kinematic methods

@ -102,6 +102,7 @@ public:
virtual void WriteDynamicsToMotionState() {}; virtual void WriteDynamicsToMotionState() {};
virtual void WriteMotionStateToDynamics(bool nondynaonly); virtual void WriteMotionStateToDynamics(bool nondynaonly);
virtual class PHY_IMotionState* GetMotionState();
/** /**
call from Scene Graph Node to 'update'. call from Scene Graph Node to 'update'.

@ -64,8 +64,8 @@ public:
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user) virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
{ {
} }
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl) {return false;}
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl) {return false;}
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;} virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;} virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}

@ -92,16 +92,19 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
} }
btTransform CcdPhysicsController::GetTransformFromMotionState(PHY_IMotionState* motionState) btTransform& CcdPhysicsController::GetTransformFromMotionState(PHY_IMotionState* motionState)
{ {
btTransform trans; static btTransform trans;
float tmp[3]; btVector3 tmp;
motionState->getWorldPosition(tmp[0],tmp[1],tmp[2]); motionState->getWorldPosition(tmp.m_floats[0], tmp.m_floats[1], tmp.m_floats[2]);
trans.setOrigin(btVector3(tmp[0],tmp[1],tmp[2])); trans.setOrigin(tmp);
btQuaternion orn; float ori[12];
motionState->getWorldOrientation(orn[0],orn[1],orn[2],orn[3]); motionState->getWorldOrientation(ori);
trans.setRotation(orn); trans.getBasis().setFromOpenGLSubMatrix(ori);
//btQuaternion orn;
//motionState->getWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
//trans.setRotation(orn);
return trans; return trans;
} }
@ -118,18 +121,18 @@ public:
} }
virtual void getWorldTransform(btTransform& worldTrans ) const void getWorldTransform(btTransform& worldTrans ) const
{ {
float pos[3]; btVector3 pos;
float quatOrn[4]; float ori[12];
m_blenderMotionState->getWorldPosition(pos[0],pos[1],pos[2]); m_blenderMotionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
m_blenderMotionState->getWorldOrientation(quatOrn[0],quatOrn[1],quatOrn[2],quatOrn[3]); m_blenderMotionState->getWorldOrientation(ori);
worldTrans.setOrigin(btVector3(pos[0],pos[1],pos[2])); worldTrans.setOrigin(pos);
worldTrans.setBasis(btMatrix3x3(btQuaternion(quatOrn[0],quatOrn[1],quatOrn[2],quatOrn[3]))); worldTrans.getBasis().setFromOpenGLSubMatrix(ori);
} }
virtual void setWorldTransform(const btTransform& worldTrans) void setWorldTransform(const btTransform& worldTrans)
{ {
m_blenderMotionState->setWorldPosition(worldTrans.getOrigin().getX(),worldTrans.getOrigin().getY(),worldTrans.getOrigin().getZ()); m_blenderMotionState->setWorldPosition(worldTrans.getOrigin().getX(),worldTrans.getOrigin().getY(),worldTrans.getOrigin().getZ());
btQuaternion rotQuat = worldTrans.getRotation(); btQuaternion rotQuat = worldTrans.getRotation();
@ -493,10 +496,12 @@ void CcdPhysicsController::CreateRigidbody()
//convert collision flags! //convert collision flags!
//special case: a near/radar sensor controller should not be defined static or it will //special case: a near/radar sensor controller should not be defined static or it will
//generate loads of static-static collision messages on the console //generate loads of static-static collision messages on the console
if ((m_cci.m_collisionFilterGroup & CcdConstructionInfo::SensorFilter) != 0) if (m_cci.m_bSensor)
{ {
// reset the flags that have been set so far // reset the flags that have been set so far
GetCollisionObject()->setCollisionFlags(0); GetCollisionObject()->setCollisionFlags(0);
// sensor must never go to sleep: they need to detect continously
GetCollisionObject()->setActivationState(DISABLE_DEACTIVATION);
} }
GetCollisionObject()->setCollisionFlags(m_object->getCollisionFlags() | m_cci.m_collisionFlags); GetCollisionObject()->setCollisionFlags(m_object->getCollisionFlags() | m_cci.m_collisionFlags);
btRigidBody* body = GetRigidBody(); btRigidBody* body = GetRigidBody();
@ -613,12 +618,13 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time)
body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len)); body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len));
} }
const btVector3& worldPos = body->getCenterOfMassPosition(); const btTransform& xform = body->getCenterOfMassTransform();
const btMatrix3x3& worldOri = xform.getBasis();
const btVector3& worldPos = xform.getOrigin();
float ori[12];
worldOri.getOpenGLSubMatrix(ori);
m_MotionState->setWorldOrientation(ori);
m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]); m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
const btQuaternion& worldquat = body->getOrientation();
m_MotionState->setWorldOrientation(worldquat[0],worldquat[1],worldquat[2],worldquat[3]);
m_MotionState->calculateWorldTransformations(); m_MotionState->calculateWorldTransformations();
float scale[3]; float scale[3];
@ -655,8 +661,10 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time)
void CcdPhysicsController::WriteMotionStateToDynamics(bool nondynaonly) void CcdPhysicsController::WriteMotionStateToDynamics(bool nondynaonly)
{ {
btTransform& xform = CcdPhysicsController::GetTransformFromMotionState(m_MotionState);
SetCenterOfMassTransform(xform);
} }
void CcdPhysicsController::WriteDynamicsToMotionState() void CcdPhysicsController::WriteDynamicsToMotionState()
{ {
} }
@ -673,12 +681,12 @@ void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
if (m_shapeInfo) if (m_shapeInfo)
{ {
m_shapeInfo->AddRef(); m_shapeInfo->AddRef();
m_collisionShape = m_shapeInfo->CreateBulletShape(); m_collisionShape = m_shapeInfo->CreateBulletShape(m_cci.m_margin);
if (m_collisionShape) if (m_collisionShape)
{ {
// new shape has no scaling, apply initial scaling // new shape has no scaling, apply initial scaling
m_collisionShape->setMargin(m_cci.m_margin); //m_collisionShape->setMargin(m_cci.m_margin);
m_collisionShape->setLocalScaling(m_cci.m_scaling); m_collisionShape->setLocalScaling(m_cci.m_scaling);
if (m_cci.m_mass) if (m_cci.m_mass)
@ -698,7 +706,9 @@ void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor); body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
} }
} }
m_cci.m_physicsEnv->addCcdPhysicsController(this); // sensor object are added when needed
if (!m_cci.m_bSensor)
m_cci.m_physicsEnv->addCcdPhysicsController(this);
/* SM_Object* dynaparent=0; /* SM_Object* dynaparent=0;
@ -773,7 +783,7 @@ void CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dloc
if (m_object) if (m_object)
{ {
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject() && !m_cci.m_bSensor)
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
} }
@ -799,7 +809,7 @@ void CcdPhysicsController::RelativeRotate(const float rotval[9],bool local)
if (m_object) if (m_object)
{ {
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject() && !m_cci.m_bSensor)
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
} }
@ -843,7 +853,7 @@ void CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float
if (m_object) if (m_object)
{ {
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject() && !m_cci.m_bSensor)
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
} }
@ -866,7 +876,7 @@ void CcdPhysicsController::setWorldOrientation(const btMatrix3x3& orn)
if (m_object) if (m_object)
{ {
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject() && !m_cci.m_bSensor)
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
} }
@ -895,7 +905,7 @@ void CcdPhysicsController::setPosition(float posX,float posY,float posZ)
if (m_object) if (m_object)
{ {
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject() && !m_cci.m_bSensor)
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
} }
@ -909,9 +919,19 @@ void CcdPhysicsController::setPosition(float posX,float posY,float posZ)
// not required // not required
//m_bulletMotionState->setWorldTransform(xform); //m_bulletMotionState->setWorldTransform(xform);
} }
} }
void CcdPhysicsController::forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos)
{
if (m_object)
{
btTransform& xform = m_object->getWorldTransform();
xform.setBasis(mat);
xform.setOrigin(pos);
}
}
void CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) void CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
{ {
} }
@ -961,7 +981,9 @@ void CcdPhysicsController::ApplyTorque(float torqueX,float torqueY,float torque
m_object->activate(); m_object->activate();
if (m_object->isStaticObject()) if (m_object->isStaticObject())
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); if (!m_cci.m_bSensor)
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
return;
} }
if (local) if (local)
{ {
@ -989,27 +1011,26 @@ void CcdPhysicsController::ApplyForce(float forceX,float forceY,float forceZ,bo
m_object->activate(); m_object->activate();
if (m_object->isStaticObject()) if (m_object->isStaticObject())
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); if (!m_cci.m_bSensor)
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
return;
} }
btTransform xform = m_object->getWorldTransform();
if (local)
{ {
btTransform xform = m_object->getWorldTransform(); force = xform.getBasis()*force;
}
if (local) btRigidBody* body = GetRigidBody();
{ if (body)
force = xform.getBasis()*force; body->applyCentralForce(force);
} btSoftBody* soft = GetSoftBody();
btRigidBody* body = GetRigidBody(); if (soft)
if (body) {
body->applyCentralForce(force); // the force is applied on each node, must reduce it in the same extend
btSoftBody* soft = GetSoftBody(); if (soft->m_nodes.size() > 0)
if (soft) force /= soft->m_nodes.size();
{ soft->addForce(force);
// the force is applied on each node, must reduce it in the same extend
if (soft->m_nodes.size() > 0)
force /= soft->m_nodes.size();
soft->addForce(force);
}
} }
} }
} }
@ -1021,19 +1042,18 @@ void CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,flo
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject())
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); if (!m_cci.m_bSensor)
} else m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
{ return;
btTransform xform = m_object->getWorldTransform();
if (local)
{
angvel = xform.getBasis()*angvel;
}
btRigidBody* body = GetRigidBody();
if (body)
body->setAngularVelocity(angvel);
} }
btTransform xform = m_object->getWorldTransform();
if (local)
{
angvel = xform.getBasis()*angvel;
}
btRigidBody* body = GetRigidBody();
if (body)
body->setAngularVelocity(angvel);
} }
} }
@ -1046,7 +1066,8 @@ void CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
m_object->activate(true); m_object->activate(true);
if (m_object->isStaticObject()) if (m_object->isStaticObject())
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); if (!m_cci.m_bSensor)
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
return; return;
} }
@ -1080,7 +1101,9 @@ void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attac
m_object->activate(); m_object->activate();
if (m_object->isStaticObject()) if (m_object->isStaticObject())
{ {
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); if (!m_cci.m_bSensor)
m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
return;
} }
btVector3 pos(attachX,attachY,attachZ); btVector3 pos(attachX,attachY,attachZ);
@ -1207,7 +1230,7 @@ PHY_IPhysicsController* CcdPhysicsController::GetReplica()
if (m_shapeInfo) if (m_shapeInfo)
{ {
// This situation does not normally happen // This situation does not normally happen
cinfo.m_collisionShape = m_shapeInfo->CreateBulletShape(); cinfo.m_collisionShape = m_shapeInfo->CreateBulletShape(0.01);
} }
else if (m_collisionShape) else if (m_collisionShape)
{ {
@ -1274,28 +1297,22 @@ void DefaultMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scal
void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal) void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{ {
quatIma0 = m_worldTransform.getRotation().x(); btQuaternion quat = m_worldTransform.getRotation();
quatIma1 = m_worldTransform.getRotation().y(); quatIma0 = quat.x();
quatIma2 = m_worldTransform.getRotation().z(); quatIma1 = quat.y();
quatReal = m_worldTransform.getRotation()[3]; quatIma2 = quat.z();
quatReal = quat[3];
} }
void DefaultMotionState::getWorldOrientation(float* ori) void DefaultMotionState::getWorldOrientation(float* ori)
{ {
*ori++ = m_worldTransform.getBasis()[0].x(); m_worldTransform.getBasis().getOpenGLSubMatrix(ori);
*ori++ = m_worldTransform.getBasis()[1].x();
*ori++ = m_worldTransform.getBasis()[1].x();
*ori++ = 0.f;
*ori++ = m_worldTransform.getBasis()[0].y();
*ori++ = m_worldTransform.getBasis()[1].y();
*ori++ = m_worldTransform.getBasis()[1].y();
*ori++ = 0.f;
*ori++ = m_worldTransform.getBasis()[0].z();
*ori++ = m_worldTransform.getBasis()[1].z();
*ori++ = m_worldTransform.getBasis()[1].z();
*ori++ = 0.f;
} }
void DefaultMotionState::setWorldOrientation(const float* ori)
{
m_worldTransform.getBasis().setFromOpenGLSubMatrix(ori);
}
void DefaultMotionState::setWorldPosition(float posX,float posY,float posZ) void DefaultMotionState::setWorldPosition(float posX,float posY,float posZ)
{ {
btVector3 pos(posX,posY,posZ); btVector3 pos(posX,posY,posZ);
@ -1583,7 +1600,7 @@ bool CcdShapeConstructionInfo::SetProxy(CcdShapeConstructionInfo* shapeInfo)
return true; return true;
} }
btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape(btScalar margin)
{ {
btCollisionShape* collisionShape = 0; btCollisionShape* collisionShape = 0;
btTriangleMeshShape* concaveShape = 0; btTriangleMeshShape* concaveShape = 0;
@ -1591,7 +1608,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
CcdShapeConstructionInfo* nextShapeInfo; CcdShapeConstructionInfo* nextShapeInfo;
if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL) if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
return m_shapeProxy->CreateBulletShape(); return m_shapeProxy->CreateBulletShape(margin);
switch (m_shapeType) switch (m_shapeType)
{ {
@ -1600,22 +1617,27 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
case PHY_SHAPE_BOX: case PHY_SHAPE_BOX:
collisionShape = new btBoxShape(m_halfExtend); collisionShape = new btBoxShape(m_halfExtend);
collisionShape->setMargin(margin);
break; break;
case PHY_SHAPE_SPHERE: case PHY_SHAPE_SPHERE:
collisionShape = new btSphereShape(m_radius); collisionShape = new btSphereShape(m_radius);
collisionShape->setMargin(margin);
break; break;
case PHY_SHAPE_CYLINDER: case PHY_SHAPE_CYLINDER:
collisionShape = new btCylinderShapeZ(m_halfExtend); collisionShape = new btCylinderShapeZ(m_halfExtend);
collisionShape->setMargin(margin);
break; break;
case PHY_SHAPE_CONE: case PHY_SHAPE_CONE:
collisionShape = new btConeShapeZ(m_radius, m_height); collisionShape = new btConeShapeZ(m_radius, m_height);
collisionShape->setMargin(margin);
break; break;
case PHY_SHAPE_POLYTOPE: case PHY_SHAPE_POLYTOPE:
collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar)); collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar));
collisionShape->setMargin(margin);
break; break;
case PHY_SHAPE_MESH: case PHY_SHAPE_MESH:
@ -1638,7 +1660,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
); );
btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(indexVertexArrays); btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(indexVertexArrays);
gimpactShape->setMargin(margin);
collisionShape = gimpactShape; collisionShape = gimpactShape;
gimpactShape->updateBound(); gimpactShape->updateBound();
@ -1683,6 +1705,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
m_unscaledShape->recalcLocalAabb(); m_unscaledShape->recalcLocalAabb();
} }
collisionShape = new btScaledBvhTriangleMeshShape(m_unscaledShape, btVector3(1.0f,1.0f,1.0f)); collisionShape = new btScaledBvhTriangleMeshShape(m_unscaledShape, btVector3(1.0f,1.0f,1.0f));
collisionShape->setMargin(margin);
} }
break; break;
@ -1694,7 +1717,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
sit != m_shapeArray.end(); sit != m_shapeArray.end();
sit++) sit++)
{ {
collisionShape = (*sit)->CreateBulletShape(); collisionShape = (*sit)->CreateBulletShape(margin);
if (collisionShape) if (collisionShape)
{ {
collisionShape->setLocalScaling((*sit)->m_childScale); collisionShape->setLocalScaling((*sit)->m_childScale);

@ -152,7 +152,7 @@ public:
return m_shapeProxy; return m_shapeProxy;
} }
btCollisionShape* CreateBulletShape(); btCollisionShape* CreateBulletShape(btScalar margin);
// member variables // member variables
PHY_ShapeType m_shapeType; PHY_ShapeType m_shapeType;
@ -222,6 +222,7 @@ struct CcdConstructionInfo
m_collisionFlags(0), m_collisionFlags(0),
m_bRigid(false), m_bRigid(false),
m_bSoft(false), m_bSoft(false),
m_bSensor(false),
m_collisionFilterGroup(DefaultFilter), m_collisionFilterGroup(DefaultFilter),
m_collisionFilterMask(AllFilter), m_collisionFilterMask(AllFilter),
m_collisionShape(0), m_collisionShape(0),
@ -288,6 +289,7 @@ struct CcdConstructionInfo
int m_collisionFlags; int m_collisionFlags;
bool m_bRigid; bool m_bRigid;
bool m_bSoft; bool m_bSoft;
bool m_bSensor;
///optional use of collision group/mask: ///optional use of collision group/mask:
///only collision with object goups that match the collision mask. ///only collision with object goups that match the collision mask.
@ -326,7 +328,7 @@ class btSoftBody;
///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution. ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
class CcdPhysicsController : public PHY_IPhysicsController class CcdPhysicsController : public PHY_IPhysicsController
{ {
protected:
btCollisionObject* m_object; btCollisionObject* m_object;
@ -361,8 +363,8 @@ class CcdPhysicsController : public PHY_IPhysicsController
return (--m_registerCount == 0) ? true : false; return (--m_registerCount == 0) ? true : false;
} }
protected: void setWorldOrientation(const btMatrix3x3& mat);
void setWorldOrientation(const btMatrix3x3& mat); void forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos);
public: public:
@ -407,6 +409,7 @@ class CcdPhysicsController : public PHY_IPhysicsController
virtual void WriteMotionStateToDynamics(bool nondynaonly); virtual void WriteMotionStateToDynamics(bool nondynaonly);
virtual void WriteDynamicsToMotionState(); virtual void WriteDynamicsToMotionState();
// controller replication // controller replication
virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl); virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
@ -505,7 +508,7 @@ class CcdPhysicsController : public PHY_IPhysicsController
void SetCenterOfMassTransform(btTransform& xform); void SetCenterOfMassTransform(btTransform& xform);
static btTransform GetTransformFromMotionState(PHY_IMotionState* motionState); static btTransform& GetTransformFromMotionState(PHY_IMotionState* motionState);
void setAabb(const btVector3& aabbMin,const btVector3& aabbMax); void setAabb(const btVector3& aabbMin,const btVector3& aabbMax);
@ -563,6 +566,7 @@ class DefaultMotionState : public PHY_IMotionState
virtual void setWorldPosition(float posX,float posY,float posZ); virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal); virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void getWorldOrientation(float* ori); virtual void getWorldOrientation(float* ori);
virtual void setWorldOrientation(const float* ori);
virtual void calculateWorldTransformations(); virtual void calculateWorldTransformations();

@ -415,61 +415,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
obj->setActivationState(ISLAND_SLEEPING); obj->setActivationState(ISLAND_SLEEPING);
} }
//CollisionObject(body,ctrl->GetCollisionFilterGroup(),ctrl->GetCollisionFilterMask());
assert(obj->getBroadphaseHandle()); assert(obj->getBroadphaseHandle());
btBroadphaseInterface* scene = getBroadphase();
btCollisionShape* shapeinterface = ctrl->GetCollisionShape();
assert(shapeinterface);
const btTransform& t = ctrl->GetCollisionObject()->getWorldTransform();
btVector3 minAabb,maxAabb;
shapeinterface->getAabb(t,minAabb,maxAabb);
float timeStep = 0.02f;
//extent it with the motion
if (body)
{
btVector3 linMotion = body->getLinearVelocity()*timeStep;
float maxAabbx = maxAabb.getX();
float maxAabby = maxAabb.getY();
float maxAabbz = maxAabb.getZ();
float minAabbx = minAabb.getX();
float minAabby = minAabb.getY();
float minAabbz = minAabb.getZ();
if (linMotion.x() > 0.f)
maxAabbx += linMotion.x();
else
minAabbx += linMotion.x();
if (linMotion.y() > 0.f)
maxAabby += linMotion.y();
else
minAabby += linMotion.y();
if (linMotion.z() > 0.f)
maxAabbz += linMotion.z();
else
minAabbz += linMotion.z();
minAabb = btVector3(minAabbx,minAabby,minAabbz);
maxAabb = btVector3(maxAabbx,maxAabby,maxAabbz);
}
} }
@ -1884,29 +1830,20 @@ void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
// addCcdPhysicsController(ctrl1); // addCcdPhysicsController(ctrl1);
//} //}
enableCcdPhysicsController(ctrl1); enableCcdPhysicsController(ctrl1);
//Collision filter/mask is now set at the time of the creation of the controller
//force collision detection with everything, including static objects (might hurt performance!)
//ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask = btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::SensorTrigger;
//ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterGroup = btBroadphaseProxy::SensorTrigger;
//todo: make this 'sensor'!
requestCollisionCallback(ctrl);
//printf("addSensor\n");
} }
void CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl) bool CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
{ {
CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl; CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl;
if (ccdCtrl->Unregister()) if (!ccdCtrl->Unregister())
m_triggerControllers.erase(ccdCtrl); return false;
m_triggerControllers.erase(ccdCtrl);
return true;
} }
void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl) void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
{ {
removeCollisionCallback(ctrl);
disableCcdPhysicsController((CcdPhysicsController*)ctrl); disableCcdPhysicsController((CcdPhysicsController*)ctrl);
} }
@ -1942,12 +1879,14 @@ void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCal
m_triggerCallbacksUserPtrs[response_class] = user; m_triggerCallbacksUserPtrs[response_class] = user;
} }
void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl) bool CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
{ {
CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl); CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
if (ccdCtrl->Register()) if (!ccdCtrl->Register())
m_triggerControllers.insert(ccdCtrl); return false;
m_triggerControllers.insert(ccdCtrl);
return true;
} }
void CcdPhysicsEnvironment::CallbackTriggers() void CcdPhysicsEnvironment::CallbackTriggers()
@ -2096,12 +2035,13 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radi
// declare this object as Dyamic rather then static!! // declare this object as Dyamic rather then static!!
// The reason as it is designed to detect all type of object, including static object // The reason as it is designed to detect all type of object, including static object
// It would cause static-static message to be printed on the console otherwise // It would cause static-static message to be printed on the console otherwise
cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE/* | btCollisionObject::CF_KINEMATIC_OBJECT*/; cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
DefaultMotionState* motionState = new DefaultMotionState(); DefaultMotionState* motionState = new DefaultMotionState();
cinfo.m_MotionState = motionState; cinfo.m_MotionState = motionState;
// we will add later the possibility to select the filter from option // we will add later the possibility to select the filter from option
cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter; cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter; cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
cinfo.m_bSensor = true;
motionState->m_worldTransform.setIdentity(); motionState->m_worldTransform.setIdentity();
motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2])); motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
@ -2555,13 +2495,14 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateConeController(float conera
cinfo.m_collisionShape = new btConeShape(coneradius,coneheight); cinfo.m_collisionShape = new btConeShape(coneradius,coneheight);
cinfo.m_MotionState = 0; cinfo.m_MotionState = 0;
cinfo.m_physicsEnv = this; cinfo.m_physicsEnv = this;
cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
DefaultMotionState* motionState = new DefaultMotionState(); DefaultMotionState* motionState = new DefaultMotionState();
cinfo.m_MotionState = motionState; cinfo.m_MotionState = motionState;
// we will add later the possibility to select the filter from option // we will add later the possibility to select the filter from option
cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter; cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter; cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
cinfo.m_bSensor = true;
motionState->m_worldTransform.setIdentity(); motionState->m_worldTransform.setIdentity();
// motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2])); // motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));

@ -179,8 +179,8 @@ protected:
virtual void addSensor(PHY_IPhysicsController* ctrl); virtual void addSensor(PHY_IPhysicsController* ctrl);
virtual void removeSensor(PHY_IPhysicsController* ctrl); virtual void removeSensor(PHY_IPhysicsController* ctrl);
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user); virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl); virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl);
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl); virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl);
//These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else //These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position); virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight); virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);

@ -79,8 +79,8 @@ public:
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user) virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
{ {
} }
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl) { return false; }
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl) { return false;}
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;} virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;} virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}

@ -390,6 +390,11 @@ void SumoPhysicsController::PostProcessReplica(class PHY_IMotionState* motionst
m_sumoScene->add(* (m_sumoObj)); m_sumoScene->add(* (m_sumoObj));
} }
PHY_IMotionState* SumoPhysicsController::GetMotionState()
{
return m_MotionState;
}
void SumoPhysicsController::SetSimulatedTime(float) void SumoPhysicsController::SetSimulatedTime(float)
{ {
} }

@ -110,6 +110,7 @@ public:
virtual void WriteDynamicsToMotionState() {}; virtual void WriteDynamicsToMotionState() {};
virtual void WriteMotionStateToDynamics(bool nondynaonly); virtual void WriteMotionStateToDynamics(bool nondynaonly);
virtual class PHY_IMotionState* GetMotionState();
/** /**
* call from Scene Graph Node to 'update'. * call from Scene Graph Node to 'update'.

@ -213,7 +213,7 @@ void SumoPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCa
m_sumoScene->addTouchCallback(sumoRespClass,SumoPHYCallbackBridge::StaticSolidToPHYCallback,bridge); m_sumoScene->addTouchCallback(sumoRespClass,SumoPHYCallbackBridge::StaticSolidToPHYCallback,bridge);
} }
void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl) bool SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
{ {
SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl); SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
MT_assert(smctrl); MT_assert(smctrl);
@ -225,12 +225,15 @@ void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ct
smObject->setPhysicsClientObject(ctrl); smObject->setPhysicsClientObject(ctrl);
m_sumoScene->requestCollisionCallback(*smObject); m_sumoScene->requestCollisionCallback(*smObject);
return true;
} }
return false;
} }
void SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl) bool SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
{ {
// intentionally empty // intentionally empty
return false;
} }
PHY_IPhysicsController* SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position) PHY_IPhysicsController* SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)

@ -83,8 +83,8 @@ public:
virtual void addSensor(PHY_IPhysicsController* ctrl); virtual void addSensor(PHY_IPhysicsController* ctrl);
virtual void removeSensor(PHY_IPhysicsController* ctrl); virtual void removeSensor(PHY_IPhysicsController* ctrl);
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user); virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl); virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl);
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl); virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl);
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position); virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight); virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);

@ -45,10 +45,12 @@ class PHY_IMotionState
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0; virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0;
// ori = array 12 floats, [0..3] = first column + 0, [4..7] = second colum, [8..11] = third column // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second colum, [8..11] = third column
virtual void getWorldOrientation(float* ori)=0; virtual void getWorldOrientation(float* ori)=0;
virtual void setWorldOrientation(const float* ori)=0;
virtual void setWorldPosition(float posX,float posY,float posZ)=0; virtual void setWorldPosition(float posX,float posY,float posZ)=0;
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0; virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0;
virtual void calculateWorldTransformations()=0; virtual void calculateWorldTransformations()=0;
}; };

@ -31,7 +31,7 @@
#include "PHY_IController.h" #include "PHY_IController.h"
class PHY_IMotionState;
/** /**
PHY_IPhysicsController is the abstract simplified Interface to a physical object. PHY_IPhysicsController is the abstract simplified Interface to a physical object.
@ -53,6 +53,7 @@ class PHY_IPhysicsController : public PHY_IController
virtual void WriteMotionStateToDynamics(bool nondynaonly)=0; virtual void WriteMotionStateToDynamics(bool nondynaonly)=0;
virtual void WriteDynamicsToMotionState()=0; virtual void WriteDynamicsToMotionState()=0;
virtual class PHY_IMotionState* GetMotionState() = 0;
// controller replication // controller replication
virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0; virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0;

@ -152,8 +152,8 @@ class PHY_IPhysicsEnvironment
virtual void addSensor(PHY_IPhysicsController* ctrl)=0; virtual void addSensor(PHY_IPhysicsController* ctrl)=0;
virtual void removeSensor(PHY_IPhysicsController* ctrl)=0; virtual void removeSensor(PHY_IPhysicsController* ctrl)=0;
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0; virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0;
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl)=0; virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl)=0; virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl)=0;
//These two methods are *solely* used to create controllers for sensor! Don't use for anything else //These two methods are *solely* used to create controllers for sensor! Don't use for anything else
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0; virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0; virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;

@ -203,6 +203,13 @@ public:
return m_SGcontrollers; return m_SGcontrollers;
} }
/**
*
*/
SG_Callbacks& GetCallBackFunctions()
{
return m_callbacks;
}
/** /**
* Get the client object associated with this * Get the client object associated with this

@ -148,6 +148,13 @@ public:
SetModified(); SetModified();
} }
// rot is arrange like openGL matrix
void SetLocalOrientation(const float* rot)
{
m_localRotation.setValue(rot);
SetModified();
}
void SetWorldOrientation(const MT_Matrix3x3& rot) void SetWorldOrientation(const MT_Matrix3x3& rot)
{ {
m_worldRotation = rot; m_worldRotation = rot;