Пример #1
0
            public float2 CalculateGravity(Entity entity, float2 pos, float mass)
            {
                float2 force = float2.zero;
                float2 displ = pos - centerOfMass;
                float  dist  = math.length(displ);

                if (dist == 0)
                {
                    dist = 0.001f;
                }

                if (isExternal)
                {
                    if (objects.Count == 0 || (objects.Count == 1 && objects[0].Index == entity.Index))
                    {
                        force = float2.zero;
                    }
                    else
                    {
                        force -= displ * WorldSettings.GravityConstant * this.mass * mass / math.pow(dist, 3);
                    }
                }
                else if (math.abs(area.Width / dist) < WorldSettings.Threshold)
                {
                    force -= displ * WorldSettings.GravityConstant * this.mass * mass / math.pow(dist, 3);
                }
                else
                {
                    force += bottomLeft.CalculateGravity(entity, pos, mass);
                    force += bottomRight.CalculateGravity(entity, pos, mass);
                    force += topLeft.CalculateGravity(entity, pos, mass);
                    force += topRight.CalculateGravity(entity, pos, mass);
                }

                return(force);
            }
Пример #2
0
 public float2 CalculateGravity(Entity entity, float2 pos, float mass)
 {
     return(baseNode != null?baseNode.CalculateGravity(entity, pos, mass) : float2.zero);
 }