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; }
public XZGridRayHit(Ray ray, XZGridCell hitCell, float hitEnter) { _hitCell = hitCell; _hitEnter = hitEnter; _hitPoint = ray.GetPoint(hitEnter); _hitPlane = hitCell.ParentGrid.WorldPlane; _hitNormal = _hitPlane.normal; }
public XZGridRayHit RaycastSceneGridIfVisible(Ray ray) { if (!RTSceneGrid.Get.Settings.IsVisible) { return(null); } float t; if (RTSceneGrid.Get.Raycast(ray, out t)) { XZGridCell hitCell = RTSceneGrid.Get.CellFromWorldPoint(ray.GetPoint(t)); return(new XZGridRayHit(ray, hitCell, t)); } return(null); }
public XZGridCell CellFromWorldPoint(Vector3 worldPoint) { return(XZGridCell.FromPoint(worldPoint, _settings.CellSizeX, _settings.CellSizeZ, this)); }