/// <summary> /// 获取小球滚动加速度 /// </summary> /// <param name="velocity"></param> /// <param name="areaType"></param> /// <param name="poly"></param> /// <returns></returns> public Vector3 GetRollAcceleration(Vector3 velocity, AreaType areaType, GolfAIMapPolygon poly) { //根据配档的摩擦系数求加速度 Vector3 acc = CalcRollFrictionAcc(velocity, areaType, poly); //加速度方向校正 acc = CalcTangentVelocity(acc, poly.Normal); return(acc); }
/// <summary> /// 计算滚动点的摩擦力加速度 /// </summary> /// <param name="velocity"></param> /// <param name="areaType"></param> /// <returns></returns> public Vector3 CalcRollFrictionAcc(Vector3 velocity, AreaType areaType, GolfAIMapPolygon poly) { GroundmaterialConfig groundMatConfig = GroundmaterialDao.Inst.GetCfg((uint)areaType); if (groundMatConfig == null) { return(Vector3.zero); } //摩擦系数 float u = groundMatConfig.Friction; //获取小球在该三角面的加速度 Vector3 acc = poly.GetAcceleration(velocity, 1, u); return(acc); }
/// <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); }
/// <summary> /// 求真实滚动点的速度 /// </summary> /// <param name="startPosition"></param> /// <param name="endPosition"></param> /// <param name="velocity"></param> /// <param name="areaType"></param> /// <param name="poly"></param> /// <param name="time"></param> /// <returns></returns> public Vector3 CalcRealRollVelocity(Vector3 startPosition, Vector3 endPosition, Vector3 velocity, AreaType areaType, GolfAIMapPolygon poly, float time, Vector3 acc, out float realTime) { Vector3 deltaPosition = endPosition - startPosition; //求真实的时间间隔,根据公式解一元二次方程,有两个值,取正值 realTime = (-velocity.x + Mathf.Sqrt(velocity.x * velocity.x - (4 * 0.5f * acc.x * (-deltaPosition.x)))) / (2 * 0.5f * acc.x); float vx = velocity.x + acc.x * realTime; float vy = velocity.y + acc.y * realTime; float vz = velocity.z + acc.z * realTime; Vector3 endVelocity = new Vector3(vx, vy, vz); //求与法线垂直方向的速度 Vector3 realVelocity = CalcTangentVelocity(endVelocity, poly.Normal); return(endVelocity); }
/// <summary> /// 计算下一个预测的滚动点 /// </summary> /// <param name="position"></param> /// <param name="velocity"></param> /// <param name="time"></param> /// <param name="areaType"></param> /// <param name="nextVelocity"></param> /// <returns></returns> public Vector3 CalcRollPoint(Vector3 position, Vector3 velocity, float time, AreaType areaType, GolfAIMapPolygon poly, ref Vector3 nextVelocity, ref Vector3 acc) { //速度方向校正,始终沿切线方向 Vector3 tangentVelocity = CalcTangentVelocity(velocity, poly.Normal); acc = GetRollAcceleration(tangentVelocity, areaType, poly); //切线方向x分量 nextVelocity.x = tangentVelocity.x + acc.x * time; position.x = position.x + tangentVelocity.x * time + 0.5f * acc.x * time * time; //切线方向y分量 nextVelocity.y = tangentVelocity.y + acc.y * time; position.y = position.y + tangentVelocity.y * time + 0.5f * acc.y * time * time; //切线方向z分量 nextVelocity.z = tangentVelocity.z + acc.z * time; position.z = position.z + tangentVelocity.z * time + 0.5f * acc.z * time * time; return(position); }
/// <summary> /// 设置三角形的父多边形 /// </summary> /// <param name="parent"></param> public void SetParent(GolfAIMapPolygon parent) { this.m_Parent = parent; }