Example #1
0
        /// <summary>
        /// 计算碰撞点
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        public bool CalcBouncePoint(GolfMapFlyCollision collision, GolfFlyPoint startPoint, int haveReboundCount, ref GolfBouncePoint golfBouncePoint)
        {
            //Debug.Log("lastPos:" + lastPos + "  curPos:" + curPos + " collisionPoint:" + ret.Point + " ret.Tri:" + ret.Tri);
            golfBouncePoint.Position = collision.Point;
            golfBouncePoint.ColType  = collision.ColType;
            if (collision.ColType == CollisionType.Out)
            {
                return(true);
            }
            //计算碰撞点的速度
            Vector3 collisionVelocity = CalcCollisionVelocity(startPoint.Position, collision.Point, startPoint.Velocity);

            golfBouncePoint.Velocity = collisionVelocity;
            golfBouncePoint.Poly     = collision.Poly;
            golfBouncePoint.AType    = collision.Type;

            //计算反弹
            //旋球限制
            //int type = (int)ret.Type;
            //if (type >= 1 && type <= 5)
            //{
            //    GolfBounceParam.SpinVelocityRevise = Mathf.Clamp(GolfBounceParam.SpinVelocityRevise, -MaxSpinList[type - 1], MaxSpinList[type - 1]);
            //}
            Vector3 outVelocity = Vector3.zero;
            bool    rebound     = CalcBounce(collisionVelocity, collision.Normal, collision.Type, haveReboundCount, ref outVelocity);

            golfBouncePoint.IsRebound   = rebound;
            golfBouncePoint.OutVelocity = outVelocity;
            return(rebound);
        }
Example #2
0
        public bool CheckCollisionPoint(Vector3 s, Vector3 e, ref GolfMapFlyCollision ret)
        {
            if (s.Equals(e) == true)
            {
                return(false);
            }

            if (CheckIsOut(s, e) == true || m_Qtree == null)
            {
                if (ret == null)
                {
                    ret = new GolfMapFlyCollision();
                }
                ret.Point   = e;
                ret.ColType = CollisionType.Out;
                return(true);
            }

            QuadTree tree = m_Qtree.GetTree(s, e);

            if (tree == null)
            {
                if (ret == null)
                {
                    ret = new GolfMapFlyCollision();
                }
                ret.Point   = e;
                ret.ColType = CollisionType.Out;
                return(true);
            }
            else
            {
                Vector3       Hitpoint = Vector3.zero;
                List <Index2> l        = tree.GetAllTri(s, e);
                if (l == null || l.Count == 0)
                {
                    return(false);
                }
                foreach (Index2 v in l)
                {
                    GolfMaptriangle tri = GetMapTriangle(v);
                    if (tri.CalcIntersectPoint(s, e, ref Hitpoint) == true)
                    {
                        if (ret == null)
                        {
                            ret = new GolfMapFlyCollision();
                        }
                        ret.Point   = Hitpoint;
                        ret.Type    = GetSubMap(v.MapID).Type;
                        ret.Poly    = tri.Parent;
                        ret.ColType = CollisionType.Normal;
                        ret.Normal  = ret.Poly.Normal;
                        return(true);
                    }
                }
            }
            if (s.y >= 0 && e.y < 0)
            {
                if (s.y >= 0 && e.y < 0)
                {
                    Debug.Log("XXXXXXXXXXXXXPPPPP:");
                    Debug.Log("s:" + s.x + "," + s.y + "," + s.z);
                    Debug.Log("e:" + e.x + "," + e.y + "," + e.z);
                }
            }
            return(false);
        }