コード例 #1
0
        public override void AddForce(bool inTaintTime, OMV.Vector3 force)
        {
            if (force.IsFinite())
            {
                OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude);
                // DetailLog("{0},BSCharacter.addForce,call,force={1},push={2},inTaint={3}", LocalID, addForce, pushforce, inTaintTime);

                PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.AddForce", delegate()
                {
                    // Bullet adds this central force to the total force for this tick
                    // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
                    if (PhysBody.HasPhysicalBody)
                    {
                        // Bullet adds this central force to the total force for this tick.
                        // Deep down in Bullet:
                        //      linearVelocity += totalForce / mass * timeStep;
                        PhysScene.PE.ApplyCentralForce(PhysBody, addForce);
                        PhysScene.PE.Activate(PhysBody, true);
                    }
                    if (m_moveActor != null)
                    {
                        m_moveActor.SuppressStationayCheckUntilLowVelocity();
                    }
                });
            }
            else
            {
                m_log.WarnFormat("{0}: Got a NaN force applied to a character. LocalID={1}", LogHeader, LocalID);
                return;
            }
        }
コード例 #2
0
        // Internal version that, if initializing, doesn't do all the updating of the physics engine
        public void SetAvatarSize(OMV.Vector3 size, float feetOffset, bool initializing)
        {
            OMV.Vector3 newSize = size;
            if (newSize.IsFinite())
            {
                // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
                //     replace with the default values.
                if (newSize.X == 0f)
                {
                    newSize.X = BSParam.AvatarCapsuleDepth;
                }
                if (newSize.Y == 0f)
                {
                    newSize.Y = BSParam.AvatarCapsuleWidth;
                }

                if (newSize.X < 0.01f)
                {
                    newSize.X = 0.01f;
                }
                if (newSize.Y < 0.01f)
                {
                    newSize.Y = 0.01f;
                }
                if (newSize.Z < 0.01f)
                {
                    newSize.Z = BSParam.AvatarCapsuleHeight;
                }
            }
            else
            {
                newSize = new OMV.Vector3(BSParam.AvatarCapsuleDepth, BSParam.AvatarCapsuleWidth, BSParam.AvatarCapsuleHeight);
            }

            // This is how much the avatar size is changing. Positive means getting bigger.
            // The avatar altitude must be adjusted for this change.
            float heightChange = newSize.Z - Size.Z;

            _size = newSize;

            Scale = ComputeAvatarScale(Size);
            ComputeAvatarVolumeAndMass();
            DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
                      LocalID, _size, Scale, Density, _avatarVolume, RawMass);

            PhysScene.TaintedObject(LocalID, "BSCharacter.setSize", delegate()
            {
                if (PhysBody.HasPhysicalBody && PhysShape.physShapeInfo.HasPhysicalShape)
                {
                    PhysScene.PE.SetLocalScaling(PhysShape.physShapeInfo, Scale);
                    UpdatePhysicalMassProperties(RawMass, true);

                    // Adjust the avatar's position to account for the increase/decrease in size
                    ForcePosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, RawPosition.Z + heightChange / 2f);

                    // Make sure this change appears as a property update event
                    PhysScene.PE.PushUpdate(PhysBody);
                }
            });
        }
コード例 #3
0
ファイル: BSPhysObject.cs プロジェクト: osCore2/osCore2-1
        // Subscribe for collision events.
        // Parameter is the millisecond rate the caller wishes collision events to occur.
        public override void SubscribeEvents(int ms)
        {
            // DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms);
            SubscribedEventsMs = ms;
            if (ms > 0)
            {
                // make sure first collision happens
                NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);

                PhysScene.TaintedObject(LocalID, TypeName + ".SubscribeEvents", delegate()
                {
                    if (PhysBody.HasPhysicalBody)
                    {
                        CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
                        DetailLog("{0},{1}.SubscribeEvents,setting collision. ms={2}, collisionFlags={3:x}",
                                  LocalID, TypeName, SubscribedEventsMs, CurrentCollisionFlags);
                    }
                });
            }
            else
            {
                // Subscribing for zero or less is the same as unsubscribing
                UnSubscribeEvents();
            }
        }
コード例 #4
0
 // Tell the object to clean up.
 public virtual void Destroy()
 {
     PhysicalActors.Enable(false);
     PhysScene.TaintedObject(LocalID, "BSPhysObject.Destroy", delegate()
     {
         PhysicalActors.Dispose();
     });
 }
