Exemple #1
0
        public List <ushort> FindClosestRenderedThings(Vector2 worldPos, float searchRadius, List <ushort> toReturn)
        {
            if (toReturn == null)
            {
                toReturn = new List <ushort>();
            }
            else
            {
                toReturn.Clear();
            }

            for (ushort i = 0; i < thingsToRenderAmount; i++)
            {
                ThingPosition thingPosition = thingsPositions[thingsToRender[i]];

                float distance = (worldPos - new Vector2(thingPosition.x, thingPosition.y)).sqrMagnitude;

                if (distance < (thingPosition.radius + searchRadius) * (thingPosition.radius + searchRadius))
                {
                    toReturn.Add(thingsToRender[i]);
                }
            }

            ThingDistanceComparerReference = worldPos;
            toReturn.Sort(ThingDistanceComparer);

            return(toReturn);
        }
Exemple #2
0
        public int FindClosestRenderedThing(Vector2 worldPos, float searchRadius)
        {
            ushort closestThingIndex    = ushort.MaxValue;
            float  closestThingDistance = float.MaxValue;

            for (ushort i = 0; i < thingsToRenderAmount; i++)
            {
                ThingPosition thingPosition = thingsPositions[thingsToRender[i]];

                float distance = (worldPos - new Vector2(thingPosition.x, thingPosition.y)).sqrMagnitude;

                if (distance < (thingPosition.radius + searchRadius) * (thingPosition.radius + searchRadius) &&
                    distance < closestThingDistance)
                {
                    closestThingIndex    = thingsToRender[i];
                    closestThingDistance = distance;
                }
            }

            if (closestThingIndex != ushort.MaxValue)
            {
                return(closestThingIndex);
            }
            else
            {
                return(-1);
            }
        }
Exemple #3
0
        private void UpdatePlanetPosition()
        {
            ThingPosition thing = universe.GetThingPosition(thingIndex);

            position.x = thing.x;
            position.y = thing.y;
            rotation   = thing.rotation;
        }