# Formula for affine transformation of RSSetViewports

This topic is 2255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

D3D function RSSetViewports plays the same role as glViewport. They all define an affine transformation that convert normalized device coordinates to viewport (window) coordinates. A explicit formula for glViewport is given at http://msdn.microsoft.com/en-us/library/dd374202(v=VS.85).aspx. It's
x_w = (x_ndc+1)*w/2 + x0
y_w = (y_ndc+1)*h/2 + y0
However, there is no formula given to RSSetViewports. I believe the same formula can be applied to RSSetViewports. Am I right?

##### Share on other sites
The formula is here:

 X = (X + 1) * Viewport.Width * 0.5 + Viewport.TopLeftX Y = (1 - Y) * Viewport.Height * 0.5 + Viewport.TopLeftY Z = Viewport.MinDepth + Z * (Viewport.MaxDepth - Viewport.MinDepth) 

Thanks a lot.

• 22
• 10
• 19
• 15
• 14