示例#1
0
 public override void linkGroupToThis(PhysicsActor[] objs)
 {
     for(int i = 0 ; i < objs.Length; i++)
         _parent_scene.AddSimulationChange(() => ((AuroraODEPrim) objs[i]).changelink(this));
 }
 public abstract void RemoveAvatar(PhysicsActor actor);
示例#3
0
 public void GetContactParam(PhysicsActor actor, ref d.Contact contact)
 {
     int vehicleType = 0;
     if ((_parent != null && (vehicleType = _parent.VehicleType) != (int) Vehicle.TYPE_NONE) ||
         (vehicleType = VehicleType) != (int) Vehicle.TYPE_NONE ||
         (actor is AuroraODEPrim && ((AuroraODEPrim) actor).Parent != null &&
          (vehicleType = ((AuroraODEPrim) actor).Parent.VehicleType) != (int) Vehicle.TYPE_NONE) ||
         (actor is AuroraODEPrim &&
          (vehicleType = ((AuroraODEPrim) actor).VehicleType) != (int) Vehicle.TYPE_NONE))
     {
         if (vehicleType == (int) Vehicle.TYPE_CAR)
         {
             contact.surface.bounce = 0;
             contact.surface.bounce_vel = 0;
             contact.surface.mu = 2;
         }
         else if (vehicleType == (int) Vehicle.TYPE_SLED)
         {
             contact.surface.bounce = 0;
             contact.surface.bounce_vel = 0;
             contact.surface.mu = 0;
         }
         else if (vehicleType == (int) Vehicle.TYPE_AIRPLANE ||
                  vehicleType == (int) Vehicle.TYPE_BALLOON ||
                  vehicleType == (int) Vehicle.TYPE_BOAT)
         {
             contact.surface.bounce = 0;
             contact.surface.bounce_vel = 0;
             contact.surface.mu = 100;
         }
     }
     else
     {
         float restSquared = Restitution*Restitution*Restitution;
         float maxVel = Velocity.Z < -1f ? -1f : Velocity.Z > 1f ? 1f : Velocity.Z;
         contact.surface.bounce = (maxVel*-(restSquared));
             //Its about 1:1 surprisingly, even though this constant was for havok
         if (contact.surface.bounce > 0.5f)
             contact.surface.bounce = 0.5f; //Limit the bouncing please...
         if (contact.surface.bounce <= 0)
         {
             contact.surface.bounce = 0;
             contact.surface.bounce_vel = 0;
         }
         else
             contact.surface.bounce_vel = 0.01f*restSquared*(-maxVel*restSquared);
                 //give it a good amount of bounce and have it depend on how much velocity is there too
         contact.surface.mu = 800;
         if (contact.surface.bounce_vel != 0)
             contact.surface.mode |= d.ContactFlags.Bounce;
         else
             contact.surface.mode &= d.ContactFlags.Bounce;
         if (actor.PhysicsActorType == (int) ActorTypes.Prim)
             contact.surface.mu *= Friction;
         else if (actor.PhysicsActorType == (int) ActorTypes.Ground)
             contact.surface.mu *= 2;
         else
             contact.surface.mu /= 2;
         if (m_vehicle.Type != Vehicle.TYPE_NONE && actor.PhysicsActorType != (int) ActorTypes.Agent)
             contact.surface.mu *= 0.05f;
     }
 }
 public override void DeletePrim(PhysicsActor prim)
 {
 }
 public override void RemovePrim(PhysicsActor prim)
 {
 }
        public override void link(PhysicsActor obj)
        {
            BSPrimLinkable parent = obj as BSPrimLinkable;
            if (parent != null)
            {
            BSPhysObject parentBefore = Linkset.LinksetRoot;
            int childrenBefore = Linkset.NumberOfChildren;

            Linkset = parent.Linkset.AddMeToLinkset(this);

            DetailLog("{0},BSPrimLinkset.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
                LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
            }
            return;
        }
示例#7
0
        public override void RemovePrim(PhysicsActor prim)
        {
            if (!m_initialized) return;

            BSPhysObject bsprim = prim as BSPhysObject;
            if (bsprim != null)
            {
            DetailLog("{0},RemovePrim,call", bsprim.LocalID);
            // MainConsole.Instance.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID);
            try
            {
                lock (PhysObjects) PhysObjects.Remove(bsprim.LocalID);
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("{0}: Attempt to remove prim that is not in physics scene: {1}", LogHeader, e);
            }
            bsprim.Destroy();
            // bsprim.dispose();
            }
            else
            {
            MainConsole.Instance.ErrorFormat("{0}: Attempt to remove prim that is not a BSPrim type.", LogHeader);
            }
        }
示例#8
0
 /// <summary>
 /// Removes an entire group from the physics scene
 /// </summary>
 /// <param name="prim"></param>
 public abstract void DeletePrim(PhysicsActor prim);
示例#9
0
 public override void RemoveAvatar(PhysicsActor actor)
 {
 }
示例#10
0
 public abstract void RemoveAvatar(PhysicsActor actor);
示例#11
0
 /// <summary>
 /// Removes a single prim from the group that it is in
 /// (or removes it entirely from the scene if it is as single prim)
 /// </summary>
 /// <param name="prim"></param>
 public abstract void RemovePrim(PhysicsActor prim);
示例#12
0
 public override void linkGroupToThis(PhysicsActor[] objs)
 {
 }
示例#13
0
 // link me to the specified parent
 public override void link(PhysicsActor obj)
 {
 }
        public override void linkGroupToThis(PhysicsActor[] objs)
        {
            Linkset.AddGroupToLinkset(objs.Cast<BSPrimLinkable>().ToArray());

            DetailLog("{0},BSPrimLinkset.linkGroupToThis,call, childrenAdded={1}, childrenAfter={2}",
            LocalID, objs.Length, Linkset.NumberOfChildren);
        }
示例#15
0
 public virtual void link(PhysicsActor obj) { }
示例#16
0
 public override void RemovePrim(PhysicsActor prim)
 {
 }
 /// <summary>
 ///     Removes physics plugin scene representation of this agent if it exists.
 /// </summary>
 public virtual void RemoveFromPhysicalScene()
 {
     try
     {
         if (PhysicsActor != null)
         {
             if (OnRemovePhysics != null)
                 OnRemovePhysics();
             if (m_physicsActor != null)
                 m_scene.PhysicsScene.RemoveAvatar(m_physicsActor);
             if (m_physicsActor != null)
                 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
             if (m_physicsActor != null)
                 m_physicsActor.OnRequestTerseUpdate -= SendPhysicsTerseUpdateToAllClients;
             if (m_physicsActor != null)
                 m_physicsActor.OnSignificantMovement -= CheckForSignificantMovement;
             if (m_physicsActor != null)
                 m_physicsActor.OnPositionAndVelocityUpdate -= PhysicsUpdatePosAndVelocity;
             if (m_physicsActor != null)
                 m_physicsActor.OnCheckForRegionCrossing -= CheckForBorderCrossing;
             if (m_physicsActor != null)
                 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
             if (m_physicsActor != null)
                 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
             m_physicsActor = null;
         }
     }
     catch
     {
     }
 }
示例#18
0
 public override void DeletePrim(PhysicsActor prim)
 {
 }
示例#19
0
        public override void RemoveAvatar(PhysicsActor actor)
        {
            // MainConsole.Instance.DebugFormat("{0}: RemoveAvatar", LogHeader);

            if (!m_initialized) return;

            BSCharacter bsactor = actor as BSCharacter;
            if (bsactor != null)
            {
            try
            {
                lock (PhysObjects)
                    PhysObjects.Remove(bsactor.LocalID);
                // Remove kludge someday
                lock (m_avatars)
                    m_avatars.Remove(bsactor);
            }
            catch (Exception e)
            {
                MainConsole.Instance.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}", LogHeader, e);
            }
            bsactor.Destroy();
            // bsactor.dispose();
            }
            else
            {
            MainConsole.Instance.ErrorFormat("{0}: Requested to remove avatar that is not a BSCharacter. ID={1}, type={2}",
                                        LogHeader, actor.LocalID, actor.GetType().Name);
            }
        }
