Ejemplo n.º 1
0
        private void RotateCamera(PulsarMessage message)
        {
            PulsarCamera camera = null;

            if (_renderSurface.InvokeRequired)
            {
                var delegateCameraRotate = new ThreadSafeCameraRotate(RotateCamera);
                _renderSurface.Invoke(delegateCameraRotate, new object[] { message });
            }
            else
            {
                //get the mouseDelta property from the message
                message.Properties.TryGetValue("mouseDelta", out object mouseDelta);
                if (mouseDelta != null)
                {
                    IntVector2 delta = (IntVector2)mouseDelta;
                    if (delta != null)
                    {
                        camera = _mainApplication.DisplayScene.SceneCamera;
                        if (camera != null)
                        {
                            //remove any Z component computed as a result of a previous 'Rotate' call
                            //fixes Z axis rotation to zero thus preventing camera roll
                            var cameraRotation = camera.Node.Rotation.ToEulerAngles();
                            cameraRotation.Z     = 0;
                            camera.Node.Rotation = new Quaternion(cameraRotation.X, cameraRotation.Y, cameraRotation.Z);
                            //do the desired rotation
                            camera.Node.Rotate(new Quaternion(delta.Y, delta.X, 0));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void PanCamera(PulsarMessage message)
        {
            PulsarCamera camera = null;

            if (_renderSurface.InvokeRequired)
            {
                var delegateCameraRotate = new ThreadSafeCameraPan(PanCamera);
                _renderSurface.Invoke(delegateCameraRotate, new object[] { message });
            }
            else
            {
                string keyPressed = "";
                //check if any constraint key is present
                message.Properties.TryGetValue("constrainKeyDown", out object constrainKeyPressed);
                bool keyDownFound = (constrainKeyPressed != null);
                if (keyDownFound)
                {
                    keyPressed = (string)constrainKeyPressed;
                }
                //get the mouseDelta property from the message
                message.Properties.TryGetValue("mouseDelta", out object mouseDelta);
                if (mouseDelta != null)
                {
                    IntVector2 delta = (IntVector2)mouseDelta;
                    if (delta != null)
                    {
                        camera = _mainApplication.DisplayScene.SceneCamera;
                        if (camera != null)
                        {
                            //only pan horizontally if there is no vertical constraint
                            if (!keyDownFound || keyPressed != "shift")
                            {
                                if (delta.X > 0)
                                {
                                    camera.Node.Translate(Vector3.Right * 3);
                                }
                                else if (delta.X < 0)
                                {
                                    camera.Node.Translate(Vector3.Left * 3);
                                }
                            }
                            //only pan vertically if there is no horizontal constraint
                            if (!keyDownFound || keyPressed != "ctrl")
                            {
                                if (delta.Y > 0)
                                {
                                    camera.Node.Translate(Vector3.Down * 3);
                                }
                                else if (delta.Y < 0)
                                {
                                    camera.Node.Translate(Vector3.Up * 3);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void AdjustZoom()
        {
            PulsarCamera mainCamera      = null;
            Component    cameraComponent = null;

            if (InvokeRequired)
            {
                Urho.Application.InvokeOnMain(AdjustZoom);
            }
            else
            {
                if (!Focused)
                {
                    return;
                }

                //get the main camera
                if (_mainApplication != null)
                {
                    if (_mainApplication.DisplayScene != null)
                    {
                        cameraComponent = _mainApplication.DisplayScene.Components.ToList().Find(camera => camera.Node.Name == "mainCamera");
                        if (cameraComponent != null)
                        {
                            mainCamera = (PulsarCamera)cameraComponent;
                            if (mainCamera == null)
                            {
                                return;
                            }
                        }
                    }
                }

                switch (_zoom)
                {
                case Zoom.In:
                    mainCamera.Camera.Fov -= 2.0f;
                    break;

                case Zoom.Out:
                    mainCamera.Camera.Fov += 2.0f;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private void AdjustZoom()
        {
            PulsarCamera camera = null;


            if (_renderSurface.InvokeRequired)
            {
                var delegateZoom = new ThreadSafeAdjustZoom(AdjustZoom);
                _renderSurface.Invoke(delegateZoom, Array.Empty <object>());
            }
            else
            {
                //get the main camera
                if (_mainApplication != null)
                {
                    if (_mainApplication.DisplayScene != null)
                    {
                        camera = _mainApplication.DisplayScene.SceneCamera;
                        if (camera == null)
                        {
                            return;
                        }
                    }
                }

                switch (_zoom)
                {
                case Zoom.In:
                    camera.Camera.Node.Translate(Vector3.Forward * 3, TransformSpace.Local);
                    break;

                case Zoom.Out:
                    camera.Camera.Node.Translate(Vector3.Forward * -3, TransformSpace.Local);
                    break;
                }
            }
        }