Ejemplo n.º 1
0
        private static float CalculateForce(IEnumerable <GravityObject> objects, Vector2f point)
        {
            var totalForce = new Vector2f();

            foreach (var go in objects)
            {
                var distSquared = point.DistanceSquared(go.GlobalCenterOfMass);
                distSquared /= 10;
                var offsetVec = go.GlobalCenterOfMass - point;
                var force     = GravityObject.GravitationalConstant * (Mass * go.Mass) * offsetVec.Normalize() /
                                distSquared;

                totalForce += force;
            }

            return(totalForce.Magnitude());
        }
Ejemplo n.º 2
0
        public Actor GetClosestActor(Vector2f origin, ActorCategory category)
        {
            const float SEARCH_RADIUS_SQ = 50.0f * 50.0f;

            Actor closestActor  = null;
            float closestSqDist = Single.MaxValue;

            // Find scenes near the actor
            for (int i = 0; i < this.Scenes.Length; i++)
            {
                Scene scene = this.Scenes[i];
                if (AABB.DistanceSquared(scene.BoundingBox, origin) <= SEARCH_RADIUS_SQ)
                {
                    // Check distance for all actors in the this scene
                    for (int j = 0; j < scene.Actors.Count; j++)
                    {
                        Actor actor = scene.Actors[j];
                        if (actor.AcdID == this.Me.AcdID || actor.Category == ActorCategory.ServerProp)
                        {
                            continue;
                        }

                        if (category == ActorCategory.Invalid || category == actor.Category)
                        {
                            float sqDist = Vector2f.DistanceSquared(origin, actor.Position);
                            if (sqDist < closestSqDist)
                            {
                                closestActor  = actor;
                                closestSqDist = sqDist;
                            }
                        }
                    }
                }
            }

            return(closestActor);
        }
Ejemplo n.º 3
0
 public bool Contains(Vector2f point)
 {
     return(center.DistanceSquared(point) < radius * radius);
 }