示例#20
0
        private void AddODECollision(d.ContactGeom curContact, PhysicsActor p1, PhysicsActor p2, IntPtr b1, IntPtr b2,
            ContactPoint maxDepthContact, ref int NotSkipedCount)
        {
            IntPtr joint = IntPtr.Zero;

            bool p2col = true;

            // We only need to test p2 for 'jump crouch purposes'
            if (p2 is AuroraODECharacter && p1.PhysicsActorType == (int) ActorTypes.Prim)
            {
                // Testing if the collision is at the feet of the avatar
                if ((p2.Position.Z - maxDepthContact.Position.Z) < (p2.Size.Z*0.5f))
                    p2col = false;
            }

            p2.IsTruelyColliding = true;
            p2.IsColliding = p2col;

            // Logic for collision handling
            // Note, that if *all* contacts are skipped (VolumeDetect)
            // The prim still detects (and forwards) collision events but
            // appears to be phantom for the world

            // No collision on volume detect prims
            if ((p1 is AuroraODEPrim && p1.VolumeDetect) ||
                (p2 is AuroraODEPrim && p2.VolumeDetect))
                return;

            if (curContact.depth < 0f)
                return; //Has to be penetrating

            if (m_filterCollisions &&
                checkDupe(curContact, p2.PhysicsActorType))
                return;
            if (m_filterCollisions)
                _perloopContact.Add(curContact);

            NotSkipedCount++;

            // If we're colliding against terrain
            if (p1.PhysicsActorType == (int) ActorTypes.Ground)
            {
                if (p2.PhysicsActorType == (int) ActorTypes.Prim)
                {
                    ((AuroraODEPrim) p2).GetContactParam(p2, ref newGlobalcontact);

                    joint = CreateContacJoint(curContact);
                }
                else
                {
                    newGlobalcontact = new d.Contact();
                    newGlobalcontact.surface.mode |= d.ContactFlags.SoftERP;
                    newGlobalcontact.surface.mu = 75;
                    newGlobalcontact.surface.bounce = 0.1f;
                    newGlobalcontact.surface.soft_erp = 0.05025f;
                    //GetContactParam(0.0f, AvatarContactBounce, ref newGlobalcontact);
                    joint = CreateContacJoint(curContact);
                }
                //Can't collide against anything else, agents do their own ground checks
            }
            else if ((p1.PhysicsActorType == (int) ActorTypes.Agent) &&
                     (p2.PhysicsActorType == (int) ActorTypes.Agent))
            {
                GetContactParam(0.0f, AvatarContactBounce, ref newGlobalcontact);

                joint = CreateContacJoint(curContact);
            }
            else if (p1.PhysicsActorType == (int) ActorTypes.Prim)
            {
                //Add restitution and friction changes
                ((AuroraODEPrim) p1).GetContactParam(p2, ref newGlobalcontact);

                joint = CreateContacJoint(curContact);
            }

            if (m_global_contactcount < m_currentmaxContactsbeforedeath && joint != IntPtr.Zero)
            {
                d.JointAttach(joint, b1, b2);
                m_global_contactcount++;
                joint = IntPtr.Zero;
            }
        }
