28 using System.Collections.Generic;
31 using OMV = OpenMetaverse;
32 using OpenSim.Framework;
33 using OpenSim.Region.PhysicsModules.SharedBase;
35 namespace OpenSim.
Region.PhysicsModule.BulletS
75 IsInitialized =
false;
77 PhysScene = parentScene;
79 PhysObjectName = name;
84 if (!PhysBody.HasPhysicalBody)
89 PhysicalActors.Dispose();
91 UserSetCenterOfMassDisplacement = null;
93 PrimAssetState = PrimAssetCondition.Unknown;
98 Gravity =
new OMV.Vector3(0f, 0f, BSParam.Gravity);
104 CollisionsLastTickStep = -1;
106 SubscribedEventsMs = 0;
108 CollidingStep = BSScene.NotASimulationStep;
109 CollidingGroundStep = BSScene.NotASimulationStep;
110 CollisionAccumulation = BSScene.NotASimulationStep;
111 ColliderIsMoving =
false;
115 LockedLinearAxis = LockedAxisFree;
116 LockedAngularAxis = LockedAxisFree;
122 PhysicalActors.Enable(
false);
123 PhysScene.TaintedObject(LocalID,
"BSPhysObject.Destroy", delegate()
125 PhysicalActors.Dispose();
129 public BSScene PhysScene {
get;
protected set; }
131 public string PhysObjectName {
get;
protected set; }
132 public string TypeName {
get;
protected set; }
136 public bool IsInitialized {
get;
protected set; }
145 abstract public bool IsIncomplete {
get; }
148 public abstract float RawMass {
get; }
151 public abstract void UpdatePhysicalMassProperties(
float mass,
bool inWorld);
154 public virtual OMV.Vector3 Gravity {
get; set; }
156 public OMV.Vector3 Inertia {
get; set; }
167 Unknown, Waiting, FailedAssetFetch, FailedMeshing, Fetched
185 public virtual OMV.Vector3
Scale {
get; set; }
190 public abstract bool IsPhysicallyActive {
get; }
193 public abstract bool IsSolid {
get; }
194 public abstract bool IsStatic {
get; }
195 public abstract bool IsSelected {
get; }
196 public abstract bool IsVolumeDetect {
get; }
207 Friction = matAttrib.friction;
208 Restitution = matAttrib.restitution;
209 Density = matAttrib.density;
213 public override float Density
221 DetailLog(
"{0},BSPhysObject.Density,set,den={1}", LocalID, value);
222 base.Density = value;
227 public abstract void ZeroMotion(
bool inTaintTime);
228 public abstract void ZeroAngularMotion(
bool inTaintTime);
233 public virtual OMV.Vector3 RawPosition {
get; set; }
234 public abstract OMV.Vector3 ForcePosition {
get; set; }
236 public virtual OMV.Quaternion RawOrientation {
get; set; }
237 public abstract OMV.Quaternion ForceOrientation {
get; set; }
239 public virtual OMV.Vector3 RawVelocity {
get; set; }
240 public abstract OMV.Vector3 ForceVelocity {
get; set; }
243 public OMV.Vector3 RawForce {
get; set; }
244 public OMV.Vector3 RawTorque {
get; set; }
248 AddAngularForce(
false, force);
250 public abstract void AddAngularForce(
bool inTaintTime,
OMV.Vector3 force);
251 public abstract void AddForce(
bool inTaintTime,
OMV.Vector3 force);
253 public abstract OMV.Vector3 ForceRotationalVelocity {
get; set; }
255 public abstract float ForceBuoyancy {
get; set; }
259 public override bool PIDActive
261 get {
return MoveToTargetActive; }
262 set { MoveToTargetActive = value; }
265 public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } }
266 public override float PIDTau { set { MoveToTargetTau = value; } }
268 public bool MoveToTargetActive {
get; set; }
269 public OMV.Vector3 MoveToTargetTarget {
get; set; }
270 public float MoveToTargetTau {
get; set; }
273 public override bool PIDHoverActive {
get {
return HoverActive;} set { HoverActive = value; } }
274 public override float PIDHoverHeight { set { HoverHeight = value; } }
276 public override float PIDHoverTau { set { HoverTau = value; } }
278 public bool HoverActive {
get; set; }
279 public float HoverHeight {
get; set; }
281 public float HoverTau {
get; set; }
284 public override OMV.Quaternion APIDTarget { set {
return; } }
285 public override bool APIDActive { set {
return; } }
286 public override float APIDStrength { set {
return; } }
287 public override float APIDDamping { set {
return; } }
290 public virtual float ForwardSpeed
294 OMV.Vector3 characterOrientedVelocity = RawVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation));
295 return characterOrientedVelocity.X;
299 public virtual float TargetVelocitySpeed
303 OMV.Vector3 characterOrientedVelocity = TargetVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation));
304 return characterOrientedVelocity.X;
311 public OMV.Vector3? UserSetCenterOfMassDisplacement {
get; set; }
315 public const float FreeAxis = 1f;
316 public const float LockedAxis = 0f;
317 public readonly OMV.Vector3 LockedAxisFree =
new OMV.Vector3(FreeAxis, FreeAxis, FreeAxis);
332 if (PhysBody.HasPhysicalBody)
337 PhysScene.PE.Activate(PhysBody, forceIt);
342 PhysScene.PE.ClearCollisionProxyCache(PhysScene.World, PhysBody);
353 public delegate
BSActor CreateActor();
354 public void EnableActor(
bool enableActor,
string actorName, CreateActor creator)
356 lock (PhysicalActors)
359 if (PhysicalActors.TryGetActor(actorName, out theActor))
362 DetailLog(
"{0},BSPhysObject.EnableActor,enablingExistingActor,name={1},enable={2}", LocalID, actorName, enableActor);
363 theActor.Enabled = enableActor;
370 DetailLog(
"{0},BSPhysObject.EnableActor,creatingActor,name={1}", LocalID, actorName);
371 theActor = creator();
372 PhysicalActors.Add(actorName, theActor);
373 theActor.Enabled =
true;
377 DetailLog(
"{0},BSPhysObject.EnableActor,notCreatingActorSinceNotEnabled,name={1}", LocalID, actorName);
386 protected int SubscribedEventsMs {
get; set; }
388 protected int NextCollisionOkTime {
get; set; }
390 protected long CollidingStep {
get; set; }
392 protected long CollidingGroundStep {
get; set; }
394 protected long CollidingObjectStep {
get; set; }
406 protected long CollisionAccumulation {
get; set; }
408 public override bool IsColliding {
409 get {
return (CollidingStep == PhysScene.SimulationStep); }
412 CollidingStep = PhysScene.SimulationStep;
414 CollidingStep = BSScene.NotASimulationStep;
422 public virtual bool HasSomeCollision
424 get {
return IsColliding; }
425 set { IsColliding = value; }
427 public override bool CollidingGround {
428 get {
return (CollidingGroundStep == PhysScene.SimulationStep); }
432 CollidingGroundStep = PhysScene.SimulationStep;
434 CollidingGroundStep = BSScene.NotASimulationStep;
437 public override bool CollidingObj {
438 get {
return (CollidingObjectStep == PhysScene.SimulationStep); }
441 CollidingObjectStep = PhysScene.SimulationStep;
443 CollidingObjectStep = BSScene.NotASimulationStep;
454 private long CollisionsLastTickStep = -1;
468 if (collideeLocalID <= PhysScene.TerrainManager.HighestTerrainID) {
469 collideeLocalID = BSScene.TERRAIN_ID;
473 CollidingStep = PhysScene.SimulationStep;
476 CollidingGroundStep = PhysScene.SimulationStep;
480 CollidingObjectStep = PhysScene.SimulationStep;
483 CollisionAccumulation++;
488 ColliderIsMoving = collidee != null ? (collidee.RawVelocity != OMV.Vector3.Zero || collidee.RotationalVelocity != OMV.Vector3.Zero) :
false;
489 ColliderIsVolumeDetect = collidee != null ? (collidee.IsVolumeDetect) :
false;
494 if (CollisionsLastTickStep != PhysScene.SimulationStep)
497 CollisionsLastTickStep = PhysScene.SimulationStep;
499 CollisionsLastTick.AddCollider(collideeLocalID,
new ContactPoint(contactPoint, contactNormal, pentrationDepth));
502 if (SubscribedEvents()) {
506 OMV.Vector3 relvel = OMV.Vector3.Zero;
508 relvel = RawVelocity;
510 relvel -= collidee.RawVelocity;
511 newContact.RelativeSpeed = OMV.Vector3.Dot(relvel, contactNormal);
515 lock (PhysScene.CollisionLock)
517 CollisionCollection.AddCollider(collideeLocalID, newContact);
519 DetailLog(
"{0},{1}.Collision.AddCollider,call,with={2},point={3},normal={4},depth={5},speed={6},colliderMoving={7}",
520 LocalID, TypeName, collideeLocalID, contactPoint, contactNormal, pentrationDepth,
539 bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0);
542 if (force || (PhysScene.SimulationNowTime >= NextCollisionOkTime))
544 NextCollisionOkTime = PhysScene.SimulationNowTime + SubscribedEventsMs;
548 if (CollisionCollection.Count == 0)
554 DetailLog(
"{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count);
555 base.SendCollisionUpdate(CollisionCollection);
558 CollisionsLastReported = CollisionCollection;
573 SubscribedEventsMs = ms;
577 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);
579 PhysScene.TaintedObject(LocalID, TypeName+
".SubscribeEvents", delegate()
581 if (PhysBody.HasPhysicalBody)
583 CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
584 DetailLog(
"{0},{1}.SubscribeEvents,setting collision. ms={2}, collisionFlags={3:x}",
585 LocalID, TypeName, ms, CurrentCollisionFlags);
597 SubscribedEventsMs = 0;
598 PhysScene.TaintedObject(LocalID, TypeName+
".UnSubscribeEvents", delegate()
601 if (PhysBody.HasPhysicalBody)
602 CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
607 return (SubscribedEventsMs > 0);
616 long timeAgo = PhysScene.SimulationStep - CollidingStep + 1;
617 CollisionScore = CollisionAccumulation / timeAgo;
619 public override float CollisionScore {
get; set; }
621 #endregion // Collisions
623 #region Per Simulation Step actions
633 PreUpdatePropertyAction actions = OnPreUpdateProperty;
635 actions(ref entprop);
638 #endregion // Per Simulation Step actions
641 protected void DetailLog(
string msg, params Object[] args)
643 if (PhysScene.PhysicsLogging.Enabled)
644 PhysScene.DetailLog(msg, args);
OMV.Vector3 LockedLinearAxisHigh
void DetailLog(string msg, params Object[] args)
bool ColliderIsVolumeDetect
void ActivateIfPhysical(bool forceIt)
override void AddAngularForce(OMV.Vector3 force, bool pushforce)
override void UnSubscribeEvents()
override void SubscribeEvents(int ms)
OMV.Vector3 LockedAngularAxisHigh
Each physical object can have 'actors' who are pushing the object around. This can be used for hover...
OMV.Vector3 LockedLinearAxisLow
OMV.Vector3 LockedAngularAxis
void TriggerPreUpdatePropertyAction(ref EntityProperties entprop)
virtual bool AssetFailed()
Used to pass collision information to OnCollisionUpdate listeners.
OMV.Vector3 LockedAngularAxisLow
override bool SubscribedEvents()
void EnableActor(bool enableActor, string actorName, CreateActor creator)
virtual bool ForceBodyShapeRebuild(bool inTaintTime)
override void SetMaterial(int material)
void ComputeCollisionScore()
virtual bool SendCollisions()
virtual bool Collide(BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
Material
Material type for a primitive
BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
OMV.Vector3 LockedLinearAxis
PreUpdatePropertyAction OnPreUpdateProperty