Пример #1
0
        /// <summary>
        /// Zooms the camera in or out.
        /// </summary>
        /// <param name="zoomIn">Whether to zoom the camera in or out.</param>
        public void ZoomCamera(bool zoomIn)
        {
            if (zoomIn)
            {
                // Keeps from zooming in too far.
                if (zoom > 0.2f)
                {
                    zoom -= zoom * 0.05f;                       // decreses the zoom by 10%
                }
            }
            else
            {
                zoom += zoom * 0.05f;                   // increases the zoom by 10%
            }

            // Sets the camera position to the origin point, then zooms in/out and offsets the camera.
            position -= offset;
            position.Normalize();
            position  = position = Vector3.Multiply(position, zoom);
            position += offset;

            projection = Matrix.PerspectiveFovRH((float)(Math.PI / 4), width / height, zoom / 100.0f, float.MaxValue);
            view       = Matrix.LookAtRH(position, target, upVector);

            // Updates the camera's position.
            device.SetTransform(TransformType.View, view);
            device.SetTransform(TransformType.Projection, projection);
        }
Пример #2
0
        /// <summary>
        /// Sets up the camera's perspective and view.
        /// </summary>
        /// <param name="width">The width of the panel being used.</param>
        /// <param name="height">The height of the panel being used.</param>
        public void SetCamera(float width, float height)
        {
            this.width  = width;
            this.height = height;

            projection = Matrix.PerspectiveFovRH((float)(Math.PI / 4), width / height, 2.0f, 100000000.0f);
            view       = Matrix.LookAtRH(position, target, upVector);

            device.SetTransform(TransformType.Projection, projection);
            device.SetTransform(TransformType.View, view);
        }
Пример #3
0
        /// <summary>
        /// Zooms the camera to a set value.
        /// </summary>
        /// <param name="zoomValue"></param>
        public void ZoomCamera(float zoomValue)
        {
            zoom = zoomValue;

            // Sets the camera position to the camAngle(normalized) then zooms in/out and offsets the camera and target.
            position.Normalize();
            position  = Vector3.Multiply(position, zoom);
            position += offset;
            target   += offset;

            projection = Matrix.PerspectiveFovRH((float)(Math.PI / 4), width / height, zoom / 100.0f, float.MaxValue);
            view       = Matrix.LookAtRH(position, target, upVector);

            // Updates the camera's position.
            device.SetTransform(TransformType.View, view);
            device.SetTransform(TransformType.Projection, projection);
        }