示例#21
0
 public override void RemoveAvatar(PhysicsActor actor)
 {
     BasicCharacterActor act = (BasicCharacterActor) actor;
     if (_actors.Contains(act))
     {
         _actors.Remove(act);
     }
 }
示例#22
0
 private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact)
 {
     if (!p2.SubscribedEvents() && !p1.SubscribedEvents())
         return;
     if (p1.SubscribedEvents())
         p1.AddCollisionEvent(p2.LocalID, contact);
     if (p2.SubscribedEvents())
         p2.AddCollisionEvent(p1.LocalID, contact);
 }
 public override void RemoveAvatar(PhysicsActor actor)
 {
 }
示例#24
0
 public void addCollisionEventReporting(PhysicsActor obj)
 {
     if (!_collisionEventDictionary.ContainsKey(obj.UUID))
         _collisionEventDictionary.TryAdd(obj.UUID, obj);
 }
 /// <summary>
 /// Removes an entire group from the physics scene
 /// </summary>
 /// <param name="prim"></param>
 public abstract void DeletePrim(PhysicsActor prim);
示例#26
0
 public void remCollisionEventReporting(PhysicsActor obj)
 {
     _collisionEventDictionary.TryRemove(obj.UUID, out obj);
 }
 /// <summary>
 /// Removes a single prim from the group that it is in 
 /// (or removes it entirely from the scene if it is as single prim)
 /// </summary>
 /// <param name="prim"></param>
 public abstract void RemovePrim(PhysicsActor prim);
