private void RotateTargetsAroundAnchor() { IInputDevice inputDevice = RTInputDevice.Get.Device; if (!inputDevice.WasMoved()) { return; } float rotationAmount = inputDevice.GetFrameDelta().x *SharedSettings.RotationSensitivity; foreach (GrabTarget grabTarget in _grabTargets) { if (grabTarget == null) { continue; } ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer); if (layerGrabSettings.IsActive) { if (layerGrabSettings.AlignAxis) { Quaternion rotation = Quaternion.AngleAxis(rotationAmount, _grabSurfaceInfo.AnchorNormal); grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint); grabTarget.AnchorVector = rotation * grabTarget.AnchorVector; } else { Quaternion rotation = Quaternion.AngleAxis(rotationAmount, Vector3.up); grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint); grabTarget.AnchorVector = rotation * grabTarget.AnchorVector; } } else { if (SharedSettings.AlignAxis) { Quaternion rotation = Quaternion.AngleAxis(rotationAmount, _grabSurfaceInfo.AnchorNormal); grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint); grabTarget.AnchorVector = rotation * grabTarget.AnchorVector; } else { Quaternion rotation = Quaternion.AngleAxis(rotationAmount, Vector3.up); grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint); grabTarget.AnchorVector = rotation * grabTarget.AnchorVector; } } } SnapTargetsToSurface(); }
private void OffsetTargetsFromSurface() { IInputDevice inputDevice = RTInputDevice.Get.Device; if (!inputDevice.WasMoved()) { return; } float offsetAmount = inputDevice.GetFrameDelta().x *SharedSettings.OffsetFromSurfaceSensitivity; foreach (GrabTarget grabTarget in _grabTargets) { if (grabTarget == null) { continue; } ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer); if (layerGrabSettings.IsActive) { if (layerGrabSettings.AlignAxis) { grabTarget.Transform.position += grabTarget.SittingPlane.normal * offsetAmount; grabTarget.OffsetFromSurface += offsetAmount; } else { grabTarget.Transform.position += Vector3.up * offsetAmount; grabTarget.OffsetFromSurface += offsetAmount; } } else { if (SharedSettings.AlignAxis) { grabTarget.Transform.position += grabTarget.SittingPlane.normal * offsetAmount; grabTarget.OffsetFromSurface += offsetAmount; } else { grabTarget.Transform.position += Vector3.up * offsetAmount; grabTarget.OffsetFromSurface += offsetAmount; } } } CalculateGrabTargetsAnchorVectors(); }
private void RotateTargets() { IInputDevice inputDevice = RTInputDevice.Get.Device; if (!inputDevice.WasMoved()) { return; } float rotationAmount = inputDevice.GetFrameDelta().x *SharedSettings.RotationSensitivity; foreach (GrabTarget grabTarget in _grabTargets) { if (grabTarget == null) { continue; } ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer); if (layerGrabSettings.IsActive) { if (layerGrabSettings.AlignAxis) { grabTarget.Transform.Rotate(grabTarget.SittingPlane.normal, rotationAmount, Space.World); } else { grabTarget.Transform.Rotate(Vector3.up, rotationAmount, Space.World); } } else { if (SharedSettings.AlignAxis) { grabTarget.Transform.Rotate(grabTarget.SittingPlane.normal, rotationAmount, Space.World); } else { grabTarget.Transform.Rotate(Vector3.up, rotationAmount, Space.World); } } } CalculateGrabTargetsAnchorVectors(); }
protected override void CalculateDragValues() { IInputDevice inputDevice = RTInputDevice.Get.Device; Vector2 inputDeviceDelta = inputDevice.GetFrameDelta(); _relativeRotation0 = Vector2.Dot(inputDeviceDelta, _workData.ScreenAxis0) * Sensitivity; _relativeRotation1 = Vector2.Dot(inputDeviceDelta, _workData.ScreenAxis1) * Sensitivity; if (_relativeRotation0 == 0.0f && _relativeRotation1 == 0.0f) { _relativeDragRotation = Quaternion.identity; return; } if (CanSnap()) { _accumSnapDrag0 += _relativeRotation0; _accumSnapDrag0 %= 360.0f; _accumSnapDrag1 += _relativeRotation1; _accumSnapDrag1 %= 360.0f; if (_workData.SnapMode == GizmoSnapMode.Absolute && _adjustRotationForAbsSnap) { NumSnapSteps numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep0, _totalRotation0); float oldRotation = _totalRotation0; if (numSnapSteps.AbsFracSteps < 0.5f) { _totalRotation0 = numSnapSteps.AbsIntNumSteps * _workData.SnapStep0 * Mathf.Sign(_totalRotation0); } else { _totalRotation0 = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep0 * Mathf.Sign(_totalRotation0); } _accumSnapDrag0 = 0.0f; _relativeRotation0 = _totalRotation0 - oldRotation; numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep1, _totalRotation1); oldRotation = _totalRotation1; if (numSnapSteps.AbsFracSteps < 0.5f) { _totalRotation1 = numSnapSteps.AbsIntNumSteps * _workData.SnapStep1 * Mathf.Sign(_totalRotation1); } else { _totalRotation1 = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep1 * Mathf.Sign(_totalRotation1); } _accumSnapDrag1 = 0.0f; _relativeRotation1 = _totalRotation1 - oldRotation; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0); _adjustRotationForAbsSnap = false; } else { _relativeDragRotation = Quaternion.identity; if (SnapMath.CanExtractSnap(_workData.SnapStep0, _accumSnapDrag0)) { _relativeRotation0 = SnapMath.ExtractSnap(_workData.SnapStep0, ref _accumSnapDrag0); _totalRotation0 += _relativeRotation0; _totalRotation0 %= 360.0f; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0); } if (SnapMath.CanExtractSnap(_workData.SnapStep1, _accumSnapDrag1)) { _relativeRotation1 = SnapMath.ExtractSnap(_workData.SnapStep1, ref _accumSnapDrag1); _totalRotation1 += _relativeRotation1; _totalRotation1 %= 360.0f; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * _relativeDragRotation; } } } else { _adjustRotationForAbsSnap = true; _accumSnapDrag0 = _accumSnapDrag1 = 0.0f; _totalRotation0 += _relativeRotation0; _totalRotation1 += _relativeRotation1; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0); } _totalDragRotation = _relativeDragRotation * _totalDragRotation; }
protected override void CalculateDragValues() { IInputDevice inputDevice = RTInputDevice.Get.Device; _relativeRotation = Vector2.Dot(_screenDragCircleTangent, inputDevice.GetFrameDelta()) * Sensitivity; if (_relativeRotation == 0.0f) { _relativeDragRotation = Quaternion.identity; return; } if (CanSnap()) { _accumSnapDrag += _relativeRotation; _accumSnapDrag %= 360.0f; if (_workData.SnapMode == GizmoSnapMode.Absolute && _adjustRotationForAbsSnap) { NumSnapSteps numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep, _totalRotation); float oldRotation = _totalRotation; if (numSnapSteps.AbsFracSteps < 0.5f) { _totalRotation = numSnapSteps.AbsIntNumSteps * _workData.SnapStep * Mathf.Sign(_totalRotation); } else { _totalRotation = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep * Mathf.Sign(_totalRotation); } _relativeRotation = _totalRotation - oldRotation; _accumSnapDrag = 0.0f; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation, _workData.Axis); _adjustRotationForAbsSnap = false; } else if (SnapMath.CanExtractSnap(_workData.SnapStep, _accumSnapDrag)) { _relativeRotation = SnapMath.ExtractSnap(_workData.SnapStep, ref _accumSnapDrag); _totalRotation += _relativeRotation; _totalRotation %= 360.0f; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation, _workData.Axis); } else { _relativeDragRotation = Quaternion.identity; } } else { _accumSnapDrag = 0.0f; _adjustRotationForAbsSnap = true; _totalRotation += _relativeRotation; _totalRotation %= 360.0f; _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation, _workData.Axis); } _totalDragRotation = Quaternion.AngleAxis(_totalRotation, _workData.Axis); }