Exemplo n.º 1
0
        public static void PinchAndZoom(this Urho.Camera camera, TouchState fingerOne, TouchState fingerTwo, float min, float max)
        {
            float zoom = GetZoomAmountFromPinch(fingerOne, fingerTwo);

            if (zoom != 0)
            {
                bool reset2DPosition = false;
                // TODO: transform the precision depending on distance from screen to camera so
                // that the user can zoom in really closely with great precision
                float newPosition = camera.Node.Position.Z + (float)zoom;

                if (newPosition <= min)
                {
                    newPosition = min;

                    // We also need to reset panning (2D position)
                    // TODO: Handle a smooth transition hier
                    reset2DPosition = true;
                }
                else if (newPosition >= max)
                {
                    newPosition = max;
                }

                // NOTE: Is this marked as dirty and only updated in the update loop
                camera.Node.SetWorldPosition(new Vector3(reset2DPosition == true ? 0.0f : camera.Node.Position.X, reset2DPosition == true ? 0.0f : camera.Node.Position.Y, newPosition));
            }
        }
Exemplo n.º 2
0
        public GridScreenLayout(int itemCount, int columns, Urho.Camera camera)
        {
            Columns   = columns;
            Camera    = camera;
            ItemCount = itemCount;

            // TODO: Handle offset when panning
            Offset = 0;
        }
Exemplo n.º 3
0
        // TODO: Add initialization for float frameHeight, float frameWidth, float min
        public CameraScreen(DataModels.Camera camera, Node cameraNode)
        {
            Camera          = camera;
            this.cameraNode = cameraNode;
            urhoCamera      = cameraNode.GetComponent <Urho.Camera>();

            orientation = camera.Orientation;

            ReceiveSceneUpdates = true;

            // Set position in relation to the number of cameras that are already initialized
            // so the screens can be positioned accordingly
            position = screenCount + 1;
            screenCount++;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Pans a camera in both x- and y-direction
        /// </summary>
        /// <param name="camera">the camera to be panned</param>
        /// <param name="dx">the pan value in x-direction</param>
        /// <param name="dy">the pan value in y-direction</param>
        public static void Pan(this Urho.Camera camera, int dx, int dy, float precision = 0.005f, bool onZoom = true, float maxY = -99999, float minY = -99999, float maxX = -99999, float minX = -99999)
        {
            // Only pan if camera is zoomed
            if (!onZoom || camera.Zoom > 1)
            {
                float x = camera.Node.Position.X + -dx * precision;
                float y = camera.Node.Position.Y + dy * precision;

                // TODO: create an extension method to handle clamping of values
                if (maxY > -99999 && y > maxY)
                {
                    y = maxY;
                }

                if (minY > -99999 && y < minY)
                {
                    y = minY;
                }

                if (maxX > -99999 && x > maxX)
                {
                    x = maxX;
                }

                if (minX > -99999 && x < minX)
                {
                    x = minX;
                }

                Urho.Application.InvokeOnMain(() => camera.Node.SetPosition2D(new Vector2(x, y)));
            }
            else
            {
                // Reset camera position
                camera.Node.Position = new Vector3(0, 0, camera.Node.Position.Z);
            }
        }