﻿using UnityEngine;

namespace pdinklag.CPW.Common
{
    /// <summary>
    /// Component for body parts approximated by a capsule.
    /// </summary>
    public class BodyPartCapsule : BodyPartCylindrical
    {
        public override float Volume
        {
            get
            {
                var v = MathExt.SphereVolumeCoeff * (Radius * Radius * Radius); ;
                if (Height > 2.0f * Radius)
                {
                    v += Mathf.PI * (Radius * Radius) * (Height - 2.0f * Radius);
                }
                return v;
            }
        }

#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            var p = transform.position;
            var ext = 0.5f * Height * transform.up;
            DebugExtension.DrawCapsule(p - ext, p + ext, GizmoColor, Radius);
        }
#endif
    }
}
