From e7ad6ed3a3fda013cd393df6bb50236871092249 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 3 Aug 2012 14:44:07 -0700 Subject: BulletSim: pass collision subscription information to the C++ code so collisions on objects that don't care are not reported up. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 18 ++++++++++++++- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 16 +++++++++++-- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 27 +++++++++++----------- 3 files changed, 45 insertions(+), 16 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index a5635ff..494f5a6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -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() { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 22f5995..8e6685b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -642,11 +642,23 @@ public sealed class BSPrim : PhysicsActor } public override void SubscribeEvents(int ms) { _subscribedEventsMs = ms; - // make sure first collision happens - _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; + 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); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 1881e41..4e05df6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -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); -- cgit v1.1