private void DoMove()
        {
            VRageMath.BoundingBoxD aggregatebox = new VRageMath.BoundingBoxD();
            for (var x = 0; x < Entities.Count; x++)
            {
                var entity = MyAPIGateway.Entities.GetEntityById(Entities[x]);
                if (entity != null)
                {
                    var box = entity.PositionComp.WorldAABB;
                    box.Translate(entity.PositionComp.GetPosition() - Positions[x]);
                    aggregatebox.Include(ref box);
                }
            }
            MyAPIGateway.Physics.EnsurePhysicsSpace(aggregatebox);
            for (var x = 0; x < Entities.Count; x++)
            {
                var entity = MyAPIGateway.Entities.GetEntityById(Entities[x]);
                if (entity != null)
                {
                    entity.PositionComp.SetPosition(Positions[x]);

                    //if (entity.SyncObject != null)
                    //    entity.SyncObject.UpdatePosition();

                    Logger.Instance.LogMessage(string.Format("updated {0} to: {1:F0}, {2:F0}, {3:F0}", entity.DisplayName, Positions[x].X, Positions[x].Y, Positions[x].Z));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all valid connected grids, and floating objects or players.
        /// </summary>
        /// <param name="ftl"></param>
        /// <returns></returns>
        public static HashSet <IMyEntity> GetAllValidObjects(this IMyFunctionalBlock ftl)
        {
            Logger.Instance.LogDebug("GetAllValidObjects()");

            var objects      = ftl.GetConnectedGrids();
            var floatingobjs = new HashSet <IMyEntity>();

            foreach (var entity in objects)
            {
                var collisions                = new List <IMyEntity>();
                var uniqueEntities            = new HashSet <IMyEntity>();
                VRageMath.BoundingBoxD shipBB = entity.PositionComp.WorldAABB;

                // Get a list of entities nearby
                collisions = MyAPIGateway.Entities.GetEntitiesInAABB(ref shipBB);
                // The collision list will contain every block on a entity
                // So we need to reduce it down to just the entities themselves
                foreach (var col in collisions)
                {
                    if (col == null)
                    {
                        continue;
                    }

                    if (col.GetTopMostParent() is IMyCubeGrid)
                    {
                        if (!uniqueEntities.Contains(col.GetTopMostParent()))
                        {
                            uniqueEntities.Add(col.GetTopMostParent());
                        }
                    }
                    else
                    {
                        uniqueEntities.Add(col);
                    }
                }
                Logger.Instance.LogDebug("uniqueEntities: " + uniqueEntities.Count);

                foreach (var unique in uniqueEntities)
                {
                    if (!IsEntityValid(unique))
                    {
                        continue;
                    }

                    // Check if the two entities actually intersect, otherwise we don't want to jump it
                    if (!floatingobjs.Contains(unique.GetTopMostParent()) && shipBB.Intersects(unique.GetTopMostParent().PositionComp.WorldAABB))
                    {
                        floatingobjs.Add(unique.GetTopMostParent());
                    }
                }
            }

            objects.UnionWith(floatingobjs);
            return(objects);
        }
        List <IMyEntity> IMyEntities.GetEntitiesInAABB(ref VRageMath.BoundingBoxD boundingBox)
        {
            var lst    = MyEntities.GetEntitiesInAABB(ref boundingBox);
            var result = new List <IMyEntity>(lst.Count);

            foreach (var entity in lst)
            {
                result.Add(entity);
            }
            return(result);
        }
Esempio n. 4
0
        List <IMyEntity> IMyEntities.GetElementsInBox(ref VRageMath.BoundingBoxD boundingBox)
        {
            m_entityList.Clear();
            MyEntities.GetElementsInBox(ref boundingBox, m_entityList);
            var result = new List <IMyEntity>(m_entityList.Count);

            foreach (var entity in m_entityList)
            {
                result.Add(entity);
            }
            return(result);
        }
Esempio n. 5
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix    = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
Esempio n. 6
0
 float IMyVoxelMap.GetVoxelContentInBoundingBox(VRageMath.BoundingBoxD worldAabb, out float cellCount)
 {
     return(GetVoxelContentInBoundingBox_Obsolete(worldAabb, out cellCount));
 }
Esempio n. 7
0
 /// <summary>
 /// Add AABB box to be drawn
 /// </summary>
 /// <param name="aabb">AABB box in world coords</param>
 /// <param name="col">Color</param>
 static public void AddAABB(VRageMath.BoundingBoxD aabb, VRageMath.Color col)
 {
     AABBsToDraw.Add(new Tuple <VRageMath.BoundingBoxD, VRageMath.Color>(aabb, col));
 }
        public static void ShowMessageToUsersInRange(this IMyFunctionalBlock ftl, string message, int time = 2000, bool bIsError = false)
        {
            bool isMe = false;

            if (MyAPIGateway.Players == null || MyAPIGateway.Entities == null || MyAPIGateway.Session == null || MyAPIGateway.Utilities == null)
            {
                return;
            }

            if (MyAPIGateway.Multiplayer.IsServer || MyAPIGateway.Session.Player == null)
            {
                // DS, look for players
                VRageMath.BoundingBoxD box = ftl.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity>    entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);
                HashSet <IMyPlayer> players  = new HashSet <IMyPlayer>();

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    var player = MyAPIGateway.Players.GetPlayerControllingEntity(entity);

                    if (player != null && entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        players.Add(player);
                    }
                }

                foreach (var player in players)
                {
                    SendTextMessage(player, message, time, bIsError);
                }
            }
            else
            {
                if (MyAPIGateway.Session.Player == null || MyAPIGateway.Session.Player.Controller == null ||
                    MyAPIGateway.Session.Player.Controller.ControlledEntity == null)
                {
                    return;
                }

                VRageMath.BoundingBoxD box = ftl.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    if (entity.EntityId == MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent().EntityId&&
                        entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        isMe = true;
                        break;
                    }
                }

                if ((MyAPIGateway.Players.GetPlayerControllingEntity(ftl.GetTopMostParent()) != null &&
                     MyAPIGateway.Session.Player != null &&
                     MyAPIGateway.Session.Player.PlayerID == MyAPIGateway.Players.GetPlayerControllingEntity(ftl.GetTopMostParent()).PlayerID) ||
                    isMe)
                {
                    MyAPIGateway.Utilities.ShowNotification(message, time);
                }
            }
        }
 bool IMyCamera.IsInFrustum(BoundingBoxD boundingBox)
 {
     return IsInFrustum(boundingBox);
 }
