Exemple #1
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);
                                }
                            }
                        }
                    }
                }
            }
        }