BulletSim: make it so objects in a linkset do not generate collisions with each other.

integration
Robert Adams 2012-08-15 16:27:30 -07:00
parent ae5db637f2
commit 376441e550
3 changed files with 27 additions and 2 deletions

View File

@ -42,6 +42,9 @@ public class BSLinkset
private BSScene m_physicsScene; private BSScene m_physicsScene;
public BSScene PhysicsScene { get { return m_physicsScene; } } public BSScene PhysicsScene { get { return m_physicsScene; } }
static int m_nextLinksetID = 1;
public int LinksetID { get; private set; }
// The children under the root in this linkset // The children under the root in this linkset
private List<BSPrim> m_children; private List<BSPrim> m_children;
@ -74,6 +77,10 @@ public class BSLinkset
public BSLinkset(BSScene scene, BSPrim parent) public BSLinkset(BSScene scene, BSPrim parent)
{ {
// A simple linkset of one (no children) // A simple linkset of one (no children)
LinksetID = m_nextLinksetID++;
// We create LOTS of linksets.
if (m_nextLinksetID < 0)
m_nextLinksetID = 1;
m_physicsScene = scene; m_physicsScene = scene;
m_linksetRoot = parent; m_linksetRoot = parent;
m_children = new List<BSPrim>(); m_children = new List<BSPrim>();

View File

@ -1353,6 +1353,7 @@ public sealed class BSPrim : PhysicsActor
} }
// I've collided with something // I've collided with something
// Called at taint time from within the Step() function
CollisionEventUpdate collisionCollection; CollisionEventUpdate collisionCollection;
public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
{ {
@ -1366,6 +1367,15 @@ public sealed class BSPrim : PhysicsActor
} }
// DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith); // DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith);
BSPrim collidingWithPrim;
if (_scene.Prims.TryGetValue(collidingWith, out collidingWithPrim))
{
// prims in the same linkset cannot collide with each other
if (this.Linkset.LinksetID == collidingWithPrim.Linkset.LinksetID)
{
return;
}
}
// if someone is subscribed to collision events.... // if someone is subscribed to collision events....
if (_subscribedEventsMs != 0) { if (_subscribedEventsMs != 0) {

View File

@ -78,10 +78,16 @@ public class BSScene : PhysicsScene, IPhysicsParameters
public string BulletSimVersion = "?"; public string BulletSimVersion = "?";
private Dictionary<uint, BSCharacter> m_avatars = new Dictionary<uint, BSCharacter>(); private Dictionary<uint, BSCharacter> m_avatars = new Dictionary<uint, BSCharacter>();
public Dictionary<uint, BSCharacter> Characters { get { return m_avatars; } }
private Dictionary<uint, BSPrim> m_prims = new Dictionary<uint, BSPrim>(); private Dictionary<uint, BSPrim> m_prims = new Dictionary<uint, BSPrim>();
public Dictionary<uint, BSPrim> Prims { get { return m_prims; } }
private HashSet<BSCharacter> m_avatarsWithCollisions = new HashSet<BSCharacter>(); private HashSet<BSCharacter> m_avatarsWithCollisions = new HashSet<BSCharacter>();
private HashSet<BSPrim> m_primsWithCollisions = new HashSet<BSPrim>(); private HashSet<BSPrim> m_primsWithCollisions = new HashSet<BSPrim>();
private List<BSPrim> m_vehicles = new List<BSPrim>(); private List<BSPrim> m_vehicles = new List<BSPrim>();
private float[] m_heightMap; private float[] m_heightMap;
private float m_waterLevel; private float m_waterLevel;
private uint m_worldID; private uint m_worldID;
@ -429,13 +435,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters
{ {
numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep, numSubSteps = BulletSimAPI.PhysicsStep(m_worldID, timeStep, m_maxSubSteps, m_fixedTimeStep,
out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr);
// DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); DetailLog("{0},Simulate,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e); m_log.WarnFormat("{0},PhysicsStep Exception: substeps={1}, updates={2}, colliders={3}, e={4}", LogHeader, numSubSteps, updatedEntityCount, collidersCount, e);
// DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount); // DetailLog("{0},PhysicsStepException,call, substeps={1}, updates={2}, colliders={3}", DetailLogZero, numSubSteps, updatedEntityCount, collidersCount);
// updatedEntityCount = 0; updatedEntityCount = 0;
collidersCount = 0; collidersCount = 0;
} }
@ -534,6 +540,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
else if (m_avatars.ContainsKey(collidingWith)) else if (m_avatars.ContainsKey(collidingWith))
type = ActorTypes.Agent; type = ActorTypes.Agent;
DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith);
BSPrim prim; BSPrim prim;
if (m_prims.TryGetValue(localID, out prim)) { if (m_prims.TryGetValue(localID, out prim)) {
prim.Collide(collidingWith, type, collidePoint, collideNormal, penitration); prim.Collide(collidingWith, type, collidePoint, collideNormal, penitration);