void IInputReceiver.OnInputUpdate(float timeStep, IInputPermissions inputPermissions) { if (EnabledEffective) { MoveNode(timeStep, inputPermissions); } }
void OnInputUpdate(float timeStep, IInputPermissions inputPermissions, string key) { if (EnabledEffective) { MoveNode(timeStep, inputPermissions, key); } }
void IInputReceiver.OnInputUpdate(float timeStep, IInputPermissions inputPermissions) { if (EnabledEffective && !_selectedButton) { MoveServo(inputPermissions); } }
void ProcessSelection(IInputPermissions inputPermissions) { var input = _app.Input; //unselect on mouse up if (_selection != null && _selectionArg != null && !_selectionArg.LockSelectionUntilClick) { if (!input.GetMouseDownOrTouching(out var delta)) { TrySetSelection(null, null); //unselect } } //validate if (!inputPermissions.CanUseMouse) { return; } var ray = GetMouseOver(_camera, _octree, _app); ISelectable selectable = null; if (ray != null && ray.Value.Node != null) { try { selectable = ray.Value.Node.Components.OfType <ISelectable>().FirstOrDefault(); } catch { } } //mouse over TrySetMouseOver((Selection == null) ? selectable : null, ray); //mouse click if (input.GetMouseClickOrTouch()) { //if currently has locked selection then release it if (Selection != null && _selectionArg != null && _selectionArg.LockSelectionUntilClick) { if (TrySetSelection(null, null)) //unselect { return; } } //select it, if its selectable if (selectable != null) { if (TrySetSelection(selectable, ray)) { return; } } //bug fix - set window focus _uiSuportWindow?.SetFocus(); } }
private void MoveNode(float timeStep, IInputPermissions inputPermissions) { var input = Application.Input; if (inputPermissions.CanUseKeyboard) { using (var n = new Node()) { n.SetDirection(_plane.Normal); if (input.GetKeyDown(Key.W)) { n.Translate(Vector3.UnitY * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.S)) { n.Translate(-Vector3.UnitY * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.A)) { n.Translate(Vector3.UnitX * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.D)) { n.Translate(-Vector3.UnitX * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.C)) { n.Translate(Vector3.UnitZ * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.E)) { n.Translate(-Vector3.UnitZ * MoveSpeed * timeStep, TransformSpace.Local); } var move = n.Position; Node.Translate(move, TransformSpace.Local); } } //move by mouse var mousePos = input.GetMousePositionOrTouchPosition(_usingTouch); if (_prevMousePos != mousePos) { _prevMousePos = mousePos; if (inputPermissions.CanUseMouse) { var camera = (Application as App).CameraNode.GetComponent <Camera>(); var graphics = Application.Graphics; Ray ray = camera.GetScreenRay((float)mousePos.X / graphics.Width, (float)mousePos.Y / graphics.Height); var dist = ray.HitDistance(_plane); var pos = (ray.Direction * dist) + ray.Origin; Node.Position = pos + _offset; } } }
private void MoveServo(IInputPermissions inputPermissions) { //validate if (!inputPermissions.CanUseMouse) { return; } //get diffrence var currentMousePosition = Application.Input.GetMousePositionOrTouchPosition(_usingTouch); var knob = GetKnob(); var mouseDiff = IntVector2.Subtract(_mousePosition, currentMousePosition); var dif = ((float)mouseDiff.Y) * .1f; var newPos = _origKnobPos + dif; newPos = MathHelper.Clamp(newPos, -8000f, 8000f); var newPosInt = (int)Math.Round(newPos); //move knob in sim if (knob.Position != newPosInt) { knob.Position = newPosInt; } }
void IInputReceiver.RevokedInputControl(IInputPermissions inputPermissions) { }
void IInputReceiver.ReceivedInputControl(IInputPermissions inputPermissions) { inputPermissions.RequestExclusiveMouse = true; inputPermissions.RequestExclusiveKeyboard = true; }
void IInputReceiver.OnInputUpdate(float timeStep, IInputPermissions inputPermissions) { _transformGimbal.OnInputUpdate(timeStep, inputPermissions, _key); }
private void MoveNode(float timeStep, IInputPermissions inputPermissions, string key) { var prevPos = Node.Position; //move by keyboard var input = Application.Input; if (inputPermissions.CanUseKeyboard) { if (input.GetKeyDown(Key.W)) { Node.Translate(Vector3.UnitZ * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.S)) { Node.Translate(-Vector3.UnitZ * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.A)) { Node.Translate(-Vector3.UnitX * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.D)) { Node.Translate(Vector3.UnitX * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.C)) { Node.Translate(-Vector3.UnitY * MoveSpeed * timeStep, TransformSpace.Local); } if (input.GetKeyDown(Key.E)) { Node.Translate(Vector3.UnitY * MoveSpeed * timeStep, TransformSpace.Local); } } //move by mouse var mousePos = input.GetMousePositionOrTouchPosition(_usingTouch); if (_prevMousePos != mousePos) { _prevMousePos = mousePos; if (inputPermissions.CanUseMouse) { var camera = (Application as App).CameraNode.GetComponent <Camera>(); var graphics = Application.Graphics; Ray ray = camera.GetScreenRay((float)mousePos.X / graphics.Width, (float)mousePos.Y / graphics.Height); var dist = ray.HitDistance(_plane); var pos = (ray.Direction * dist) + ray.Origin; pos = pos + _offset; //constrain to selected axes switch (key) { case "x": pos = new Vector3(pos.X, Node.Position.Y, Node.Position.Z); break; case "y": pos = new Vector3(Node.Position.X, pos.Y, Node.Position.Z); break; case "z": pos = new Vector3(Node.Position.X, Node.Position.Y, pos.Z); break; } Node.Position = pos; } } //fire event if (prevPos != Node.Position) { ChangedPosition?.Invoke(this, new TranformGizmoEventArgs() { X = Node.Position.X, Y = Node.Position.Y, Z = Node.Position.Z }); } }
void IInputReceiver.OnInputUpdate(float timeStep, IInputPermissions inputPermissions) { ProcessSelection(inputPermissions); }
void IInputReceiver.ReceivedInputControl(IInputPermissions inputPermissions) { _inputPermissions = inputPermissions; }
void IInputReceiver.OnInputUpdate(float timeStep, IInputPermissions inputPermissions) { if (!inputPermissions.CanUseMouse) { _transition = true; return; } var input = Application.Input; //create helper nodes if (_orbitTarget == null) { _orbitTarget = Scene.CreateChild("orbitTarget"); _camera = _orbitTarget.CreateChild("orbitCamera"); //setup auto distance too var body = Node.GetOrCreateComponent <RigidBody>(); var collide = Node.GetOrCreateComponent <CollisionShape>(); collide.SetSphere(5, Vector3.Zero, Quaternion.Identity); body.Trigger = true; body.Mass = 1; body.Kinematic = true; Node.NodeCollisionStart += Camera_NodeCollisionStart; } //get target pos if (AutoCenter || _targetPosition == null || _targetPosition == Vector3.Zero) { _targetPosition = GetTargetBoundingBox()?.Center ?? new Vector3(); } //set distance if (_transitionDistance == null) { Distance = Vector3.Distance(_targetPosition, Node.Position); } //change distance input.GetMouseWheelOrPinch(out var wheel); Distance -= MoveSpeed * wheel * 1f; Distance = MathHelper.Clamp(Distance, _distanceMin, _distanceMax); var cameraRotation = Node.GetOrCreateComponent <CameraRotation>(); if (input.GetMouseDownOrTouching(out var mouseMove)) { inputPermissions.RequestExclusiveMouse = true; _transition = false; //change rotation cameraRotation.Yaw += MouseSensitivity * mouseMove.X; cameraRotation.Pitch += MouseSensitivity * mouseMove.Y; cameraRotation.Pitch = MathHelper.Clamp(cameraRotation.Pitch, _minPitch, 90); } else { inputPermissions.RequestExclusiveMouse = false; } //set rotation Node.Rotation = new Quaternion(cameraRotation.Pitch, cameraRotation.Yaw, 0); //calculate position _orbitTarget.Position = _targetPosition; _orbitTarget.Rotation = new Quaternion(cameraRotation.Pitch, cameraRotation.Yaw, 0); _camera.Position = new Vector3(0, 0, -Distance); //set position if (_transition && AutoCenter) { //transition target var speed = MathHelper.Clamp(.1668f * timeStep, .1f, 1); Node.SetWorldPosition(Vector3.Lerp(Node.Position, _camera.WorldPosition, speed)); if (_transitionDistance != null) { Distance = MathHelper.Lerp(Distance, _transitionDistance.Value, speed); } if (_transitionPitch != null) { cameraRotation.Pitch = MathHelper.Lerp(cameraRotation.Pitch, _transitionPitch.Value, speed); } if (_transitionYaw != null) { cameraRotation.Yaw = MathHelper.Lerp(cameraRotation.Yaw, _transitionYaw.Value, speed); } //transition is complete if ((Node.Position - _camera.WorldPosition).Length < .05f) { _transition = false; } } else { Node.SetWorldPosition(_camera.WorldPosition); if (_transitionDistance != null) { Distance = _transitionDistance.Value; _transitionDistance = null; } if (_transitionPitch != null) { cameraRotation.Pitch = _transitionPitch.Value; _transitionPitch = null; } if (_transitionYaw != null) { cameraRotation.Yaw = _transitionYaw.Value; _transitionYaw = null; } } //set min pitch if (Floor != null) { var angleToFloor = MathHelper.RadiansToDegrees((float)Math.Atan((_orbitTarget.WorldPosition.Y - Floor.WorldPosition.Y - 2f) / Distance)); _minPitch = MathHelper.Clamp(-angleToFloor, -90, 0); } }
void MoveCamera(float timeStep, IInputPermissions inputPermissions) { var input = Application.Input; var moveSpeed = MoveSpeed; if (Application.UI.FocusElement != null) { return; } if (inputPermissions.CanUseMouse) { if (CaptureMouse) { input.CenterMousePosition(); var cameraRotation = Node.GetOrCreateComponent <CameraRotation>(); var mouseMove = input.MouseMove; cameraRotation.Yaw += MouseSensitivity * mouseMove.X; cameraRotation.Pitch += MouseSensitivity * mouseMove.Y; Node.Rotation = new Quaternion(cameraRotation.Pitch, cameraRotation.Yaw, 0); //mouse click to exit if (input.GetMouseButtonPress(MouseButton.Left)) { CaptureMouse = false; } } else { //mouse click to capture if (input.GetMouseButtonPress(MouseButton.Left)) { CaptureMouse = true; } } //mouse wheel var wheel = input.MouseMoveWheel; Node.Translate(Vector3.UnitZ * moveSpeed * timeStep * wheel * 20f); } else { inputPermissions.MouseVisible = true; } if (inputPermissions.CanUseKeyboard) { if (input.GetKeyDown(Key.LeftShift)) { moveSpeed = moveSpeed / 10f; } if (input.GetKeyDown(Key.W)) { Node.Translate(Vector3.UnitZ * moveSpeed * timeStep); } if (input.GetKeyDown(Key.S)) { Node.Translate(-Vector3.UnitZ * moveSpeed * timeStep); } if (input.GetKeyDown(Key.A)) { Node.Translate(-Vector3.UnitX * moveSpeed * timeStep); } if (input.GetKeyDown(Key.D)) { Node.Translate(Vector3.UnitX * moveSpeed * timeStep); } if (input.GetKeyDown(Key.X)) { Node.Translate(-Vector3.UnitY * moveSpeed * timeStep); } if (input.GetKeyDown(Key.E)) { Node.Translate(Vector3.UnitY * moveSpeed * timeStep); } } }