Translation matrix of 3D World coordinates mapped to 2D screen coordinates under the D3D coordinate system

Source: Internet
Author: User

D3D coordinate system under the 3D world coordinates mapped to 2D screen coordinates of the translation matrix, there is a need for friends to refer to.

D3D 3D model is basically based on 3 matrix world, view, projection to the model location positioning, perspective positioning and perspective deformation, and 2D to draw a graph only need to give a pixel coordinate on the screen to be able to locate a very big difference. On some occasions, we want to draw a 3D model based on the pixel coordinates on the screen, which can be easily drawn by using orthographic projection instead of perspective projection, but in some extremely special cases we want to have the 3D model that we have drawn to maintain all the transformations of the 3 matrices that we originally specified. This requires the 3 matrix and the target pixel counter to find a translation matrix, this article is about how to do.

Let's start with a brief introduction to how the 3D space coordinates in the D3D are converted to the screen coordinates without any changes. The spatial coordinates of the D3D in the 3 axis range are [ -1,1],d3d painting to the 2D screen area called Viewport,viewport the horizontal axis range is [left, right], the ordinate range is [Top, Bottom],viewport and near Point ( Near) and the distance (FAR) 2 values represent the z-axis, then the x-coordinate of a point SP (z/y) in d3d space coordinates xsp corresponds to the x-coordinate of the on-screen coordinate SC (x, y) xsc the corresponding formula is (this detailed explanation is on the net, no longer repeat here):
Xsc−leftright−left =xsp− (−1) 1− (−1) \dfrac{xsc−left}{right−left}=\dfrac{xsp− (−1)}{1− (−1)}
Let width = right-left, the above formula will eventually become:
Xsc= (xsp+1) ∗width2+left
Also draw the Y axis:
Ysc= (ysp+1) ∗height2+top
Z-Axis (although there is no z-coordinate on the screen, but this is given for the sake of the subsequent derivation of the uniform processing):
Zsc=zsp∗ (far−near) +near

Next, simply say the homogeneous coordinates, the D3D system used coordinates are not just (x, Y, z), but with 4-dimensional coordinates (X,Y,Z,W) to represent, here the homogeneous coordinates and 3-dimensional coordinates of the conversion relationship is:
⎡⎣⎢⎢⎢xyzw⎤⎦⎥⎥⎥=⎡⎣⎢⎢⎢⎢x/wy/wz/w1⎤⎦⎥⎥⎥⎥\left[\begin{array} {c} x \ y \ \ z \ W \end{array} \right ] = \left[\begin{array} {c} x/w \ y/w \ z/w \ 1 \end{array} \right]

That is, the homogeneous coordinates of each item is divided by the W, this process is called the homogeneous coordinate normalization (Normalize) can also be called normalization, the coordinates obtained is normalized coordinates, of course, it is important to note that when the homogeneous coordinates of the vector w=0, this time do not have to remove the W, the vector represents the coordinates, that is, when w= 0 o'clock do not have to do any processing. Finally, the function of W, w from the painting results is essentially a nonlinear deformation, perspective projection is the use of W to transform.

The homogeneous coordinates are obtained by multiplying a normalized 3-D coordinate with a transformation matrix, because D3D is left-handed, and the transform matrix is a 4x4 matrix using the left-hand coordinate of the transformation matrix:
⎡⎣⎢⎢⎢xyz1⎤⎦⎥⎥⎥∗⎡⎣⎢⎢⎢m11m12m13m14 M21M22M23

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.