예제 #1
0
파일: Renderer.cs 프로젝트: aologos/Citrus
        private static Rectangle CalcLocalScissorAABB(Matrix32 transform)
        {
            // Get the scissor rectangle in 0,0 - 1,1 coordinate space
            var vp = new Rectangle {
                A = new Vector2(viewport.X, viewport.Y),
                B = new Vector2(viewport.X + viewport.Width, viewport.Y + viewport.Height)
            };
            var r           = (Rectangle)(IntRectangle)scissorState.Bounds;
            var scissorRect = new Rectangle {
                A = (r.A - vp.A) / vp.Size,
                B = (r.B - vp.A) / vp.Size
            };

            // Transform it to the normalized OpenGL space
            scissorRect.A = scissorRect.A * 2 - Vector2.One;
            scissorRect.B = scissorRect.B * 2 - Vector2.One;
            // Get the unprojected coordinates
            var invProjection = Projection.CalcInverted();
            var v0            = invProjection.ProjectVector(scissorRect.A);
            var v1            = invProjection.ProjectVector(new Vector2(scissorRect.B.X, scissorRect.A.Y));
            var v2            = invProjection.ProjectVector(scissorRect.B);
            var v3            = invProjection.ProjectVector(new Vector2(scissorRect.A.X, scissorRect.B.Y));
            // Get coordinates in the widget space
            var invTransform = transform.CalcInversed();

            v0 = invTransform.TransformVector(v0);
            v1 = invTransform.TransformVector(v1);
            v2 = invTransform.TransformVector(v2);
            v3 = invTransform.TransformVector(v3);
            var aabb = new Rectangle {
                A = v0, B = v0
            }.
            IncludingPoint(v1).
            IncludingPoint(v2).
            IncludingPoint(v3);

            return(aabb);
        }