BulletSim: pass collision subscription information to the C++ code so collisions on objects that don't care are not reported up.
parent
ea36d4a4cf
commit
e7ad6ed3a3
|
@ -125,6 +125,8 @@ public class BSCharacter : PhysicsActor
|
|||
BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData);
|
||||
|
||||
m_body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
|
||||
// avatars get all collisions no matter what
|
||||
BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -384,11 +386,25 @@ public class BSCharacter : PhysicsActor
|
|||
// Turn on collision events at a rate no faster than one every the given milliseconds
|
||||
public override void SubscribeEvents(int ms) {
|
||||
_subscribedEventsMs = ms;
|
||||
_nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; // make first collision happen
|
||||
if (ms > 0)
|
||||
{
|
||||
// make sure first collision happens
|
||||
_nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
|
||||
|
||||
Scene.TaintedObject(delegate()
|
||||
{
|
||||
BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
|
||||
});
|
||||
}
|
||||
}
|
||||
// Stop collision events
|
||||
public override void UnSubscribeEvents() {
|
||||
_subscribedEventsMs = 0;
|
||||
// Avatars get all their collision events
|
||||
// Scene.TaintedObject(delegate()
|
||||
// {
|
||||
// BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
|
||||
// });
|
||||
}
|
||||
// Return 'true' if someone has subscribed to events
|
||||
public override bool SubscribedEvents() {
|
||||
|
|
|
@ -642,11 +642,23 @@ public sealed class BSPrim : PhysicsActor
|
|||
}
|
||||
public override void SubscribeEvents(int ms) {
|
||||
_subscribedEventsMs = ms;
|
||||
if (ms > 0)
|
||||
{
|
||||
// make sure first collision happens
|
||||
_nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
|
||||
|
||||
Scene.TaintedObject(delegate()
|
||||
{
|
||||
BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
|
||||
});
|
||||
}
|
||||
}
|
||||
public override void UnSubscribeEvents() {
|
||||
_subscribedEventsMs = 0;
|
||||
Scene.TaintedObject(delegate()
|
||||
{
|
||||
BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
|
||||
});
|
||||
}
|
||||
public override bool SubscribedEvents() {
|
||||
return (_subscribedEventsMs > 0);
|
||||
|
|
|
@ -179,17 +179,18 @@ public struct ConfigurationParameters
|
|||
// Values used by Bullet and BulletSim to control collisions
|
||||
public enum CollisionFlags : uint
|
||||
{
|
||||
STATIC_OBJECT = 1 << 0,
|
||||
KINEMATIC_OBJECT = 1 << 1,
|
||||
NO_CONTACT_RESPONSE = 1 << 2,
|
||||
CUSTOM_MATERIAL_CALLBACK = 1 << 3,
|
||||
CHARACTER_OBJECT = 1 << 4,
|
||||
DISABLE_VISUALIZE_OBJECT = 1 << 5,
|
||||
DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
|
||||
CF_STATIC_OBJECT = 1 << 0,
|
||||
CF_KINEMATIC_OBJECT = 1 << 1,
|
||||
CF_NO_CONTACT_RESPONSE = 1 << 2,
|
||||
CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
|
||||
CF_CHARACTER_OBJECT = 1 << 4,
|
||||
CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
|
||||
CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
|
||||
// Following used by BulletSim to control collisions
|
||||
VOLUME_DETECT_OBJECT = 1 << 10,
|
||||
PHANTOM_OBJECT = 1 << 11,
|
||||
PHYSICAL_OBJECT = 1 << 12,
|
||||
BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
|
||||
BS_VOLUME_DETECT_OBJECT = 1 << 11,
|
||||
BS_PHANTOM_OBJECT = 1 << 12,
|
||||
BS_PHYSICAL_OBJECT = 1 << 13,
|
||||
};
|
||||
|
||||
// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
|
||||
|
@ -481,13 +482,13 @@ public static extern bool SetLinearVelocity2(IntPtr obj, Vector3 val);
|
|||
public static extern bool SetInterpolation2(IntPtr obj, Vector3 lin, Vector3 ang);
|
||||
|
||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
public static extern IntPtr SetCollisionFlags2(IntPtr obj, uint flags);
|
||||
public static extern IntPtr SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
|
||||
|
||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
public static extern IntPtr AddToCollisionFlags2(IntPtr obj, uint flags);
|
||||
public static extern IntPtr AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
|
||||
|
||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
public static extern IntPtr RemoveFromCollisionFlags2(IntPtr obj, uint flags);
|
||||
public static extern IntPtr RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
|
||||
|
||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
public static extern bool SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
|
||||
|
|
Loading…
Reference in New Issue