Esempio n. 1
0
        /// <summary>
        /// Sets the screen spaced coordinates.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="deviceContext">The device context.</param>
        /// <param name="clearDepthBuffer">if set to <c>true</c> [clear depth buffer].</param>
        protected virtual void SetScreenSpacedCoordinates(RenderContext context, DeviceContextProxy deviceContext, bool clearDepthBuffer)
        {
            context.WorldMatrix = Matrix.Identity;
            DepthStencilView dsView;

            if (clearDepthBuffer)
            {
                deviceContext.GetDepthStencilView(out dsView);
                if (dsView == null)
                {
                    return;
                }

                deviceContext.ClearDepthStencilView(dsView, DepthStencilClearFlags.Depth, 1f, 0);
                dsView.Dispose();
            }
            IsRightHand = !context.Camera.CreateLeftHandSystem;
            float viewportSize = Size * SizeScale;
            var   globalTrans  = context.GlobalTransform;

            UpdateProjectionMatrix((float)context.ActualWidth, (float)context.ActualHeight);
            globalTrans.View           = CreateViewMatrix(context, out globalTrans.EyePos);
            globalTrans.Projection     = projectionMatrix;
            globalTrans.ViewProjection = globalTrans.View * globalTrans.Projection;
            globalTrans.Viewport       = new Vector4(viewportSize, viewportSize, 1f / viewportSize, 1f / viewportSize);
            globalTransformCB.UploadDataToBuffer(deviceContext, ref globalTrans);
            GlobalTransform = globalTrans;
            int offX = (int)(Width / 2 * (1 + RelativeScreenLocationX) - viewportSize / 2);
            int offY = (int)(Height / 2 * (1 - RelativeScreenLocationY) - viewportSize / 2);

            deviceContext.SetViewport(offX, offY, viewportSize, viewportSize);
            deviceContext.SetScissorRectangle(offX, offY, (int)viewportSize + offX, (int)viewportSize + offY);
        }