Ejemplo n.º 1
0
        public void Kill()
        {
            PhysicsQB physicsQB = Stage.ActiveStage.GetQB<PhysicsQB>();
            if (characterController != null && characterController.Space != null)
            {
                physicsQB.RemoveFromSpace(characterController);
                characterController = null;
            }

            if (cylinderCharController != null && cylinderCharController.Space != null)
            {
                physicsQB.RemoveFromSpace(cylinderCharController);
                cylinderCharController = null;
            }

            if (spaceObject != null && spaceObject.Space != null)
            {
                physicsQB.RemoveFromSpace(spaceObject);
                spaceObject = null;
            }
        }
Ejemplo n.º 2
0
 public void AddOject(ISpaceObject entity, GameObject gameObject)
 {
     entity.Tag = gameObject;
     space.Add(entity);
 }
 public void AddPhysicsObject(ISpaceObject spaceObject)
 {
     space.Add(spaceObject);
 }
Ejemplo n.º 4
0
 ///<summary>
 /// Adds a space object to the buffer.
 /// It will be added to the space the next time the buffer is flushed.
 ///</summary>
 ///<param name="spaceObject">Space object to add.</param>
 public void Add(ISpaceObject spaceObject)
 {
     objectsToChange.Enqueue(new SpaceObjectChange(spaceObject, true));
 }
