Beispiel #1
0
        /// <summary>
        /// 获取滚动进入的邻边多边形形
        /// </summary>
        /// <param name="s">起点,s点在目标三角形内</param>
        /// <param name="e">终点</param>
        /// <param name="TargetTri">目标三角形</param>
        /// <param name="collision"></param>
        /// <returns>true:有进入 false 未进入</returns>
        public bool CheckIntoNearTriangle(Vector3 s, Vector3 e, GolfAIMapPolygon PolyTarget, ref GolfIntoTriCollision collision)
        {
            Vector3 hitPoint = Vector3.zero;

            if (PolyTarget == null)
            {
                return(false);
            }
            // 判断是否在多边形内部
            if (PolyTarget.CheckProjectionInArea(e) == true)
            {
                return(false);
            }
            //
            if (collision == null)
            {
                collision = new GolfIntoTriCollision();
            }

            collision.ColType = CollisionType.Out;
            List <Index2> l = m_Qtree.GetAllTri(e);

            if (l == null || l.Count == 0)
            {
                return(false);
            }
            foreach (Index2 v in l)
            {
                GolfMaptriangle tri = GetMapTriangle(v);
                if (tri.Parent == PolyTarget)
                {
                    continue;
                }
                if (tri.GetLineIntersectPoint(s, e, ref hitPoint) == true)
                {
                    collision.Poly  = tri.Parent;
                    collision.Point = hitPoint;
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// 计算下一个真正的滚动点
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="nextPosition"></param>
        /// <param name="nextVelocity"></param>
        /// <param name="acc"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public GolfRollPoint CalcRealRollPoint(GolfRollPoint startPoint, Vector3 nextPosition, Vector3 nextVelocity, Vector3 acc, float time)
        {
            GolfRollPoint        nextPoint = new GolfRollPoint();
            GolfIntoTriCollision collision = null;
            bool isChangeTri = m_CurMap.CheckIntoNearTriangle(startPoint.Position, nextPosition, startPoint.Poly, ref collision);

            if (isChangeTri)
            {
                //切换三角面,这里返回的collision是预测滚动路径与三角面对应边的交点,即真正的下一个点
                nextPoint.Position = collision.Point;
                float realTime = time;
                nextPoint.Velocity = CalcRealRollVelocity(startPoint.Position, collision.Point, startPoint.Velocity, startPoint.AType, startPoint.Poly, time, acc, out realTime);;
                nextPoint.Poly     = collision.Poly;
                nextPoint.AType    = collision.Type;
                nextPoint.IsRoll   = true;
                nextPoint.ColType  = collision.ColType;
                nextPoint.Interval = realTime;
                nextPoint.IsRoll   = true;
                nextPoint.Status   = BallRunStatus.Roll;
                //Debug.Log("Change   TriCalcRollP: " + " Position:" + nextPoint.Position + " Vel:" + nextPoint.Velocity + " acc:" + acc + " Tri:" + nextPoint.MapTri + " SubMap:" + nextPoint.SubMap);
            }
            else
            {
                //在同一个三角面,按正常跑
                nextPoint.Position = nextPosition;
                nextPoint.Velocity = nextVelocity;
                nextPoint.Poly     = startPoint.Poly;
                nextPoint.AType    = startPoint.AType;
                nextPoint.IsRoll   = true;
                nextPoint.ColType  = startPoint.ColType;
                nextPoint.Interval = time;
                nextPoint.IsRoll   = true;
                nextPoint.Status   = BallRunStatus.Roll;
                //Debug.Log("No   ChangeTriCalcRollP: " + " Position:" + nextPoint.Position + " Vel:" + nextPoint.Velocity + " acc:" + acc + " Tri:" + nextPoint.MapTri + " SubMap:" + nextPoint.SubMap);
            }
            return(nextPoint);
        }