new BulletSPlugin and version of BulletSim.dll

dsg
Robert Adams 2011-05-24 17:09:45 -07:00
parent 080db3019e
commit 53fa87ad76
5 changed files with 83 additions and 36 deletions

View File

@ -30,6 +30,7 @@ using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
using OpenSim.Region.CoreModules.RegionSync.RegionSyncModule;
namespace OpenSim.Region.Physics.BulletSPlugin
{
@ -123,7 +124,19 @@ public class BSCharacter : PhysicsActor
public override void RequestPhysicsterseUpdate()
{
base.RequestPhysicsterseUpdate();
if (PhysEngineToSceneConnectorModule.IsPhysEngineActorS)
{
// if the values have changed and it was I who changed them, send an update
if (this.lastValues.Changed(this) && ChangingActorID == RegionSyncServerModule.ActorID)
{
// m_log.DebugFormat("{0}: Sending terse update for {1}", LogHeader, LocalID);
PhysEngineToSceneConnectorModule.RouteUpdate(this);
}
}
else
{
base.RequestPhysicsterseUpdate();
}
}
public override bool Stopped {
@ -132,6 +145,7 @@ public class BSCharacter : PhysicsActor
public override Vector3 Size {
get { return _size; }
set { _size = value;
base.ChangingActorID = RegionSyncServerModule.ActorID;
}
}
public override PrimitiveBaseShape Shape {
@ -158,11 +172,12 @@ public class BSCharacter : PhysicsActor
public override Vector3 Position {
get {
_position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
// _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
return _position;
}
set {
_position = value;
base.ChangingActorID = RegionSyncServerModule.ActorID;
_scene.TaintedObject(delegate()
{
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
@ -178,7 +193,7 @@ public class BSCharacter : PhysicsActor
get { return _force; }
set {
_force = value;
m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force);
// m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force);
_scene.TaintedObject(delegate()
{
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
@ -204,6 +219,7 @@ public class BSCharacter : PhysicsActor
get { return _velocity; }
set {
_velocity = value;
base.ChangingActorID = RegionSyncServerModule.ActorID;
_scene.TaintedObject(delegate()
{
BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity);
@ -229,7 +245,7 @@ public class BSCharacter : PhysicsActor
_orientation = value;
_scene.TaintedObject(delegate()
{
_position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
// _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
});
}
@ -329,15 +345,16 @@ public class BSCharacter : PhysicsActor
_force.X += force.X;
_force.Y += force.Y;
_force.Z += force.Z;
base.ChangingActorID = RegionSyncServerModule.ActorID;
_scene.TaintedObject(delegate()
{
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
});
}
else
{
m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader);
}
_scene.TaintedObject(delegate()
{
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
});
//m_lastUpdateSent = false;
}
public override void AddAngularForce(Vector3 force, bool pushforce) {
@ -387,14 +404,13 @@ public class BSCharacter : PhysicsActor
}
if (changed)
{
base.RequestPhysicsterseUpdate();
this.RequestPhysicsterseUpdate();
}
}
public void Collide(uint collidingWith, ActorTypes type, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
{
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
if (_subscribedEventsMs == 0) return; // don't want collisions
// The following says we're colliding this simulation step
_collidingStep = _scene.SimulationStep;
@ -403,6 +419,8 @@ public class BSCharacter : PhysicsActor
_collidingGroundStep = _scene.SimulationStep;
}
if (_subscribedEventsMs == 0) return; // don't want collisions
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
CollisionEventUpdate args = new CollisionEventUpdate(LocalID, (int)type, 1, contactPoints);

View File

@ -56,6 +56,7 @@ public sealed class BSPrim : PhysicsActor
private bool _stopped;
private bool _grabbed;
private bool _isSelected;
private bool _isVolumeDetect;
private OMV.Vector3 _position;
private float _mass;
private float _density;
@ -109,6 +110,7 @@ public sealed class BSPrim : PhysicsActor
_hullKey = 0;
_pbs = pbs;
_isPhysical = pisPhysical;
_isVolumeDetect = false;
_subscribedEventsMs = 0;
_friction = _scene.DefaultFriction; // TODO: compute based on object material
_density = _scene.DefaultDensity; // TODO: compute based on object material
@ -323,7 +325,21 @@ public sealed class BSPrim : PhysicsActor
public override void VehicleFlags(int param, bool remove) { }
// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
public override void SetVolumeDetect(int param) { return; }
public override void SetVolumeDetect(int param) {
bool newValue = (param != 0);
if (_isVolumeDetect != newValue)
{
_isVolumeDetect = newValue;
_scene.TaintedObject(delegate()
{
// make the object ghostly or not (walk throughable)
BulletSimAPI.SetObjectGhost(_scene.WorldID, LocalID, _isVolumeDetect);
// set whether we hear about collisions
BulletSimAPI.SetObjectCollidable(_scene.WorldID, LocalID, !IsPhantom);
});
}
return;
}
public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } }
@ -1069,15 +1085,15 @@ public sealed class BSPrim : PhysicsActor
public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
{
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
if (_subscribedEventsMs == 0) return; // nothing in the object is waiting for collision events
// The following makes it so we can sense we're colliding this simulation step
// The following makes IsColliding() and IsCollidingGround() work
_collidingStep = _scene.SimulationStep;
if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
{
_collidingGroundStep = _scene.SimulationStep;
}
if (_subscribedEventsMs == 0) return; // nothing in the object is waiting for collision events
// create the event for the collision
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));

View File

@ -40,14 +40,18 @@ using OpenSim.Region.Framework;
// Based on material, set density and friction
// More efficient memory usage in passing hull information from BSPrim to BulletSim
// Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly?
// In SL one can set both physical and phantom (gravity, does not effect others, makes collisions)
// Need three states for objects: sense and report collisions, have physical effects, affects other objects
// In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground)
// LinkSets
// Freeing of memory of linksets in BulletSim::DestroyObject
// Should prim.link() and prim.delink() be done at taint time?
// Set child prims phantom since the physicality is handled by the parent prim
// Linked children need rotation relative to parent (passed as world rotation)
// Should prim.link() and prim.delink() membership checking happen at taint time?
// Pass collision enable flags to BulletSim code so collisions are not reported up unless they are really needed
// Set child prims phantom since the physicality is handled by the parent prim
// Linked children need rotation relative to parent (passed as world rotation)
// Set bouyancy(). Maybe generalize SetFlying() to SetBouyancy() and use the factor to change the gravity effect
// Test sculpties
// Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once
// Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect
// Parameterize BulletSim. Pass a structure of parameters to the C++ code. Capsule size, friction, ...
//
namespace OpenSim.Region.Physics.BulletSPlugin
{
@ -82,6 +86,7 @@ public class BSScene : PhysicsScene
public delegate void TaintCallback();
private List<TaintCallback> _taintedObjects;
private Object _taintLock = new Object();
private BulletSimAPI.DebugLogCallback debugLogCallbackHandle;
@ -243,19 +248,22 @@ public class BSScene : PhysicsScene
IntPtr updatePointer = updatedEntities[ii];
EntityProperties entprop = (EntityProperties)Marshal.PtrToStructure(updatePointer, typeof(EntityProperties));
// m_log.DebugFormat("{0}: entprop: id={1}, pos={2}", LogHeader, entprop.ID, entprop.Position);
if (m_avatars.ContainsKey(entprop.ID))
BSCharacter actor;
if (m_avatars.TryGetValue(entprop.ID, out actor))
{
BSCharacter actor = m_avatars[entprop.ID];
actor.UpdateProperties(entprop);
continue;
}
if (m_prims.ContainsKey(entprop.ID))
BSPrim prim;
if (m_prims.TryGetValue(entprop.ID, out prim))
{
BSPrim prim = m_prims[entprop.ID];
prim.UpdateProperties(entprop);
}
}
}
// if (collidersCount > 0 || updatedEntityCount > 0) m_log.WarnFormat("{0}: collisions={1}, updates={2}", LogHeader, collidersCount/2, updatedEntityCount);
return 11f; // returns frames per second
}
@ -269,20 +277,18 @@ public class BSScene : PhysicsScene
}
ActorTypes type = ActorTypes.Prim;
if (m_avatars.ContainsKey(collidingWith))
type = ActorTypes.Agent;
else if (collidingWith == TERRAIN_ID || collidingWith == GROUNDPLANE_ID)
if (collidingWith == TERRAIN_ID || collidingWith == GROUNDPLANE_ID)
type = ActorTypes.Ground;
else if (m_avatars.ContainsKey(collidingWith))
type = ActorTypes.Agent;
if (m_prims.ContainsKey(localID))
{
BSPrim prim = m_prims[localID];
BSPrim prim;
if (m_prims.TryGetValue(localID, out prim)) {
prim.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
return;
}
if (m_avatars.ContainsKey(localID))
{
BSCharacter actor = m_avatars[localID];
BSCharacter actor;
if (m_avatars.TryGetValue(localID, out actor)) {
actor.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
return;
}
@ -440,8 +446,8 @@ public class BSScene : PhysicsScene
// We rely on C#'s closure to save and restore the context for the delegate.
public void TaintedObject(TaintCallback callback)
{
// do we need to lock?
_taintedObjects.Add(callback);
lock (_taintLock)
_taintedObjects.Add(callback);
return;
}
@ -451,8 +457,12 @@ public class BSScene : PhysicsScene
public void ProcessTaints()
{
// swizzle a new list into the list location so we can process what's there
List<TaintCallback> newList = new List<TaintCallback>();
List<TaintCallback> oldList = (List<TaintCallback>)Interlocked.Exchange(ref _taintedObjects, newList);
List<TaintCallback> oldList;
lock (_taintLock)
{
oldList = _taintedObjects;
_taintedObjects = new List<TaintCallback>();
}
foreach (TaintCallback callback in oldList)
{

View File

@ -144,6 +144,9 @@ public static extern bool SetObjectCollidable(uint worldID, uint id, bool phanto
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SetObjectFlying(uint worldID, uint id, bool flying);

Binary file not shown.