CPT205 W4
This is the note of CPT205 Week5 Transformation Pipeline and Geometric Transformations
转换管道和几何转换
- Transformation pipeline 转换管道
- Standard transformations
- Translation 翻译
- Rotation 旋转
- Scaling 扩展
- Reflection 反射
- Shearing 剪切
- Homogeneous co-ordinate transformation matrices 齐次坐标变换矩阵
- Composite (arbitrary) transformation matrices from simple transformations 复合(任意)变换矩阵由简单变换
- OpenGL functions for transformations 转换的OpenGL函数
Lecture
Transformation pipeline 转换管道
- The Transformation Pipeline is the series of transformations (alterations) that must be applied to an object before it can be properly displayed on the screen. 转换管道是一系列转换(更改),在对象可以正确地显示在屏幕上之前,必须对其应用。
- The transformations can be thought of as a set of processing stages. If a stage is omitted, very often the object will not look correct. For example if the projection stage is skipped then the object will not appear to have any depth to it. 可以将转换视为一组处理阶段。如果省略了stage,对象通常看起来就不正确。
- Once an object has passed through the pipeline it is ready to be displayed as either a wire-frame item or as a solid item. 一旦对象通过了管道,就可以将其显示为线框项目或实体项目。
- Modelling Transformation - to place an object into the Virtual World. 建模转换:将一个对象放入虚拟世界。
- Viewing Transformation - to view the object from a different vantage point in the virtual world. 观察变换-从虚拟世界的不同角度观察物体。
- Projection Transformation - to see depth in the object. 投影变换-看到物体的深度。
- Viewport Transformation - to temporarily map the volume defined by the “window of interest” plus the front and rear clipping planes into a unit cube. When this is the case, certain other operations are easier to perform. 视口变换-临时映射由“感兴趣的窗口”定义的体积,加上前面和后面的裁剪平面到一个单元立方体。在这种情况下,某些其他操作更容易执行。
- Device Transformation - to map the user defined “window of interest” (in the virtual world) to the dimensions of the display area. 设备转换-将用户定义的“感兴趣的窗口”(在虚拟世界中)映射到显示区域的尺寸。
Purpose: 当对象从文件加载并准备好被处理时启动。当对象准备好要显示在计算机屏幕上时,我们就完成了。能够画出一个简单物体的图像,比如一个长方体,并直观地显示当它通过每个管道阶段时发生了什么。
Types of geometric transformation
2D translation
向量形式
- Translating a point from
P(x, y)
toP’(x’, y’)
along vectorT
- Importance in computer graphics – we need to only transform the two endpoints of a line segment and let the implementation draw the line segment between the transformed endpoints
矩阵形式
where P(x, y)
and P’(x’, y’)
are the original and new positions, and T is the distance translated.
吐槽:矩阵不就nm是向量吗?向量不就nm是矩阵吗?
2D rotation
Rotating a point from P(x, y)
to P’(x’, y’)
about the origin by angle θ - radius stays the same, and angle increases by θ. 将一个点从P(x, y)
旋转到P'(x', y')
,绕原点旋转角度θ -半径不变,角度增加θ。
where θ is the rotation angle and φ is the angle between the x-axis and the line from the origin to (x,y). θ是旋转角度,φ是x轴和向(x,y)的向量的角度。
Rotation about a fixed point rather than the origin. 绕不动点而不是原点旋转。
- Move the fixed point to the origin 把不动点移到原点的位置
- Rotate the object 选择对象
- Move the fixed point back to its initial position 将固定点移回初始位置
- M = T(pf) R(θ) T(-pf)
2D scaling
When an object is scaled, both the size and location change. 就是把横坐标和纵坐标扩大相应的倍数。
where P, and P’ are the original and new positions, and sx and sy (是x和y的变化比例) are the scaling factors along the x- and y-axes.
2D reflection
Special case of scaling - corresponding to negative scale factors.
2D shearing
Equivalent to pulling faces in opposite directions. 相当于向相反的方向拉长面。
假设simple shearing是沿着x轴的:
2D homogeneous co-ordinates
在2D的平面上,平移是矩阵相加,旋转和缩放时矩阵相乘,因为这样太多麻烦,所以设计出了homogeneous coordinates
,而它的目的只是为了更加方便地去用矩阵来计算图形的变换。那什么是齐次坐标呢?其实就是在原来2D的维度,再加上一个新的维度,多出来的维度的值永远是1
2D composite transformation
where elements rs are the multiplicative rotation-scaling terms in the transformation (which involve only rotation angles and scaling factors); elements trs are the translation terms, containing combination of translation distances, pivot-point and fixed- point co-ordinates, rotation angles and scaling parameters. 式中元素rs为变换中的乘性旋转缩放项(只涉及旋转角度和缩放因子); 元素TRS是平移术语,包含平移距离、轴心点和定点坐标、旋转角度和缩放参数的组合。
3D translation
3D translations and scaling can be simply extended from the corresponding 2D methods.
3D co-ordinate axis rotations
从2D旋转方法扩展到3D旋转不那么简单(因为这是关于任意轴而不是任意点)。等价于在二维平面上以常数z(即绕原点)旋转。
General rotation about the origin
q绕任意轴的旋转可以分解为绕x、y和z轴的串联旋转。
R(q) = Rz(qz) Ry(qy) Rx(qx)
其中qx qy qz是欧拉角。旋转不能互换,尽管我们可以使用另一种顺序但不同角度的旋转。
3D scaling
3D composite transformation
- As with 2D transformation, a composite 3D transformation can be formed by multiplying the matrix representations for the individual operations in the transformation sequence. 与2D变换一样,通过将变换序列中各个操作的矩阵表示相乘,可以形成一个复合的3D变换。
- There are other forms of transformation, namely reflection and shearing which can be implemented with the other three transformations. 还有其他形式的转换,即反射和剪切,可以与其他三种转换一起实现。
- Translation, scaling, rotation, reflection and shearing are all affine transformations in that transformed point P’(x’,y’,z’) is a linear combination of the original point P(x,y,z). 平移,缩放,旋转,反射和剪切都是仿射变换,变换点P’(x’,y’,z’)是原始点P(x,y,z)的线性组合。
矩阵乘法没有交换律,但是有结合律。
在建模中,我们通常从一个简单的物体开始,该物体以原点为中心,以一个轴为方向,并且具有标准尺寸。
OpenGL matrices
见学校课件
Lab
有空更新
Reference
- XJTLU slides CPT205 (Week4)
- 2D平面中关于矩阵(Matrix)跟图形变换的讲解