示例#28
0
 public override void RemoveAvatar(PhysicsActor actor)
 {
     //MainConsole.Instance.Debug("[PHYSICS]:ODELOCK");
     ((AuroraODECharacter) actor).Destroy();
 }
示例#29
0
 public override void link(PhysicsActor obj)
 {
     _parent_scene.AddSimulationChange(() => changelink((AuroraODEPrim) obj));
 }
示例#30
0
 public override void RemovePrim(PhysicsActor prim)
 {
     //Add the prim to a queue which will be removed when Simulate has finished what it's doing.
     RemoveQueue.Enqueue(prim);
 }
示例#31
0
        private void changelink(AuroraODEPrim newparent)
        {
            // If the newly set parent is not null
            // create link
            if (_parent == null && newparent != null)
            {
                newparent.ParentPrim(this);
            }
                // If the newly set parent is null
                // destroy link
            else if (_parent != null)
            {
                if (_parent is AuroraODEPrim)
                {
                    if (newparent != _parent)
                    {
                        AuroraODEPrim obj = (AuroraODEPrim) _parent;
                        obj.ChildDelink(this);
                        childPrim = false;

                        if (newparent != null)
                        {
                            newparent.ParentPrim(this);
                        }
                    }
                }
            }

            _parent = newparent;
        }
示例#32
0
 public virtual void link(PhysicsActor obj)
 {
 }
示例#33
0
 public virtual void linkGroupToThis(PhysicsActor[] objs) { }
