BulletSim: Remove calculation and passing of unused collied object type.
Fix collision code to properly sense mega-region children regions as terrain. When setting an object physical, reset all the physical properties (friction, ...).connector_plugin
parent
f0a098924e
commit
6632eb7c05
|
@ -529,22 +529,20 @@ public class BSCharacter : BSPhysObject
|
||||||
// The collision, if it should be reported to the character, is placed in a collection
|
// The collision, if it should be reported to the character, is placed in a collection
|
||||||
// that will later be sent to the simulator when SendCollisions() is called.
|
// that will later be sent to the simulator when SendCollisions() is called.
|
||||||
CollisionEventUpdate collisionCollection = null;
|
CollisionEventUpdate collisionCollection = null;
|
||||||
public override bool Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
|
public override bool Collide(uint collidingWith, BSPhysObject collidee, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
// The following makes IsColliding() and IsCollidingGround() work
|
// The following makes IsColliding() and IsCollidingGround() work
|
||||||
_collidingStep = Scene.SimulationStep;
|
_collidingStep = Scene.SimulationStep;
|
||||||
if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
|
if (collidingWith <= Scene.TerrainManager.HighestTerrainID)
|
||||||
{
|
{
|
||||||
_collidingGroundStep = Scene.SimulationStep;
|
_collidingGroundStep = Scene.SimulationStep;
|
||||||
}
|
}
|
||||||
// DetailLog("{0},BSCharacter.Collison,call,with={1}", LocalID, collidingWith);
|
// DetailLog("{0},BSCharacter.Collison,call,with={1}", LocalID, collidingWith);
|
||||||
|
|
||||||
// throttle collisions to the rate specified in the subscription
|
// throttle collisions to the rate specified in the subscription
|
||||||
if (_subscribedEventsMs != 0) {
|
if (SubscribedEvents()) {
|
||||||
int nowTime = Scene.SimulationNowTime;
|
int nowTime = Scene.SimulationNowTime;
|
||||||
if (nowTime >= _nextCollisionOkTime) {
|
if (nowTime >= _nextCollisionOkTime) {
|
||||||
_nextCollisionOkTime = nowTime + _subscribedEventsMs;
|
_nextCollisionOkTime = nowTime + _subscribedEventsMs;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
{
|
{
|
||||||
public abstract BSLinkset Linkset { get; set; }
|
public abstract BSLinkset Linkset { get; set; }
|
||||||
|
|
||||||
public abstract bool Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type,
|
public abstract bool Collide(uint collidingWith, BSPhysObject collidee,
|
||||||
OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth);
|
OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth);
|
||||||
public abstract void SendCollisions();
|
public abstract void SendCollisions();
|
||||||
|
|
||||||
|
|
|
@ -545,14 +545,31 @@ public sealed class BSPrim : BSPhysObject
|
||||||
{
|
{
|
||||||
// Not a Bullet static object
|
// Not a Bullet static object
|
||||||
m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
||||||
|
|
||||||
|
// Set various physical properties so internal things will get computed correctly as they are set
|
||||||
|
BulletSimAPI.SetFriction2(BSBody.Ptr, Scene.Params.defaultFriction);
|
||||||
|
BulletSimAPI.SetRestitution2(BSBody.Ptr, Scene.Params.defaultRestitution);
|
||||||
|
// per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
|
||||||
|
BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
|
||||||
|
BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
|
||||||
|
BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero);
|
||||||
|
|
||||||
// A dynamic object has mass
|
// A dynamic object has mass
|
||||||
IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr);
|
IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr);
|
||||||
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass);
|
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass);
|
||||||
BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, inertia);
|
BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, inertia);
|
||||||
// Inertia is based on our new mass
|
// Inertia is based on our new mass
|
||||||
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
||||||
|
|
||||||
|
// Various values for simulation limits
|
||||||
|
BulletSimAPI.SetDamping2(BSBody.Ptr, Scene.Params.linearDamping, Scene.Params.angularDamping);
|
||||||
|
BulletSimAPI.SetDeactivationTime2(BSBody.Ptr, Scene.Params.deactivationTime);
|
||||||
|
BulletSimAPI.SetSleepingThresholds2(BSBody.Ptr, Scene.Params.linearSleepingThreshold, Scene.Params.angularSleepingThreshold);
|
||||||
|
BulletSimAPI.SetContactProcessingThreshold2(BSBody.Ptr, Scene.Params.contactProcessingThreshold);
|
||||||
|
|
||||||
// There can be special things needed for implementing linksets
|
// There can be special things needed for implementing linksets
|
||||||
Linkset.MakeDynamic(this);
|
Linkset.MakeDynamic(this);
|
||||||
|
|
||||||
// Force activation of the object so Bullet will act on it.
|
// Force activation of the object so Bullet will act on it.
|
||||||
BulletSimAPI.Activate2(BSBody.Ptr, true);
|
BulletSimAPI.Activate2(BSBody.Ptr, true);
|
||||||
}
|
}
|
||||||
|
@ -1475,16 +1492,15 @@ public sealed class BSPrim : BSPhysObject
|
||||||
// I've collided with something
|
// I've collided with something
|
||||||
// Called at taint time from within the Step() function
|
// Called at taint time from within the Step() function
|
||||||
CollisionEventUpdate collisionCollection;
|
CollisionEventUpdate collisionCollection;
|
||||||
public override bool Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
|
public override bool Collide(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
// The following lines make IsColliding() and IsCollidingGround() work
|
// The following lines make IsColliding() and IsCollidingGround() work
|
||||||
_collidingStep = _scene.SimulationStep;
|
_collidingStep = Scene.SimulationStep;
|
||||||
if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
|
if (collidingWith <= Scene.TerrainManager.HighestTerrainID)
|
||||||
{
|
{
|
||||||
_collidingGroundStep = _scene.SimulationStep;
|
_collidingGroundStep = Scene.SimulationStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith);
|
// DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith);
|
||||||
|
@ -1498,7 +1514,7 @@ public sealed class BSPrim : BSPhysObject
|
||||||
// if someone has subscribed for collision events....
|
// if someone has subscribed for collision events....
|
||||||
if (SubscribedEvents()) {
|
if (SubscribedEvents()) {
|
||||||
// throttle the collisions to the number of milliseconds specified in the subscription
|
// throttle the collisions to the number of milliseconds specified in the subscription
|
||||||
int nowTime = _scene.SimulationNowTime;
|
int nowTime = Scene.SimulationNowTime;
|
||||||
if (nowTime >= _nextCollisionOkTime) {
|
if (nowTime >= _nextCollisionOkTime) {
|
||||||
_nextCollisionOkTime = nowTime + _subscribedEventsMs;
|
_nextCollisionOkTime = nowTime + _subscribedEventsMs;
|
||||||
|
|
||||||
|
|
|
@ -583,27 +583,21 @@ public class BSScene : PhysicsScene, IPhysicsParameters
|
||||||
return; // don't send collisions to the terrain
|
return; // don't send collisions to the terrain
|
||||||
}
|
}
|
||||||
|
|
||||||
BSPhysObject collider = PhysObjects[localID];
|
BSPhysObject collider;
|
||||||
// TODO: as of this code, terrain was not in the physical object list.
|
if (!PhysObjects.TryGetValue(localID, out collider))
|
||||||
// When BSTerrain is created and it will be in the list, we can remove
|
{
|
||||||
// the possibility that it's not there and just fetch the collidee.
|
// If the object that is colliding cannot be found, just ignore the collision.
|
||||||
BSPhysObject collidee = null;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ActorTypes type = ActorTypes.Prim;
|
// The terrain is not in the physical object list so 'collidee'
|
||||||
if (collidingWith <= TerrainManager.HighestTerrainID)
|
// can be null when Collide() is called.
|
||||||
{
|
BSPhysObject collidee = null;
|
||||||
type = ActorTypes.Ground;
|
PhysObjects.TryGetValue(collidingWith, out collidee);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
collidee = PhysObjects[collidingWith];
|
|
||||||
if (collidee is BSCharacter)
|
|
||||||
type = ActorTypes.Agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith);
|
// DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith);
|
||||||
|
|
||||||
if (collider.Collide(collidingWith, collidee, type, collidePoint, collideNormal, penetration))
|
if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration))
|
||||||
{
|
{
|
||||||
// If a collision was posted, remember to send it to the simulator
|
// If a collision was posted, remember to send it to the simulator
|
||||||
m_objectsWithCollisions.Add(collider);
|
m_objectsWithCollisions.Add(collider);
|
||||||
|
|
Loading…
Reference in New Issue