예제 #1
0
        private void Integrate(CPosition position, CKinetic kinetic, Integrator integrator, float deltaTime)
        {
            switch (integrator)
            {
            case Integrator.SemiImplictEuler:
                SemiImplictEulerIntegration();
                break;

            case Integrator.VelocityVerlet:
                VelocityVerletIntegration();
                break;
            }

            void SemiImplictEulerIntegration()
            {
                kinetic.Velocity += kinetic.Acceleration * deltaTime;

                position.X += kinetic.Velocity.X * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime;
            }

            void VelocityVerletIntegration()
            {
                position.X += kinetic.Velocity.X * deltaTime + 0.5f * kinetic.Acceleration.X * deltaTime * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime + 0.5f * kinetic.Acceleration.Y * deltaTime * deltaTime;

                kinetic.Velocity += kinetic.Acceleration * deltaTime;
            }
        }
예제 #2
0
        private void Simultate(int entity)
        {
            CPosition position = (CPosition)positions[entity];
            CKinetic  kinetic  = (CKinetic)kinetics[entity];

            kinetic.Accumulator += (float)(Engine.TotalGameTime - kinetic.LastUpdate).TotalSeconds;
            kinetic.LastUpdate   = new TimeSpan(Engine.TotalGameTime.Ticks);

            while (kinetic.Accumulator >= target)
            {
                Integrate(position, kinetic, integrator, target);
                kinetic.Accumulator -= target;
            }
        }