예제 #1
0
        public ClosestPointToRetSplineResult CalcClosestPointOnRetSpline(Vector3 position)
        {
            ClosestPointToRetSplineResult retval = new ClosestPointToRetSplineResult();

            CalcClosestPointOnRetSpline(position, retval);
            return(retval);
        }
예제 #2
0
        public void Snap()
        {
            if (targetSpline == null)
            {
                Spline[] res = FindObjectsOfType<Spline>();
                if (res.Length == 1)
                    targetSpline = res[0];
            }

            if (targetSpline != null)
            {
                retPRes = targetSpline.CalcClosestPointOnRetSpline(transform.position);
                transform.position = retPRes.closestPoint;
            }
            else
            {
                Debug.LogError("SplineAnchor does not have a spline set");
            }
        }
예제 #3
0
        private void MakeClosestTo(Vector3 desiredPos)
        {
            numConsideredSplines = 0;
            if (splineJunctions.Count > 0)
            {
                //find closest among spline junctions
                ClosestPointToRetSplineResult res = null, curBest = null;
                Spline closestSpline = null;

                foreach (SplineJunction sj in splineJunctions)
                {
                    foreach (Spline s in sj.splines)
                    {
                        numConsideredSplines++;
                        res = s.CalcClosestPointOnRetSpline(desiredPos);

                        if (curBest == null || curBest.distSqrFromTarget > res.distSqrFromTarget)
                        {
                            curBest       = res;
                            closestSpline = s;
                        }
                    }
                }

                spline   = closestSpline;
                closeRes = curBest;
            }
            else if (spline != null)
            {
                closeRes = spline.CalcClosestPointOnRetSpline(desiredPos);
            }
            else
            {
                Debug.LogError("Cannot find closest when there are no splines");
                closeRes = null;
            }

            if (syncPosToResult && closeRes != null)
            {
                transform.position = closeRes.closestPoint;
            }
        }
예제 #4
0
        public ClosestPointToRetSplineResult CalcClosestPointOnRetSpline(Vector3 position, ClosestPointToRetSplineResult retval)
        {
            Vector3 temp = Vector3.zero, tempDif = Vector3.zero;
            float   dist = float.MaxValue;

            for (int i = 0; i < GetNumNodes(); i++)
            {
                for (int j = 0; j < GetNode(i).GetNumReticulatedSegments(); j++)
                {
                    ReticulatedSplineSegment seg = GetNode(i).GetReticulatedSegment(j);
                    temp    = AID.UTIL.ClosestPointToLine(seg.startPos, seg.endPos, position, true);
                    tempDif = temp - position;
                    if (dist > tempDif.sqrMagnitude)
                    {
                        //retval = temp;
                        dist = tempDif.sqrMagnitude;
                        retval.closestPoint      = temp;
                        retval.distSqrFromTarget = dist;
                        retval.retPos            = new SplineReticulatedPosition();

                        retval.retPos.splineNodeIndex      = i;  // = GetNode(i);
                        retval.retPos.retSeg               = j;  // = GetNode(i).GetReticulatedSegment(j);
                        retval.retPos.spline               = this;
                        retval.retPos.distanceFromRetStart = (temp - GetNode(i).reticulationPoints[j]).magnitude;
                    }
                }
            }

            return(retval);
        }