zoukankan      html  css  js  c++  java
  • The Viewport Transformation

    英文帖子链接http://glasnost.itcarlow.ie/~powerk/GeneralGraphicsNotes/projection/viewport_transformation.html

    抽空翻译一下,先记录下来备用

    The Viewport Transformation

    The final stage of the vertex transformation process is to map the points from the normalized view volume to their final position in the viewport on screen. We want to transform the view volume to the shape and position of the viewport.

    The normalised view volume is a cube centred on the origin, bounded by points (1,1,1) and (1,1,1). The u and v coordinates of each point will be transformed to x and y screen coordinates (pixel coordinates) and we will scale the n coordinates (pseudo-depth) to a range between 0 and 1 (scale the front plane to 0 and the back plane to 1), this depth value will be called z.

    The x,y sceen coordinates wil be used to draw the pixel in the refresh buffer. The z value will be stored in the depth buffer for hidden surface removal.

    The viewport transformation will be represented by a 4x4 matrix. It encapsulates 2 stages

    1. a scaling to the shape of the viewport
    2. a transformation to the position of the viewport

    The viewport is defined as the rectangle between (vl,vb) and (vr,vt)

    The view-volume needs to be scaled to the width and height of the viewport. At this stage we will also scale the pseudo-depth to a range of 0 to 1. The normalised view volume has a height, width and depth of 2.

    The width of the viewport is vrvl and the height of the view port is vtvb

    To scale a value from one range of values to another, we divide by the size of the original range and multiply by the size of the new range.

    Compare this process to the normalization transformation

    Therefore the scaling matrix required is;

    Sˆ=vrvl20000vtvb200001200001

    Finally we need to translate the scaled normalised view volume to the position of the viewport. This is a combination of two translations; first translate to the origin (add vrvl2 to u and add vtvb2 to v. Second move from the origin to the position of the viewport (add vl and vb to u and v). The n-coordinate (now in the range {1212}) needs to be shifted by +12

    Note; vrvl2+vl=vr+vl2, similarly the translation for v is vt+vb2.

    So the translation matrix is;

    Tˆ=100001000010vr+vl2vt+vb2121

    Combining the above two transfomations gives us the Viewport Transformation Matrix;

    Vpˆ=TˆSˆ=vrvl20000vtvb20000120vr+vl2vt+vb2121

    Aspect Ratio

    The aspect ratio is the relationship of the width of the viewport to its height widthheight, this is sometimes written as width:height as in 4:3 or 16:9.

    It is important that the aspect ratio of the viewport is the same as the aspect ratio of the viewvolume in order to avoid distortion.

    Viewport Transformation in OpenGL

    In OpenGL the viewport transformation is controlled by the function glViewPort()which is used to set the size and position of the viewport.

  • 相关阅读:
    colormap
    tensorflow4
    tensorflow3
    attention 机制
    tensorflow2
    Android 再谈handler
    Android表格布局之设置边框
    Android AsyncTask异步加载WebAPI
    Android JPush极光推送应用
    Android规划周期任务
  • 原文地址:https://www.cnblogs.com/sheshouyanhun/p/3427908.html
Copyright © 2011-2022 走看看