Transforms - lorentzo/IntroductionToComputerGraphics GitHub Wiki
Why we need transforms?
- Basic tool for manipulating geometry.
- To position, reshape and animate objects, lights and cameras.
- example1: modeling - https://www.youtube.com/watch?v=Hf2esGA7vCc
- example2: animation - https://www.youtube.com/watch?v=CBJp82tlR3M
- Making sure that calculations are performed in same coordinate system.
- moving in and out of coordinate systems
- e.g., light-surface calculations in shading step of rendering.
- Projecting objects onto a plane.
- orthographic and perspective projection need for rasterization
- They are everywhere in Computer Graphics software:
- Godot: https://docs.godotengine.org/en/stable/classes/class_transform.html
- Unity: https://docs.unity3d.com/ScriptReference/Transform.html
- Unreal: https://docs.unrealengine.com/4.27/en-US/BlueprintAPI/Math/Transform/
- Blender: https://docs.blender.org/manual/en/latest/scene_layout/object/properties/transforms.html
- GLM: https://github.com/g-truc/glm
What transforms do?
- Transform is operation that takes points, vectors or colors and converts them in some way.
- Linear transform: transform that preserves vector addition and scalar multiplication.
- Scaling
- Rotation
- Translation is not linear transform: use affine transforms (represented by 4x4 matrices)
- homogeneous notation is used for vectors and points
- Translation, rotation, scaling, reflection and shearing transforms are affine: preserve parallelism of lines but not (necessarily) lengths and angles
Basic transforms
Translation
- Change point location from one to another
- properties, inverse
- rigid-body transform: preserve distance between points and headedness
Rotation
- rotates vector/point by given angle around given axis passing through origin: 3 matrices: rotation of theta degrees around x, y, or z axis can be used for rotation around arbitrary axis
- Pivot point is required for determining rotation: object is first translated so that pivot point in the center and then rotation is performed after which object is again transformed so that pivot point is in the same position as before.
- rigid-body transform: preserve distance between points and headedness
- useful for positioning and orienting objects: e.g., orientation matrix - rotation matrix associated with camera view or object that defines its orientation in space: directions for up and forward are needed to define this matrix.
Scaling
- enlarging or diminishing objects
- uniform/isotropic
- non-uniform/anisotropic
- reflection/mirror matrix
Shearing
- 6 basic shearing
Concatenation of Transforms
- Non-commutativity of matrix multiplication -> order of multiplication matters!
- TRS
Rigid body transforms
Rigid body transforms - concatenation of rotation and translation matrices
- Look At Matrix
Normal transform
- Normal is geometrical property that can not be transformed using discussed transforms
- Transpose of Matrix adjoint must be used!
Special transforms
Euler Transform
- establish default view: negative z
- head orient: along y
- Euler matrix is concatenation of 3 rotation matrices around x,y and z axis
- angles: head (y-roll), pitch (x-roll), roll (z-roll)
- Problems: gimbal lock, two different sets of Euler angles can give same orientation and finally interpolation between two Euler angle sets is not as simple as interpolating each angle
- Good: angles can be extracted from Euler matrix -> matrix decomposition
Rotation around arbitrary axis
- transform to space where axis we want to rotate around is x, perform rotation, return to original space
Quaternions
- represent rotations and orientations
- 3D orientation can be represented as single rotation around particular axis
- Interpolating between two quaternions is stable and constant
- unit quaternion - any 3D rotation
Examples
- Vertex blending
- Morphing
- Geometry cache playback
Projections
- rasterization based renderers require relevant objects in 3D scene to be projected onto a plane or simple volume
- orthographic and perspective projection
- Interesting view on transforms: https://www.youtube.com/watch?v=BzSawxAQtnI&t=305s