コード例 #5
0
ファイル: BSCharacter.cs プロジェクト: zhanmusi/opensim
        public BSCharacter(
            uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, bool isFlying)

            : base(parent_scene, localID, avName, "BSCharacter")
        {
            _physicsActorType = (int)ActorTypes.Agent;
            RawPosition       = pos;

            _flying        = isFlying;
            RawOrientation = OMV.Quaternion.Identity;
            RawVelocity    = vel;
            _buoyancy      = ComputeBuoyancyFromFlying(isFlying);
            Friction       = BSParam.AvatarStandingFriction;
            Density        = BSParam.AvatarDensity;

            // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
            //     replace with the default values.
            _size = size;
            if (_size.X == 0f)
            {
                _size.X = BSParam.AvatarCapsuleDepth;
            }
            if (_size.Y == 0f)
            {
                _size.Y = BSParam.AvatarCapsuleWidth;
            }

            // The dimensions of the physical capsule are kept in the scale.
            // Physics creates a unit capsule which is scaled by the physics engine.
            Scale = ComputeAvatarScale(_size);
            // set _avatarVolume and _mass based on capsule size, _density and Scale
            ComputeAvatarVolumeAndMass();

            DetailLog(
                "{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6},vel={7}",
                LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos, vel);

            // do actual creation in taint time
            PhysScene.TaintedObject(LocalID, "BSCharacter.create", delegate()
            {
                DetailLog("{0},BSCharacter.create,taint", LocalID);

                // New body and shape into PhysBody and PhysShape
                PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this);

                // The avatar's movement is controlled by this motor that speeds up and slows down
                //    the avatar seeking to reach the motor's target speed.
                // This motor runs as a prestep action for the avatar so it will keep the avatar
                //    standing as well as moving. Destruction of the avatar will destroy the pre-step action.
                m_moveActor = new BSActorAvatarMove(PhysScene, this, AvatarMoveActorName);
                PhysicalActors.Add(AvatarMoveActorName, m_moveActor);

                SetPhysicalProperties();

                IsInitialized = true;
            });
            return;
        }
コード例 #6
0
        public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
                              OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
            : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical)
        {
            Linkset = BSLinkset.Factory(PhysScene, this);

            PhysScene.TaintedObject("BSPrimLinksetCompound.Refresh", delegate()
            {
                Linkset.Refresh(this);
            });
        }
コード例 #7
0
 public override void UnSubscribeEvents()
 {
     // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName);
     SubscribedEventsMs = 0;
     PhysScene.TaintedObject(LocalID, TypeName + ".UnSubscribeEvents", delegate()
     {
         // Make sure there is a body there because sometimes destruction happens in an un-ideal order.
         if (PhysBody.HasPhysicalBody)
         {
             CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
         }
     });
 }
コード例 #8
0
        // called when this character is being destroyed and the resources should be released
        public override void Destroy()
        {
            base.Destroy();

            DetailLog("{0},BSCharacter.Destroy", LocalID);
            PhysScene.TaintedObject("BSCharacter.destroy", delegate()
            {
                PhysScene.Shapes.DereferenceBody(PhysBody, null /* bodyCallback */);
                PhysBody.Clear();
                PhysShape.Dereference(PhysScene);
                PhysShape = new BSShapeNull();
            });
        }
コード例 #9
0
        public override void ZeroAngularMotion(bool inTaintTime)
        {
            _rotationalVelocity = OMV.Vector3.Zero;

            PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate()
            {
                if (PhysBody.HasPhysicalBody)
                {
                    PhysScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero);
                    PhysScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero);
                    // The next also get rid of applied linear force but the linear velocity is untouched.
                    PhysScene.PE.ClearForces(PhysBody);
                }
            });
        }
コード例 #10
0
        // Set motion values to zero.
        // Do it to the properties so the values get set in the physics engine.
        // Push the setting of the values to the viewer.
        // Called at taint time!
        public override void ZeroMotion(bool inTaintTime)
        {
            RawVelocity         = OMV.Vector3.Zero;
            _acceleration       = OMV.Vector3.Zero;
            _rotationalVelocity = OMV.Vector3.Zero;

            // Zero some other properties directly into the physics engine
            PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate()
            {
                if (PhysBody.HasPhysicalBody)
                {
                    PhysScene.PE.ClearAllForces(PhysBody);
                }
            });
        }
コード例 #11
0
        // A version of the sanity check that also makes sure a new position value is
        //    pushed back to the physics engine. This routine would be used by anyone
        //    who is not already pushing the value.
        private bool PositionSanityCheck(bool inTaintTime)
        {
            bool ret = false;

            if (PositionSanityCheck())
            {
                // The new position value must be pushed into the physics engine but we can't
                //    just assign to "Position" because of potential call loops.
                PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.PositionSanityCheck", delegate()
                {
                    DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
                    ForcePosition = RawPosition;
                });
                ret = true;
            }
            return(ret);
        }
