private void Snap()
        {
            Camera       camera       = RTFocusCamera.Get.TargetCamera;
            XZGridRayHit sceneGridHit = RTScene.Get.RaycastSceneGridIfVisible(RTInputDevice.Get.Device.GetRay(camera));

            if (sceneGridHit == null)
            {
                return;
            }

            List <Vector3> hitCellPoints = sceneGridHit.HitCell.GetCenterAndCorners();
            int            destPtIndex   = Vector3Ex.GetPointClosestToPoint(hitCellPoints, sceneGridHit.HitPoint);

            if (destPtIndex < 0)
            {
                return;
            }

            Vector3 snapDestination = hitCellPoints[destPtIndex];
            Vector3 snapVector      = (snapDestination - _snapPivotPoint);

            foreach (var targetParent in _targetParents)
            {
                if (targetParent == null)
                {
                    continue;
                }

                Transform targetParentTransform = targetParent.transform;
                targetParentTransform.position += snapVector;
            }

            _snapPivotPoint += snapVector;
        }
Beispiel #2
0
        protected override void CalculateDragValues()
        {
            Camera focusCamera = RTFocusCamera.Get.TargetCamera;

            _relativeDragOffset = Vector3.zero;

            if (_destinationObjects.Count != 0 && _settings.CanSnapToObjectVerts)
            {
                Vector3 worldDestPos;
                if (GetWorldPointClosestToInputDevice(focusCamera, _destinationObjects, out worldDestPos))
                {
                    _relativeDragOffset = worldDestPos - _snapPivot;
                }
            }
            else
            if (_settings.CanSnapToGrid)
            {
                Ray          ray     = RTInputDevice.Get.Device.GetRay(focusCamera);
                XZGridRayHit gridHit = RTScene.Get.RaycastSceneGridIfVisible(ray);
                if (gridHit != null)
                {
                    XZGridCell     gridCell          = RTSceneGrid.Get.CellFromWorldPoint(gridHit.HitPoint);
                    List <Vector3> centersAndCorners = gridCell.GetCenterAndCorners();
                    int            closestPtIndex    = Vector3Ex.GetPointClosestToPoint(centersAndCorners, gridHit.HitPoint);
                    if (closestPtIndex >= 0)
                    {
                        _relativeDragOffset = centersAndCorners[closestPtIndex] - _snapPivot;
                    }
                }
            }

            _snapPivot       += _relativeDragOffset;
            _totalDragOffset += _relativeDragOffset;
        }
Beispiel #3
0
        public SceneRaycastHit Raycast(Ray ray, SceneRaycastPrecision rtRaycastPrecision, SceneRaycastFilter raycastFilter)
        {
            List <GameObjectRayHit> allObjectHits    = RaycastAllObjectsSorted(ray, rtRaycastPrecision, raycastFilter);
            GameObjectRayHit        closestObjectHit = allObjectHits.Count != 0 ? allObjectHits[0] : null;
            XZGridRayHit            gridRayHit       = RaycastSceneGridIfVisible(ray);

            return(new SceneRaycastHit(closestObjectHit, gridRayHit));
        }
Beispiel #4
0
 public SceneRaycastHit(GameObjectRayHit objectRayHit, XZGridRayHit gridRayHit)
 {
     _objectHit = objectRayHit;
     _gridHit   = gridRayHit;
 }