﻿using Nemesis.Mathematics.Geometry.Intersection;
using Nemesis.Physics.Collision.Detection;
using NemesisGame.Player;

namespace NemesisGame.Level
{
    /// <summary>
    /// Collision dispatcher implementation for "CharacterShape" type
    /// (which is a type defined in "Nemesis.Player" module).
    /// </summary>
    public sealed class GameCollisionDispatcher : SimpleCollisionDispatcher
    {
        public sealed override VolumeIntersection? Collide(IShape firstShape, IShape secondShape)
        {
            return CollideImpl(firstShape as dynamic, secondShape as dynamic);
        }

        private static VolumeIntersection? CollideImpl(CharacterShape character, AabbShape aabb)
        {
            return BoxBox.GetIntersection(character.GetBoundingBox(), aabb.GetBoxPrimitive());
        }

        private static VolumeIntersection? CollideImpl(AabbShape aabb, CharacterShape character)
        {
            return BoxBox.GetIntersection(aabb.GetBoxPrimitive(), character.GetBoundingBox());
        }

        private static VolumeIntersection? CollideImpl(SphereShape sphere, CharacterShape character)
        {
            return SphereBox.GetIntersection(sphere.Primitive, character.GetBoundingBox());
        }

        private static VolumeIntersection? CollideImpl(CharacterShape character, SphereShape sphere)
        {
            return SphereBox.GetIntersection(character.GetBoundingBox(), sphere.Primitive);
        }
    }
}