コード例 #12
0
        public BSCharacter(
            uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, float footOffset, bool isFlying)

            : base(parent_scene, localID, avName, "BSCharacter")
        {
            _physicsActorType = (int)ActorTypes.Agent;
            RawPosition       = pos;

            _flying        = isFlying;
            RawOrientation = OMV.Quaternion.Identity;
            RawVelocity    = vel;
            _buoyancy      = ComputeBuoyancyFromFlying(isFlying);
            Friction       = BSParam.AvatarStandingFriction;
            Density        = BSParam.AvatarDensity;
            _isPhysical    = true;

            _footOffset = footOffset;
            // Adjustments for zero X and Y made in Size()
            // This also computes avatar scale, volume, and mass
            SetAvatarSize(size, footOffset, true /* initializing */);

            DetailLog(
                "{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6},vel={7}",
                LocalID, Size, Scale, Density, _avatarVolume, RawMass, pos, vel);

            // do actual creation in taint time
            PhysScene.TaintedObject(LocalID, "BSCharacter.create", delegate()
            {
                DetailLog("{0},BSCharacter.create,taint", LocalID);

                // New body and shape into PhysBody and PhysShape
                PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this);

                // The avatar's movement is controlled by this motor that speeds up and slows down
                //    the avatar seeking to reach the motor's target speed.
                // This motor runs as a prestep action for the avatar so it will keep the avatar
                //    standing as well as moving. Destruction of the avatar will destroy the pre-step action.
                m_moveActor = new BSActorAvatarMove(PhysScene, this, AvatarMoveActorName);
                PhysicalActors.Add(AvatarMoveActorName, m_moveActor);

                SetPhysicalProperties();

                IsInitialized = true;
            });
            return;
        }
コード例 #13
0
        public override void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime)
        {
            if (force.IsFinite())
            {
                OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude);
                // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce);

                PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.AddForce", delegate()
                {
                    // Bullet adds this central force to the total force for this tick
                    // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
                    if (PhysBody.HasPhysicalBody)
                    {
                        PhysScene.PE.ApplyCentralForce(PhysBody, addForce);
                    }
                });
            }
            else
            {
                m_log.WarnFormat("{0}: Got a NaN force applied to a character. LocalID={1}", LogHeader, LocalID);
                return;
            }
        }
コード例 #14
0
        public override object Extension(string pFunct, params object[] pParams)
        {
            DetailLog("{0} BSPrimLinkable.Extension,op={1},nParam={2}", LocalID, pFunct, pParams.Length);
            object ret = null;

            switch (pFunct)
            {
            // physGetLinksetType();
            // pParams = [ BSPhysObject root, null ]
            case ExtendedPhysics.PhysFunctGetLinksetType:
            {
                ret = (object)LinksetType;
                DetailLog("{0},BSPrimLinkable.Extension.physGetLinksetType,type={1}", LocalID, ret);
                break;
            }

            // physSetLinksetType(type);
            // pParams = [ BSPhysObject root, null, integer type ]
            case ExtendedPhysics.PhysFunctSetLinksetType:
            {
                if (pParams.Length > 2)
                {
                    BSLinkset.LinksetImplementation linksetType = (BSLinkset.LinksetImplementation)pParams[2];
                    if (Linkset.IsRoot(this))
                    {
                        PhysScene.TaintedObject(LocalID, "BSPrim.PhysFunctSetLinksetType", delegate()
                            {
                                // Cause the linkset type to change
                                DetailLog("{0},BSPrimLinkable.Extension.physSetLinksetType, oldType={1},newType={2}",
                                          LocalID, Linkset.LinksetImpl, linksetType);
                                ConvertLinkset(linksetType);
                            });
                    }
                    ret = (object)(int)linksetType;
                }
                break;
            }

            // physChangeLinkType(linknum, typeCode);
            // pParams = [ BSPhysObject root, BSPhysObject child, integer linkType ]
            case ExtendedPhysics.PhysFunctChangeLinkType:
            {
                ret = Linkset.Extension(pFunct, pParams);
                break;
            }

            // physGetLinkType(linknum);
            // pParams = [ BSPhysObject root, BSPhysObject child ]
            case ExtendedPhysics.PhysFunctGetLinkType:
            {
                ret = Linkset.Extension(pFunct, pParams);
                break;
            }

            // physChangeLinkParams(linknum, [code, value, code, value, ...]);
            // pParams = [ BSPhysObject root, BSPhysObject child, object[] [ string op, object opParam, string op, object opParam, ... ] ]
            case ExtendedPhysics.PhysFunctChangeLinkParams:
            {
                ret = Linkset.Extension(pFunct, pParams);
                break;
            }

            default:
                ret = base.Extension(pFunct, pParams);
                break;
            }
            return(ret);
        }