예제 #1
0
        public static bool LineCast(Vector3 _origin, Vector3 _end, ref VLSRayHit _hitInfo)
        {
            //rHit2D = Physics2D.Linecast(_origin, _end);

            //if (rHit2D.collider != null)
            //{
            //    _hitInfo.point = rHit2D.point;
            //    return true;
            //}
            //else
            //{
            //    _hitInfo.point = _end;
            //    return false;
            //}

            lc_outPnt.Set(0, 0, 0);    // = Vector3.zero;
            _hitInfo.sqrDist = Mathf.Infinity;
            lc_curDist       = 0;
            lc_Intersects    = false;

#if UNITY_EDITOR
            if (VLSDebug.IsModeActive(VLSDebugMode.Raycasting))
            {
                Debug.DrawLine(_origin, _end, new Color(.2f, .2f, .2f, .2f));
            }
#endif

            for (int e = 0; e < visibleEdges.Count; e++)
            {
                if (LineIntersects(visibleEdges[e].PointA.position, visibleEdges[e].PointB.position, _origin, _end, ref lc_outPnt))
                {
                    lc_curDist = Vector3.SqrMagnitude(lc_outPnt - _origin);

                    if (lc_curDist < _hitInfo.sqrDist)
                    {
                        _hitInfo.sqrDist = lc_curDist;
                        _hitInfo.point.Set(lc_outPnt.x, lc_outPnt.y, lc_outPnt.z);    // +(Vector3)(-edge.Normal);
                        //_hitInfo.obstructor = edge.Parent as VLSObstructor;
                        lc_Intersects = true;
                    }
                }
            }

            if (!lc_Intersects)
            {
                _hitInfo.point = _end;
                //_hitInfo.obstructor = null;
            }

            //_hitInfo.direction = (_hitInfo.point - _origin).normalized;

#if UNITY_EDITOR
            if (VLSDebug.IsModeActive(VLSDebugMode.Raycasting))
            {
                Debug.DrawLine(_origin, _hitInfo.point, new Color(.8f, .8f, .2f, .8f));
            }
#endif

            return(lc_Intersects);
        }
예제 #2
0
        public static bool LineCast(Vector3 _origin, Vector3 _end, ref VLSRayHit _hitInfo)
        {
            //rHit2D = Physics2D.Linecast(_origin, _end);

            //if (rHit2D.collider != null)
            //{
            //    _hitInfo.point = rHit2D.point;                
            //    return true;
            //}
            //else
            //{
            //    _hitInfo.point = _end;
            //    return false;
            //}

                lc_outPnt.Set(0, 0, 0);// = Vector3.zero;
                _hitInfo.sqrDist = Mathf.Infinity;
                lc_curDist = 0;
                lc_Intersects = false;

#if UNITY_EDITOR
                if (VLSDebug.IsModeActive(VLSDebugMode.Raycasting))
                    Debug.DrawLine(_origin, _end, new Color(.2f, .2f, .2f, .2f));
#endif

                for (int e = 0; e < visibleEdges.Count; e++)
                {
                    if (LineIntersects(visibleEdges[e].PointA.position, visibleEdges[e].PointB.position, _origin, _end, ref lc_outPnt))
                    {
                        lc_curDist = Vector3.SqrMagnitude(lc_outPnt - _origin);

                        if (lc_curDist < _hitInfo.sqrDist)
                        {
                            _hitInfo.sqrDist = lc_curDist;
                            _hitInfo.point.Set(lc_outPnt.x, lc_outPnt.y, lc_outPnt.z);// +(Vector3)(-edge.Normal);
                            //_hitInfo.obstructor = edge.Parent as VLSObstructor;
                            lc_Intersects = true;
                        }
                    }
                }

                if (!lc_Intersects)
                {
                    _hitInfo.point = _end;
                    //_hitInfo.obstructor = null;
                }

                //_hitInfo.direction = (_hitInfo.point - _origin).normalized;

#if UNITY_EDITOR
                if (VLSDebug.IsModeActive(VLSDebugMode.Raycasting))
                    Debug.DrawLine(_origin, _hitInfo.point, new Color(.8f, .8f, .2f, .8f));
#endif
                
            return lc_Intersects;
        }
예제 #3
0
 public static bool RayCast(Vector3 _origin, Vector3 _towards, ref VLSRayHit _hitInfo)
 {
     return(LineCast(_origin, _origin + (_towards - _origin) * 1000, ref _hitInfo));
 }
예제 #4
0
 public static bool RayCast(Vector3 _origin, Vector3 _towards, ref VLSRayHit _hitInfo)
 {
     return LineCast(_origin, _origin + (_towards - _origin) * 1000 , ref _hitInfo);
 }