DirectX Viewport transformation matrix in detail (derivation Viewportmatrix)

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/graphics/archive/2009/10/13/1582773.html


Viewport transformation after the projection transformation, the role of the viewport transformation is to convert the point on the projection plane to a point on the screen, which is a scaling process.

The function of the projection transform is to project the scene in the viewing frustum (visual body) to a plane, which is the projection plane, in DirectX, using the near clipping plane as the projection plane (z=1), The matrix solution of perspective projection, refer to the perspective projection detailed



The viewport transformation transforms the object in the cuboid into the viewport, as shown in the following figure.


Where the cuboid coordinate range is

The coordinate range of the viewport is

Note: From the figure above, the viewport starts with (X, Y), the width height is the width and the height,x axis to the right, the Y axis is positive, and the Y axis is opposite to the three-dimensional coordinates. The viewport is a 2D plane, but in the viewport transformation, the z-coordinate is also transformed, but not reflected in this figure.

First column of the transformation matrix is evaluated first

The upper-left corner of the cuboid (-1, 1, 0, 1) maps to the starting point in viewport (X, Y, MinZ, 1),

The upper-right corner of the cuboid (1, 1, 0, 1) maps to points in viewport (X+width, Y, MinZ, 1),

Suppose that the first column of the transformation matrix [x ', y ', z ', 1]t matrix multiplication has

[-1, 1, 0, 1]* [x ', y ', z ', 1]t = x

[1, 1, 0, 1]* [x ', y ', z ', 1]t = X+width

The corresponding two equations are

-1*x ' + 1*y ' + 0*z ' + 1*w ' = X

1*x ' + 1*y ' + 0*z ' + 1*w ' = X+width

The solution.

X ' = WIDTH/2

Y ' = 0

Z ' = 0

W ' = x + WIDTH/2

Second column, please.

The column equation (omitted here x ', Z ', but the result is unchanged, the same as the same)

Y ' + 1*w ' =y

-1*y ' + 1*w ' =y+height

The solution.

Y ' =-HEIGHT/2

W ' = Y + HEIGHT/2

Finally, we ask for the third column

Column equation

0*z ' + 1*w ' = MinZ

1*z ' + 1*w ' = MaxZ

The solution.

Z ' = Maxz–minz

W ' = MinZ

Combine the above columns to get the viewport transformation matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.