Exemple #1
0
        /// <summary>
        /// point是否在扇形范围内
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public bool ContainPoint(Vector3 point)
        {
            point.y = 0;
            Vector3 line = point - m_center;
            float   dis  = Vector3.SqrMagnitude(line) - m_radius * m_radius;

            //如果角度为0, 我们就只判断距离
            if (m_angle <= 0)
            {
                return(dis <= m_radius * m_radius);
            }

            //距离太远在圆形外
            if (dis > 0)
            {
                return(false);
            }

            float startAngle = m_centerAngle - m_angle * 0.5f;
            float endAngle   = m_centerAngle + m_angle * 0.5f;

            float targetAngle = CMathUtil.GetVec3AngleInXZ(line);

            return(targetAngle > startAngle && targetAngle < endAngle);
        }
Exemple #2
0
 /// <summary>
 /// 设置扇形中心线
 /// </summary>
 /// <param name="direction"></param>
 public void SetDirection(Vector3 direction)
 {
     m_direction   = direction;
     m_direction.y = 0;
     m_centerAngle = CMathUtil.GetVec3AngleInXZ(m_direction);
 }