Пример #1
0
 public void EnableActor(bool enableActor, string actorName, CreateActor creator)
 {
     lock (PhysicalActors)
     {
         BSActor theActor;
         if (PhysicalActors.TryGetActor(actorName, out theActor))
         {
             // The actor already exists so just turn it on or off
             DetailLog("{0},BSPhysObject.EnableActor,enablingExistingActor,name={1},enable={2}", LocalID, actorName, enableActor);
             theActor.Enabled = enableActor;
         }
         else
         {
             // The actor does not exist. If it should, create it.
             if (enableActor)
             {
                 DetailLog("{0},BSPhysObject.EnableActor,creatingActor,name={1}", LocalID, actorName);
                 theActor = creator();
                 PhysicalActors.Add(actorName, theActor);
                 theActor.Enabled = true;
             }
             else
             {
                 DetailLog("{0},BSPhysObject.EnableActor,notCreatingActorSinceNotEnabled,name={1}", LocalID, actorName);
             }
         }
     }
 }
Пример #2
0
 // Tell the object to clean up.
 public virtual void Destroy()
 {
     PhysicalActors.Enable(false);
     PhysScene.TaintedObject(LocalID, "BSPhysObject.Destroy", delegate()
     {
         PhysicalActors.Dispose();
     });
 }
Пример #3
0
        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;
        }
Пример #4
0
        private void SetPhysicalProperties()
        {
            PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody);

            ForcePosition = RawPosition;

            // Set the velocity
            if (m_moveActor != null)
            {
                m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false);
            }

            ForceVelocity  = RawVelocity;
            TargetVelocity = RawVelocity;

            // This will enable or disable the flying buoyancy of the avatar.
            // Needs to be reset especially when an avatar is recreated after crossing a region boundry.
            Flying = _flying;

            PhysScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution);
            PhysScene.PE.SetMargin(PhysShape.physShapeInfo, PhysScene.Params.collisionMargin);
            PhysScene.PE.SetLocalScaling(PhysShape.physShapeInfo, Scale);
            PhysScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
            if (BSParam.CcdMotionThreshold > 0f)
            {
                PhysScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
                PhysScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
            }

            UpdatePhysicalMassProperties(RawMass, false);

            // Make so capsule does not fall over
            PhysScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero);

            // The avatar mover sets some parameters.
            PhysicalActors.Refresh();

            PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT);

            PhysScene.PE.AddObjectToWorld(PhysScene.World, PhysBody);

            // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
            PhysScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION);
            PhysScene.PE.UpdateSingleAabb(PhysScene.World, PhysBody);

            // Do this after the object has been added to the world
            if (BSParam.AvatarToAvatarCollisionsByDefault)
            {
                PhysBody.collisionType = CollisionType.Avatar;
            }
            else
            {
                PhysBody.collisionType = CollisionType.PhantomToOthersAvatar;
            }

            PhysBody.ApplyCollisionMask(PhysScene);
        }
Пример #5
0
        protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
        {
            IsInitialized = false;

            PhysScene      = parentScene;
            LocalID        = localID;
            PhysObjectName = name;
            Name           = name; // PhysicsActor also has the name of the object. Someday consolidate.
            TypeName       = typeName;

            // Oddity if object is destroyed and recreated very quickly it could still have the old body.
            if (!PhysBody.HasPhysicalBody)
            {
                PhysBody = new BulletBody(localID);
            }

            // Clean out anything that might be in the physical actor list.
            // Again, a workaround for destroying and recreating an object very quickly.
            PhysicalActors.Dispose();

            UserSetCenterOfMassDisplacement = null;

            PrimAssetState = PrimAssetCondition.Unknown;

            // Initialize variables kept in base.
            // Beware that these cause taints to be queued whch can cause race conditions on startup.
            GravModifier = 1.0f;
            Gravity      = new OMV.Vector3(0f, 0f, BSParam.Gravity);
            HoverActive  = false;

            // Default material type. Also sets Friction, Restitution and Density.
            SetMaterial((int)MaterialAttributes.Material.Wood);

            CollisionsLastTickStep = -1;

            SubscribedEventsMs = 0;
            // Crazy values that will never be true
            CollidingStep         = BSScene.NotASimulationStep;
            CollidingGroundStep   = BSScene.NotASimulationStep;
            CollisionAccumulation = BSScene.NotASimulationStep;
            ColliderIsMoving      = false;
            CollisionScore        = 0;

            // All axis free.
            LockedLinearAxis  = LockedAxisFree;
            LockedAngularAxis = LockedAxisFree;
        }
Пример #6
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;
        }
 public void EnableActor(bool enableActor, string actorName, CreateActor creator)
 {
     lock (PhysicalActors)
     {
         BSActor theActor;
         if (PhysicalActors.TryGetActor(actorName, out theActor))
         {
             // The actor already exists so just turn it on or off
             theActor.Enabled = enableActor;
         }
         else
         {
             // The actor does not exist. If it should, create it.
             if (enableActor)
             {
                 theActor = creator();
                 PhysicalActors.Add(actorName, theActor);
                 theActor.Enabled = true;
             }
         }
     }
 }