• 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.

  • 相关阅读:
    transitiondrawable ImageVIew切换动画
    Android硬件加速
    android PorterDuffXfermode ,PorterDuff.Mode 使用 以及Porter-Duff规则详解
    listview 打对号效果实现
    nrf52832 连接参数更新过程
    Makefile 学习记录一
    W25Q128BV W25Q128FV W25Q128JV 什么区别?
    lwip Packet buffers (PBUF) API 操作 集合
    NRF SDK 中 , C语言 的 一些骚操作 ,记录下
    lwip lwiperf 方法进行性能测试 4.5MB/S
  • 原文地址:https://www.cnblogs.com/sheshouyanhun/p/3427908.html
Copyright © 2020-2023  润新知