示例#34
0
        public override void DeletePrim(PhysicsActor prim)
        {
            BSPrimLinkable linkablePrim = prim as BSPrimLinkable;
            if (linkablePrim != null && linkablePrim.Linkset.HasAnyChildren)
            {
            linkablePrim.BlockPhysicalReconstruction = true;
            //Remove all the children prims first, then kill the root
            foreach (BSPrimLinkable childPrim in linkablePrim.Linkset.Children)
            {
                childPrim.BlockPhysicalReconstruction = true;
                RemovePrim(childPrim);
            }
            //TODO: DISABLE LINKSET REBUILDING DURING THIS PROCESS
            }

            RemovePrim(prim);
        }
        /// <summary>
        ///     Adds a physical representation of the avatar to the Physics plugin
        /// </summary>
        public virtual void AddToPhysicalScene(bool isFlying, bool AddAvHeightToPosition)
        {
            //Make sure we arn't already doing this
            if (m_creatingPhysicalRepresentation)
                return;

            //Set this so we don't do it multiple times
            m_creatingPhysicalRepresentation = true;

            Vector3 size = new Vector3(0, 0, m_defaultAvHeight);
            IAvatarAppearanceModule appearance = RequestModuleInterface<IAvatarAppearanceModule>();
            if (appearance != null)
                size.Z = appearance.Appearance.AvatarHeight;

            PhysicsScene scene = m_scene.PhysicsScene;

            Vector3 pVec = AbsolutePosition;

            if (AddAvHeightToPosition)
                //This is here so that after teleports, you arrive just slightly higher so that you don't fall through the ground/objects
                pVec.Z += size.Z;

            m_physicsActor = scene.AddAvatar(Name, pVec, Rotation, size, isFlying, LocalId, UUID);

            m_physicsActor.OnRequestTerseUpdate += SendPhysicsTerseUpdateToAllClients;
            m_physicsActor.OnSignificantMovement += CheckForSignificantMovement;
            m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
            m_physicsActor.OnPositionAndVelocityUpdate += PhysicsUpdatePosAndVelocity;
            m_physicsActor.OnCheckForRegionCrossing += CheckForBorderCrossing;

            m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
            m_physicsActor.Orientation = Rotation;

            m_physicsActor.Flying = isFlying;

            //Tell any events about it
            if (OnAddPhysics != null)
                OnAddPhysics();

            //All done, reset this
            m_creatingPhysicalRepresentation = false;
        }
        /// <summary>
        ///     Rebuild the physical representation of all the prims.
        ///     This is used after copying the prim so that all of the object is readded to the physics scene.
        /// </summary>
        public void RebuildPhysicalRepresentation(bool keepSelectedStatuses, Action actionWhileNoPhysActor)
        {
            // long lock or array copy?  in this case lets try array
            SceneObjectPart[] parts;
            SceneObjectPart part;
            int i;

            lock (m_partsLock)//Force the root to be deleted last
                parts = m_partsList.OrderBy((sop)=>-sop.LinkNum).ToArray();

            if (RootPart.PhysActor != null)
                RootPart.PhysActor.BlockPhysicalReconstruction = true;

            for (i = 0; i < parts.Length; i++)
            {
                part = parts[i];
                //                PhysicsObject oldActor = part.PhysActor;
                //                PrimitiveBaseShape pbs = part.Shape;
                if (part.PhysActor != null)
                {
                    part.PhysActor.RotationalVelocity = Vector3.Zero;
                    part.m_hasSubscribedToCollisionEvent = false;
                    part.PhysActor.OnRequestTerseUpdate -= part.PhysicsRequestingTerseUpdate;
                    part.PhysActor.OnSignificantMovement -= part.ParentGroup.CheckForSignificantMovement;
                    part.PhysActor.OnOutOfBounds -= part.PhysicsOutOfBounds;

                    //part.PhysActor.delink ();
                    //Remove the old one so that we don't have more than we should,
                    //  as when we copy, it readds it to the PhysicsScene somehow
                    //if (part.IsRoot)//The root removes all children
                    m_scene.PhysicsScene.RemovePrim(part.PhysActor);
                    part.FireOnRemovedPhysics();
                    part.PhysActor = null;
                }
                //Reset any old data that we have
                part.Velocity = Vector3.Zero;
                part.AngularVelocity = Vector3.Zero;
                part.Acceleration = Vector3.Zero;
                part.GenerateRotationalVelocityFromOmega();
            }

            if(actionWhileNoPhysActor != null)
                actionWhileNoPhysActor();

            //Check for meshes and stuff
            CheckSculptAndLoad();

            // check root part setting that make the entire object not having physics rep

            if (RootPart.PhysicsType == (byte)PhysicsShapeType.None ||
                ((RootPart.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !RootPart.VolumeDetectActive))
            {
                Scene.AuroraEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this);
                if (OnFinishedPhysicalRepresentationBuilding != null)
                    OnFinishedPhysicalRepresentationBuilding();
                OnFinishedPhysicalRepresentationBuilding = null;
                return;
            }

            // create the root part
            bool isPhysical = ((RootPart.Flags & PrimFlags.Physics) != 0);
            bool isPhantom = ((RootPart.Flags & PrimFlags.Phantom) != 0);
            bool physical = isPhysical & !isPhantom;

            RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape(RootPart.UUID, RootPart.LocalId, RootPart.Name, RootPart.PhysicsType,
                RootPart.Shape, RootPart.AbsolutePosition, RootPart.Scale, RootPart.GetWorldRotation(), physical, RootPart.Material,
                RootPart.Friction, RootPart.Restitution, RootPart.GravityMultiplier, RootPart.Density);
            if (RootPart.PhysActor == null)
                return;
            //Don't let it rebuild it until we have all the links done

            RootPart.PhysActor.VolumeDetect = RootPart.VolumeDetectActive;

            //Add collision updates
            //part.PhysActor.OnCollisionUpdate += RootPart.PhysicsCollision;
            RootPart.PhysActor.OnRequestTerseUpdate += RootPart.PhysicsRequestingTerseUpdate;
            RootPart.PhysActor.OnSignificantMovement += RootPart.ParentGroup.CheckForSignificantMovement;
            RootPart.PhysActor.OnOutOfBounds += RootPart.PhysicsOutOfBounds;

            RootPart.FireOnAddedPhysics();
            RootPart.aggregateScriptEvents();

            PhysicsActor[] actors = new PhysicsActor[parts.Length - 1];
            for (i = 0; i < parts.Length; i++)
            {
                part = parts[i];
                if (part == RootPart ||
                    part.PhysicsType == (byte)PhysicsShapeType.None ||
                    ((part.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !part.VolumeDetectActive))
                {
                    continue; // ignore phantom prims
                }

                //Now read the physics actor to the physics scene
                isPhysical = ((part.ParentEntity.RootChild.Flags & PrimFlags.Physics) != 0);
                isPhantom = ((part.ParentEntity.RootChild.Flags & PrimFlags.Phantom) != 0);
                physical = isPhysical & !isPhantom;

                part.PhysActor = m_scene.PhysicsScene.AddPrimShape(part.UUID, part.LocalId, part.Name, RootPart.PhysicsType,
                    part.Shape, part.AbsolutePosition, part.Scale, part.GetWorldRotation(), physical, part.Material,
                    part.Friction, part.Restitution, part.GravityMultiplier, part.Density);
                if (part.PhysActor == null)
                    continue;
                //                    part.PhysActor.BuildingRepresentation = true;
                //                    if(part.IsRoot)
                //Don't let it rebuild it until we have all the links done

                part.PhysActor.VolumeDetect = part.VolumeDetectActive;

                //Add collision updates
                part.PhysActor.OnRequestTerseUpdate += part.PhysicsRequestingTerseUpdate;
                part.PhysActor.OnSignificantMovement += part.ParentGroup.CheckForSignificantMovement;
                part.PhysActor.OnOutOfBounds += part.PhysicsOutOfBounds;

                part.FireOnAddedPhysics();
                part.aggregateScriptEvents();
                actors[i] = part.PhysActor;

                if(!m_scene.PhysicsScene.AllowGroupLink)
                    part.PhysActor.link(RootPart.PhysActor);
            }
            if (m_scene.PhysicsScene.AllowGroupLink)
                RootPart.PhysActor.linkGroupToThis(actors);

            Scene.AuroraEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this);

            FixVehicleParams(RootPart);

            /*if (physical != RootPart.PhysActor.IsPhysical)
            {
                RootPart.PhysActor.IsPhysical = physical;
                foreach (SceneObjectPart p in parts)
                {
                    if(!p.IsRoot)
                        p.PhysActor.IsPhysical = physical;
                }
            }*/

            //Force deselection here so that it isn't stuck forever
            IsSelected = keepSelectedStatuses && IsSelected;

            if (OnFinishedPhysicalRepresentationBuilding != null)
                OnFinishedPhysicalRepresentationBuilding();
            OnFinishedPhysicalRepresentationBuilding = null;
        }