Ejemplo n.º 5
0
 public SpaceObjectChange(ISpaceObject spaceObject, bool shouldAdd)
 {
     SpaceObject = spaceObject;
     ShouldAdd = shouldAdd;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Spawns a physical object into the physics world.
 /// One entity per physics object only!
 /// </summary>
 /// <param name="ent">The controlling entity.</param>
 /// <param name="bepuent">The BEPU object.</param>
 public void Spawn(T ent, ISpaceObject bepuent)
 {
     Internal.Add(bepuent);
     SpawnedEntities.Add(ent);
 }
Ejemplo n.º 7
0
        public void AddToSpace(ISpaceObject spaceObject)
        {
            space.Add(spaceObject);

            #if DEBUG
            if (debugDrawEnabled)
            {
                Renderer.Instance.collisionDebugDrawer.Add(spaceObject);
            }
            #endif
        }
Ejemplo n.º 8
0
        private static bool IsWantedTargetForRandomTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, ISpaceObject obj)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return(false);
            }
            if (type == AiTargetType.NPC && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return(false);
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return(false);
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return(false);
                }
                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (CanSee(srcObj, target))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
 public override void Place(ISpaceObject target)
 {
     Utility.Extensions.CommonExtensions.Place(this, target);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Checks for a specific visibility level of a space object for an empire.
        /// If the object has that level of visibility or higher, we return true.
        /// </summary>
        /// <remarks>
        /// This allows us to short circuit the more expensive scanner code.
        /// See also parallel code at <see cref="CheckSpaceObjectVisibility(ISpaceObject, Empire)"/>
        /// </remarks>
        /// <param name="sobj">The space object to check.</param>
        /// <param name="emp">The empire to check against.</param>
        /// <param name="desiredVisibility">The requested visibility level.</param>
        /// <returns>true if the space object has at least the requested visibility level, otherwise false.</returns>
        public static bool HasVisibility(this ISpaceObject sobj, Empire emp, Visibility desiredVisibility)
        {
            bool hasMemory = false;

            if (sobj.IsMemory)
            {
                var mowner = sobj.MemoryOwner();
                if (mowner == emp || mowner == null)
                {
                    return(Visibility.Fogged >= desiredVisibility);
                }
                else
                {
                    return(Visibility.Unknown >= desiredVisibility);                    // can't see other players' memories
                }
            }
            else
            {
                var mem = sobj.FindMemory(emp);
                if (mem != null)
                {
                    hasMemory = true;
                }
            }

            if (emp == sobj.Owner)
            {
                return(Visibility.Owned >= desiredVisibility);
            }

            // You can always scan space objects you are in combat with.
            // But only their state at the time they were in combat; not for the rest of the turn!
            // TODO - what about glassed planets, they have no owner...
            if (Galaxy.Current.Battles.Any(b =>
                                           (b.Combatants.OfType <ISpaceObject>().Contains(sobj) ||
                                            b.StartCombatants.Values.OfType <ISpaceObject>().Contains(sobj) ||
                                            b.EndCombatants.Values.OfType <ISpaceObject>().Contains(sobj)) &&
                                           b.Combatants.Any(c => c.Owner == emp)))
            {
                return(Visibility.Scanned >= desiredVisibility);
            }

            // do we have anything that can see it?
            var sys = sobj.StarSystem;

            if (sys == null)
            {
                return(Visibility.Unknown >= desiredVisibility);
            }
            var seers = sys.FindSpaceObjects <ISpaceObject>(s => s.Owner == emp && !s.IsMemory);

            if (!seers.Any() || sobj.IsHiddenFrom(emp))
            {
                if (Galaxy.Current.OmniscientView && sobj.StarSystem.ExploredByEmpires.Contains(emp))
                {
                    return(Visibility.Visible >= desiredVisibility);
                }
                if (emp.AllSystemsExploredFromStart)
                {
                    return(Visibility.Fogged >= desiredVisibility);
                }
                var known = emp.Memory[sobj.ID];
                if (known != null && sobj.GetType() == known.GetType())
                {
                    return(Visibility.Fogged >= desiredVisibility);
                }
                else if (Galaxy.Current.Battles.Any(b => b.Combatants.Any(c => c.ID == sobj.ID) && b.Combatants.Any(c => c.Owner == emp)))
                {
                    return(Visibility.Fogged >= desiredVisibility);
                }
                else if (hasMemory)
                {
                    return(Visibility.Fogged >= desiredVisibility);
                }
                else
                {
                    return(Visibility.Unknown >= desiredVisibility);
                }
            }

            // short circuit scanner code: we now know that the object is either visible or scanned
            // so if we only care if it's visible or less, we can skip the scanner check.
            if (Visibility.Visible >= desiredVisibility)
            {
                return(true);
            }

            if (!sobj.HasAbility("Scanner Jammer"))
            {
                var scanners = seers.Where(s =>
                                           s.HasAbility("Long Range Scanner") && s.GetAbilityValue("Long Range Scanner").ToInt() >= s.Sector.Coordinates.EightWayDistance(sobj.FindSector().Coordinates) ||
                                           s.HasAbility("Long Range Scanner - System"));
                if (scanners.Any())
                {
                    return(Visibility.Scanned >= desiredVisibility);
                }
            }

            // we know that the requested visibility level is greater than "visible"
            // and the object has a scanner jammer
            // therefore it can't be scanned, and we already know it's not owned, we checked that up top
            // so we can just return false because the requested visibility (scanned or owned) can't be met
            return(false);
        }
Ejemplo n.º 11
0
        private static void StepCalcNearstTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, ISpaceObject obj, ref float minPowDist, ref CharacterInfo nearstTarget)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return;
            }
            if (type == AiTargetType.NPC && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return;
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return;
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return;
                }
                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (powDist < minPowDist)
                    {
                        if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target))
                        {
                            nearstTarget = target;
                            minPowDist   = powDist;
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Determines the level of visibility of a space object to an empire.
        /// <br/>
        /// If you only need to verify that a space object has at least a certain level of visibility,
        /// it is less expensive to call <see cref="HasVisibility(ISpaceObject, Empire, Visibility)"/>.
        /// </summary>
        /// <param name="sobj">The space object to check.</param>
        /// <param name="emp">The empire to check against.</param>
        /// <returns>The visibility level.</returns>
        internal static Visibility CheckSpaceObjectVisibility(this ISpaceObject sobj, Empire emp)
        {
            bool hasMemory = false;

            if (sobj.IsMemory)
            {
                var mowner = sobj.MemoryOwner();
                if (mowner == emp || mowner == null)
                {
                    return(Visibility.Fogged);
                }
                else
                {
                    return(Visibility.Unknown);                    // can't see other players' memories
                }
            }
            else
            {
                var mem = sobj.FindMemory(emp);
                if (mem != null)
                {
                    hasMemory = true;
                }
            }

            if (emp == sobj.Owner)
            {
                return(Visibility.Owned);
            }

            // You can always scan space objects you are in combat with.
            // But only their state at the time they were in combat; not for the rest of the turn!
            // TODO - what about glassed planets, they have no owner...
            if (Galaxy.Current.Battles.Any(b =>
                                           (b.Combatants.OfType <ISpaceObject>().Contains(sobj) ||
                                            b.StartCombatants.Values.OfType <ISpaceObject>().Contains(sobj) ||
                                            b.EndCombatants.Values.OfType <ISpaceObject>().Contains(sobj)) &&
                                           b.Combatants.Any(c => c.Owner == emp)))
            {
                return(Visibility.Scanned);
            }

            // do we have anything that can see it?
            var sys = sobj.StarSystem;

            if (sys == null)
            {
                return(Visibility.Unknown);
            }
            var seers = sys.FindSpaceObjects <ISpaceObject>(s => s.Owner == emp && !s.IsMemory);

            if (!seers.Any() || sobj.IsHiddenFrom(emp))
            {
                if (Galaxy.Current.OmniscientView && sobj.StarSystem.ExploredByEmpires.Contains(emp))
                {
                    return(Visibility.Visible);
                }
                if (emp.AllSystemsExploredFromStart)
                {
                    return(Visibility.Fogged);
                }
                var known = emp.Memory[sobj.ID];
                if (known != null && sobj.GetType() == known.GetType())
                {
                    return(Visibility.Fogged);
                }
                else if (Galaxy.Current.Battles.Any(b => b.Combatants.Any(c => c.ID == sobj.ID) && b.Combatants.Any(c => c.Owner == emp)))
                {
                    return(Visibility.Fogged);
                }
                else if (hasMemory)
                {
                    return(Visibility.Fogged);
                }
                else
                {
                    return(Visibility.Unknown);
                }
            }
            if (!sobj.HasAbility("Scanner Jammer"))
            {
                var scanners = seers.Where(s =>
                                           s.HasAbility("Long Range Scanner") && s.GetAbilityValue("Long Range Scanner").ToInt() >= s.Sector.Coordinates.EightWayDistance(sobj.FindSector().Coordinates) ||
                                           s.HasAbility("Long Range Scanner - System"));
                if (scanners.Any())
                {
                    return(Visibility.Scanned);
                }
            }
            return(Visibility.Visible);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Determines if this object is a memory of a known object.
 /// </summary>
 /// <param name="sobj">The object to check.</param>
 /// <returns>true if it is a memory of a known object, otherwise false.</returns>
 public static bool IsMemoryOfKnownObject(this ISpaceObject sobj)
 {
     return(sobj.IsMemory && Empire.Current == null && (sobj.ID == 0 || Galaxy.Current.referrables.ContainsKey(sobj.ID)));
 }
Ejemplo n.º 14
0
 public KdTreeObject(ISpaceObject obj)
 {
     CopyFrom(obj);
 }
Ejemplo n.º 15
0
 public void Query(ISpaceObject obj, float range, MyFunc <float, KdTreeObject, bool> visitor)
 {
     Query(obj.GetPosition(), range, visitor);
 }
Ejemplo n.º 16
0
 public SpaceObjectWaypoint(ISpaceObject sobj)
 {
     SpaceObject = sobj;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// De-Spawns a physical object from the physics world.
 /// One entity per physics object only!
 /// </summary>
 /// <param name="ent">The controlling entity.</param>
 /// <param name="bepuent">The BEPU object.</param>
 public void Despawn(T ent, ISpaceObject bepuent)
 {
     Internal.Remove(bepuent);
     SpawnedEntities.Remove(ent);
 }
Ejemplo n.º 18
0
 public abstract void Place(ISpaceObject target);
Ejemplo n.º 19
0
 public DummyComponent(ISpaceObject ISO)
 {
     spaceObject = ISO;
 }
Ejemplo n.º 20
0
 public SpaceObjectChange(ISpaceObject spaceObject, bool shouldAdd)
 {
     SpaceObject = spaceObject;
     ShouldAdd   = shouldAdd;
 }
Ejemplo n.º 21
0
        public void RemoveFromSpace(ISpaceObject spaceObject)
        {
            System.Diagnostics.Debug.Assert(spaceObject.Space == space, "SpaceObject does not belong to this space. Tell Scott what you did to make this happen.");

            if (spaceObject.Space == space)
            {
                space.Remove(spaceObject);

            #if DEBUG
                if (debugDrawEnabled)
                {
                    Renderer.Instance.collisionDebugDrawer.Remove(spaceObject);
                }
            #endif
            }
        }
Ejemplo n.º 22
0
 ///<summary>
 /// Adds a space object to the buffer.
 /// It will be added to the space the next time the buffer is flushed.
 ///</summary>
 ///<param name="spaceObject">Space object to add.</param>
 public void Add(ISpaceObject spaceObject)
 {
     objectsToChange.Enqueue(new SpaceObjectChange(spaceObject, true));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Enqueues a removal request to the buffer.
 /// It will be processed the next time the buffer is flushed.
 /// </summary>
 /// <param name="spaceObject">Space object to remove.</param>
 public void Remove(ISpaceObject spaceObject)
 {
     objectsToChange.Enqueue(new SpaceObjectChange(spaceObject, false));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Enqueues a removal request to the buffer.
 /// It will be processed the next time the buffer is flushed.
 /// </summary>
 /// <param name="spaceObject">Space object to remove.</param>
 public void Remove(ISpaceObject spaceObject)
 {
     objectsToChange.Enqueue(new SpaceObjectChange(spaceObject, false));
 }
Ejemplo n.º 25
0
        ///<summary>
        /// Removes a space object from the simulation.
        ///</summary>
        ///<param name="spaceObject">Space object to remove.</param>
        public void Remove(ISpaceObject spaceObject)
        {
            if (spaceObject.Space != this)
                throw new ArgumentException("The object does not belong to this space; cannot remove it.");

            SimulationIslandMember simulationIslandMember = spaceObject as SimulationIslandMember;
            if (simulationIslandMember != null)
            {
                DeactivationManager.Remove(simulationIslandMember);
            }

            ISimulationIslandMemberOwner simulationIslandMemberOwner = spaceObject as ISimulationIslandMemberOwner;
            if (simulationIslandMemberOwner != null)
            {
                DeactivationManager.Remove(simulationIslandMemberOwner.ActivityInformation);
            }

            //Go through each stage, removing the space object from it if necessary.
            IForceUpdateable velocityUpdateable = spaceObject as IForceUpdateable;
            if (velocityUpdateable != null)
            {
                ForceUpdater.Remove(velocityUpdateable);
            }

            MobileCollidable boundingBoxUpdateable = spaceObject as MobileCollidable;
            if (boundingBoxUpdateable != null)
            {
                BoundingBoxUpdater.Remove(boundingBoxUpdateable);
            }

            BroadPhaseEntry broadPhaseEntry = spaceObject as BroadPhaseEntry;
            if (broadPhaseEntry != null)
            {
                BroadPhase.Remove(broadPhaseEntry);
            }

            //Entites own collision proxies, but are not entries themselves.
            IBroadPhaseEntryOwner broadPhaseEntryOwner = spaceObject as IBroadPhaseEntryOwner;
            if (broadPhaseEntryOwner != null)
            {
                BroadPhase.Remove(broadPhaseEntryOwner.Entry);
                boundingBoxUpdateable = broadPhaseEntryOwner.Entry as MobileCollidable;
                if (boundingBoxUpdateable != null)
                {
                    BoundingBoxUpdater.Remove(boundingBoxUpdateable);
                }
            }

            SolverUpdateable solverUpdateable = spaceObject as SolverUpdateable;
            if (solverUpdateable != null)
            {
                Solver.Remove(solverUpdateable);
            }

            IPositionUpdateable integrable = spaceObject as IPositionUpdateable;
            if (integrable != null)
            {
                PositionUpdater.Remove(integrable);
            }

            Entity entity = spaceObject as Entity;
            if (entity != null)
            {
                BufferedStates.Remove(entity);
            }

            IDeferredEventCreator deferredEventCreator = spaceObject as IDeferredEventCreator;
            if (deferredEventCreator != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreator);
            }

            IDeferredEventCreatorOwner deferredEventCreatorOwner = spaceObject as IDeferredEventCreatorOwner;
            if (deferredEventCreatorOwner != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreatorOwner.EventCreator);
            }

            //Updateable stages.
            IDuringForcesUpdateable duringForcesUpdateable = spaceObject as IDuringForcesUpdateable;
            if (duringForcesUpdateable != null)
            {
                DuringForcesUpdateables.Remove(duringForcesUpdateable);
            }

            IBeforeNarrowPhaseUpdateable beforeNarrowPhaseUpdateable = spaceObject as IBeforeNarrowPhaseUpdateable;
            if (beforeNarrowPhaseUpdateable != null)
            {
                BeforeNarrowPhaseUpdateables.Remove(beforeNarrowPhaseUpdateable);
            }

            IBeforeSolverUpdateable beforeSolverUpdateable = spaceObject as IBeforeSolverUpdateable;
            if (beforeSolverUpdateable != null)
            {
                BeforeSolverUpdateables.Remove(beforeSolverUpdateable);
            }


            IBeforePositionUpdateUpdateable beforePositionUpdateUpdateable = spaceObject as IBeforePositionUpdateUpdateable;
            if (beforePositionUpdateUpdateable != null)
            {
                BeforePositionUpdateUpdateables.Remove(beforePositionUpdateUpdateable);
            }

            IEndOfTimeStepUpdateable endOfStepUpdateable = spaceObject as IEndOfTimeStepUpdateable;
            if (endOfStepUpdateable != null)
            {
                EndOfTimeStepUpdateables.Remove(endOfStepUpdateable);
            }

            IEndOfFrameUpdateable endOfFrameUpdateable = spaceObject as IEndOfFrameUpdateable;
            if (endOfFrameUpdateable != null)
            {
                EndOfFrameUpdateables.Remove(endOfFrameUpdateable);
            }

            spaceObject.Space = null;
            spaceObject.OnRemovalFromSpace(this);
        }
Ejemplo n.º 26
0
 public SpaceObjectViewModel(ISpaceObject s)
 {
     SpaceObject = s;
 }
Ejemplo n.º 27
0
 public void RemoveObject(ISpaceObject entity)
 {
     space.Remove(entity);
 }
Ejemplo n.º 28
0
 public bool Contains(ISpaceObject sobj)
 {
     return(SpaceObjectLocations.Any(l => l.Item == sobj));
 }
 public void RemovePhysicsObject(ISpaceObject spaceObject)
 {
     space.Remove(spaceObject);
 }
Ejemplo n.º 30
0
        ///<summary>
        /// Removes a space object from the simulation.
        ///</summary>
        ///<param name="spaceObject">Space object to remove.</param>
        public void Remove(ISpaceObject spaceObject)
        {
            if (spaceObject.Space != this)
            {
                throw new ArgumentException("The object does not belong to this space; cannot remove it.");
            }

            SimulationIslandMember simulationIslandMember = spaceObject as SimulationIslandMember;

            if (simulationIslandMember != null)
            {
                DeactivationManager.Remove(simulationIslandMember);
            }

            ISimulationIslandMemberOwner simulationIslandMemberOwner = spaceObject as ISimulationIslandMemberOwner;

            if (simulationIslandMemberOwner != null)
            {
                DeactivationManager.Remove(simulationIslandMemberOwner.ActivityInformation);
            }

            //Go through each stage, removing the space object from it if necessary.
            IForceUpdateable velocityUpdateable = spaceObject as IForceUpdateable;

            if (velocityUpdateable != null)
            {
                ForceUpdater.Remove(velocityUpdateable);
            }

            MobileCollidable boundingBoxUpdateable = spaceObject as MobileCollidable;

            if (boundingBoxUpdateable != null)
            {
                BoundingBoxUpdater.Remove(boundingBoxUpdateable);
            }

            BroadPhaseEntry broadPhaseEntry = spaceObject as BroadPhaseEntry;

            if (broadPhaseEntry != null)
            {
                BroadPhase.Remove(broadPhaseEntry);
            }

            //Entites own collision proxies, but are not entries themselves.
            IBroadPhaseEntryOwner broadPhaseEntryOwner = spaceObject as IBroadPhaseEntryOwner;

            if (broadPhaseEntryOwner != null)
            {
                BroadPhase.Remove(broadPhaseEntryOwner.Entry);
                boundingBoxUpdateable = broadPhaseEntryOwner.Entry as MobileCollidable;
                if (boundingBoxUpdateable != null)
                {
                    BoundingBoxUpdater.Remove(boundingBoxUpdateable);
                }
            }

            SolverUpdateable solverUpdateable = spaceObject as SolverUpdateable;

            if (solverUpdateable != null)
            {
                Solver.Remove(solverUpdateable);
            }

            IPositionUpdateable integrable = spaceObject as IPositionUpdateable;

            if (integrable != null)
            {
                PositionUpdater.Remove(integrable);
            }

            Entity entity = spaceObject as Entity;

            if (entity != null)
            {
                BufferedStates.Remove(entity);
            }

            IDeferredEventCreator deferredEventCreator = spaceObject as IDeferredEventCreator;

            if (deferredEventCreator != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreator);
            }

            IDeferredEventCreatorOwner deferredEventCreatorOwner = spaceObject as IDeferredEventCreatorOwner;

            if (deferredEventCreatorOwner != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreatorOwner.EventCreator);
            }

            //Updateable stages.
            IDuringForcesUpdateable duringForcesUpdateable = spaceObject as IDuringForcesUpdateable;

            if (duringForcesUpdateable != null)
            {
                DuringForcesUpdateables.Remove(duringForcesUpdateable);
            }

            IBeforeNarrowPhaseUpdateable beforeNarrowPhaseUpdateable = spaceObject as IBeforeNarrowPhaseUpdateable;

            if (beforeNarrowPhaseUpdateable != null)
            {
                BeforeNarrowPhaseUpdateables.Remove(beforeNarrowPhaseUpdateable);
            }

            IBeforeSolverUpdateable beforeSolverUpdateable = spaceObject as IBeforeSolverUpdateable;

            if (beforeSolverUpdateable != null)
            {
                BeforeSolverUpdateables.Remove(beforeSolverUpdateable);
            }


            IBeforePositionUpdateUpdateable beforePositionUpdateUpdateable = spaceObject as IBeforePositionUpdateUpdateable;

            if (beforePositionUpdateUpdateable != null)
            {
                BeforePositionUpdateUpdateables.Remove(beforePositionUpdateUpdateable);
            }

            IEndOfTimeStepUpdateable endOfStepUpdateable = spaceObject as IEndOfTimeStepUpdateable;

            if (endOfStepUpdateable != null)
            {
                EndOfTimeStepUpdateables.Remove(endOfStepUpdateable);
            }

            IEndOfFrameUpdateable endOfFrameUpdateable = spaceObject as IEndOfFrameUpdateable;

            if (endOfFrameUpdateable != null)
            {
                EndOfFrameUpdateables.Remove(endOfFrameUpdateable);
            }

            spaceObject.Space = null;
            spaceObject.OnRemovalFromSpace(this);
        }
Ejemplo n.º 31
0
        // position and rotation come from world parm file, which we dont have access to here
        /*public PhysicsObject(PhysicsType physicsType, Model model, Vector3 position, float mass)
        {
            this.physicsType = physicsType;
            int id = idCounter++;

            if (DisableMass)
                mass = -1.0f;

            switch (physicsType)
            {
                case PhysicsType.Box:
                    spaceObject = PhysicsHelpers.ModelToPhysicsBox(model, position, mass);
                    // boxes contain a broadphase entry which is what shows up in ray casts, so we need to make sure its tag is set to the right id
                    // this will need to be done fore anything that is an ibroadphaseentryowner
                    ((IBroadPhaseEntryOwner)spaceObject).Entry.Tag = id;
                    break;
                case PhysicsType.StaticMesh:
                    spaceObject = PhysicsHelpers.ModelToStaticMesh(model, new BEPUphysics.MathExtensions.AffineTransform(position));
                    //staticmesh's are not ibroadphaseentryowners...they will turn directly on the raycast, so nothing else to set the tag on
                    break;
                case PhysicsType.None:
                    spaceObject = null;
                    this.position = position;
                    return;
            }

            spaceObject.Tag = id;
            Stage.ActiveStage.GetQB<PhysicsQB>().Space.Add(spaceObject);
        }*/
        /// <summary>
        /// Create a physics object
        /// </summary>
        /// <param name="actor">Actor that we are attached to</param>
        /// <param name="Parm">Actor's parm file</param>
        /// <param name="model">Actors model (so we can size the collider)</param>
        /// <param name="position">Position (from world parm)</param>
        /// <param name="rotation">Rotation (from world parm)</param>
        public PhysicsObject(Actor actor, ParameterSet Parm, Model model, Vector3 position, Vector3 rotation, Stage stage)
        {
            // **rotation comes in from file as ( pitch, yaw, roll )**

            this.actor = actor;
            this.physicsType = GameLib.PhysicsObject.PhysicsTypeFromString(Parm.GetString("PhysicsType"));
            this.position = position;
            this.rotation = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);

            if (ForceStaticMesh)
                this.physicsType = PhysicsType.StaticMesh;

            switch (this.physicsType)
            {
                case PhysicsType.Box:
                    {
                        float mass;
                        if (DisableMass)
                            mass = -1.0f;
                        else
                            mass = Parm.GetFloat("Mass");
                        BEPUphysics.Entities.Entity entity = PhysicsHelpers.ModelToPhysicsBox(model, position, mass, rotation.X, rotation.Y, rotation.Z);
                        entity.CollisionInformation.OwningActor = actor;
                        spaceObject = entity;
                        break;
                    }
                case PhysicsType.StaticMesh:
                    BEPUphysics.Collidables.StaticMesh mesh = PhysicsHelpers.ModelToStaticMesh(model, new BEPUphysics.MathExtensions.AffineTransform(Quaternion.CreateFromRotationMatrix( this.rotation ), position));
                    mesh.OwningActor = actor;
                    spaceObject = mesh;
                    break;
                case PhysicsType.Character:
                    {
                        float mass = Parm.GetFloat("Mass");
                        float scaleRadius = 1.0f;
                        if (Parm.HasParm("ScaleRadius"))
                            scaleRadius = Parm.GetFloat("ScaleRadius");
                        characterController = PhysicsHelpers.ModelToCharacterController(model, position, mass, scaleRadius);
                        spaceObject = characterController.Body;
                        characterController.Body.CollisionInformation.OwningActor = actor;
                        stage.GetQB<PhysicsQB>().AddToSpace(CharacterController);
                        return;
                    }
                case PhysicsType.CylinderCharacter:
                    {
                        float mass = Parm.GetFloat("Mass");
                        float scaleRadius = 1.0f;
                        if (Parm.HasParm("ScaleRadius"))
                            scaleRadius = Parm.GetFloat("ScaleRadius");
                        if (Parm.HasParm("ColliderDims"))
                        {
                            Vector2 v = Parm.GetVector2("ColliderDims");
                            cylinderCharController = new CylinderCharacterController(position, v.Y, v.X, mass);
                        }
                        else
                            cylinderCharController = PhysicsHelpers.ModelToCylinderCharacterController(model, position, mass, scaleRadius);
                        cylinderCharController.Body.Orientation = Quaternion.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
                        spaceObject = cylinderCharController.Body;
                        cylinderCharController.Body.CollisionInformation.OwningActor = actor;
                        stage.GetQB<PhysicsQB>().AddToSpace(cylinderCharController);
                        return;
                    }
                case PhysicsType.TriggerVolume:
                    {
                        DetectorVolume detectorVolume = new DetectorVolume(PhysicsHelpers.ModelToTriangleMesh(model, position));
                        detectorVolume.OwningActor = actor;
                        spaceObject = detectorVolume;
                        detectorVolume.EntityBeganTouching += new EntityBeginsTouchingVolumeEventHandler(detectorVolume_EntityBeganTouching);
                        detectorVolume.EntityStoppedTouching += new EntityStopsTouchingVolumeEventHandler(detectorVolume_EntityStoppedTouching);
                        break;
                    }
                case PhysicsType.None:
                    spaceObject = null;
                    this.position = position;
                    this.rotation = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
                    return;
            }

            stage.GetQB<PhysicsQB>().AddToSpace(spaceObject);
        }
Ejemplo n.º 32
0
 public bool IsSelected(ISpaceObject obj)
 {
     return(obj.ObjectId == SelectedObject?.ObjectId);
 }