Esempio n. 10
0
 public bool IsInFrustum(BoundingBoxD boundingBox)
 {
     return IsInFrustum(ref boundingBox);
 }
Esempio n. 11
0
 //  Checks if specified bounding box is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding box.
 //  Don't use BoundingBox.Transform. Instead transform box manualy and then create new box.
 public bool IsInFrustum(ref BoundingBoxD boundingBox)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingBox, out result);
     return result != VRageMath.ContainmentType.Disjoint;
 }
Esempio n. 12
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
Esempio n. 13
0
 bool IMyCamera.IsInFrustum(BoundingBoxD boundingBox)
 {
     return(IsInFrustum(boundingBox));
 }
Esempio n. 14
0
 public bool IsInFrustum(BoundingBoxD boundingBox)
 {
     return(IsInFrustum(ref boundingBox));
 }
Esempio n. 15
0
 //  Checks if specified bounding box is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding box.
 //  Don't use BoundingBox.Transform. Instead transform box manualy and then create new box.
 public bool IsInFrustum(ref BoundingBoxD boundingBox)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingBox, out result);
     return(result != VRageMath.ContainmentType.Disjoint);
 }
Esempio n. 16
0
        public static void ShowMessageToUsersInRange(IMyEntity block, string message, int time = 2000, bool bIsError = false)
        {
            bool isMe = false;

            if (MyAPIGateway.Players == null || MyAPIGateway.Entities == null || MyAPIGateway.Session == null || MyAPIGateway.Utilities == null)
            {
                return;
            }

            if (MyAPIGateway.Multiplayer.IsServer || MyAPIGateway.Session.Player == null)
            {
                // DS, look for players
                VRageMath.BoundingBoxD box = block.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity>    entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);
                HashSet <IMyPlayer> players  = new HashSet <IMyPlayer>();

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    var player = MyAPIGateway.Players.GetPlayerControllingEntity(entity);

                    if (player != null && entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        players.Add(player);
                    }
                }

                foreach (var player in players)
                {
                    MessageUtils.SendMessageToPlayer(player.SteamUserId, new MessageText()
                    {
                        Message = message, Timeout = time, Error = bIsError
                    });
                }
            }
            else
            {
                if (MyAPIGateway.Players == null || MyAPIGateway.Entities == null || MyAPIGateway.Session == null || MyAPIGateway.Utilities == null ||
                    MyAPIGateway.Session.Player == null || MyAPIGateway.Session.Player.Controller == null ||
                    MyAPIGateway.Session.Player.Controller.ControlledEntity == null)
                {
                    return;
                }

                VRageMath.BoundingBoxD box = block.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    if (entity.EntityId == MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent().EntityId&&
                        entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        isMe = true;
                        break;
                    }
                }

                if ((MyAPIGateway.Players.GetPlayerControllingEntity(block.GetTopMostParent()) != null &&
                     MyAPIGateway.Session.Player != null &&
                     MyAPIGateway.Session.Player.IdentityId == MyAPIGateway.Players.GetPlayerControllingEntity(block.GetTopMostParent()).IdentityId) ||
                    isMe)
                {
                    MyAPIGateway.Utilities.ShowNotification(message, time, (bIsError ? MyFontEnum.Red : MyFontEnum.White));
                }
            }
        }