예제 #1
0
        private static void ApplyGravityZ(Moon moon1, Moon moon2)
        {
            if (moon1.Position.Z > moon2.Position.Z)
            {
                moon1.Velocity.Z--;
                moon2.Velocity.Z++;
                return;
            }

            if (moon1.Position.Z < moon2.Position.Z)
            {
                moon1.Velocity.Z++;
                moon2.Velocity.Z--;
                return;
            }
        }
예제 #2
0
        private static void ApplyGravityX(Moon moon1, Moon moon2)
        {
            if (moon1.Position.X > moon2.Position.X)
            {
                moon1.Velocity.X--;
                moon2.Velocity.X++;
                return;
            }

            if (moon1.Position.X < moon2.Position.X)
            {
                moon1.Velocity.X++;
                moon2.Velocity.X--;
                return;
            }
        }
예제 #3
0
        private static void ApplyGravityY(Moon moon1, Moon moon2)
        {
            if (moon1.Position.Y > moon2.Position.Y)
            {
                moon1.Velocity.Y--;
                moon2.Velocity.Y++;
                return;
            }

            if (moon1.Position.Y < moon2.Position.Y)
            {
                moon1.Velocity.Y++;
                moon2.Velocity.Y--;
                return;
            }
        }
예제 #4
0
        private static void Step(List <Moon> moons)
        {
            for (int i = 0; i < moons.Count; i++)
            {
                // Only apply to moons that are ahead on the list
                for (int j = i + 1; j < moons.Count; j++)
                {
                    Moon moon1 = moons[i];
                    Moon moon2 = moons[j];

                    ApplyGravityX(moon1, moon2);
                    ApplyGravityY(moon1, moon2);
                    ApplyGravityZ(moon1, moon2);
                }
            }

            ApplyVelocity(moons);
        }