Beispiel #1
0
        //Vector2
        public void GetClosestPointToCell(Vector2 targetPos, out Vector3 closestPoint, out bool isOutsideCell)
        {
            float closestSqrDistance = float.MaxValue;

            closestPoint = Vector3.zero;

            foreach (var edgeData in _contentDictionary.Keys)
            {
                if (SomeMath.PointInTriangle(edgeData.leftV2, edgeData.rightV2, centerVector2, targetPos))
                {
                    closestPoint  = new Vector3(targetPos.x, SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerVector3, targetPos.x, targetPos.y), targetPos.y);
                    isOutsideCell = false;
                    return;
                }
                else
                {
                    Vector3 curInte;
                    SomeMath.ClosestToSegmentTopProjection(edgeData.leftV3, edgeData.rightV3, targetPos, true, out curInte);
                    float curSqrDist = SomeMath.SqrDistance(targetPos.x, targetPos.y, curInte.x, curInte.z);

                    if (curSqrDist < closestSqrDistance)
                    {
                        closestSqrDistance = curSqrDist;
                        closestPoint       = curInte;
                    }
                }
            }
            isOutsideCell = true;
            return;
        }
 //Vector2
 public bool GetPointInsideCell(Vector2 targetPos, out Vector3 result)
 {
     foreach (var edgeData in _contentDictionary.Keys)
     {
         if (SomeMath.PointInTriangle(edgeData.leftV2, edgeData.rightV2, centerV2, targetPos))
         {
             result = new Vector3(targetPos.x, SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerV3, targetPos.x, targetPos.y), targetPos.y);
             return(true);
         }
     }
     result = Vector3.zero;
     return(false);
 }
Beispiel #3
0
        /// <summary>
        /// check all cell triangles and return Y position if point inside of any triangle
        /// </summary>
        /// <param name="y">result Y if point inside cell</param>
        /// <returns>true if point inside cell</returns>
        public bool GetPointInsideCell(float x, float z, out float y)
        {
            CellContentData edgeData;

            foreach (var pair in _contentDictionary)
            {
                edgeData = pair.Key;
                if (SomeMath.PointInTriangle(centerVector2.x, centerVector2.y, edgeData.xLeft, edgeData.zLeft, edgeData.xRight, edgeData.zRight, x, z))
                {
                    y = SomeMath.CalculateHeight(edgeData.leftV3, edgeData.rightV3, centerVector3, x, z);
                    return(true);
                }
            }
            y = 0;
            return(false);
        }