Affine
CGP provide also a set of helper structure to handle the combination of rotation, translation and scaling. Each transformation type is store and can be set individually, while the general structures can be combined together and apply to vectors as if it was a matrix.Code Reference
09_geometric_transformation/affine/affine_rt/affine_rt.hpp
09_geometric_transformation/affine/affine_rts/affine_rts.hpp
09_geometric_transformation/affine/affine/affine.hpp
Structures
The structure affine_rt (for Rotation-Translation) and affine_rts (for Rotation-Translation-Scaling) are available to this effect and can be combined together.
struct affine_rt
rotation_transform rotation
vec3 translation
vec3 translation
struct affine_rts
rotation_transform rotation
vec3 translation
float scaling
vec3 translation
float scaling
- affine transforms cannot be combined together as the result may contain shearing.
struct affine
rotation_transform rotation
vec3 translation
float scaling
vec3 scaling_xyz
vec3 translation
float scaling
vec3 scaling_xyz
Usage
affine_rts A; A.rotation = rotation_transform::from_axis_angle({ 1,0,0 }, Pi / 4); A.translation = { 1,1,2 }; A.scaling = 1.1f; affine_rts B; B.rotation = rotation_transform::from_axis_angle({ 0,1,0 }, Pi / 6); B.translation = { 2,1,0 }; B.scaling = 2.0f; // Combine the affine transforms using operator * affine_rts C = A * B; // The corresponding components of C can be obtained as // C.rotation, C.translation, C.scaling // Apply an affine transform to a vec3 vec3 p = C* vec3{ -3,2,0 }; // assume that the vector is (-3,2,0,1) in homogeneous coordinates // Retrieve the 4x4 matrix corresponding to the transform mat4 T = C.matrix();
rotation_transform R; // Some rotation vec3 c = { 1,2,3 }; // A position around which the rotation is applied // Encode a "rotation around a given center" affine_rt T = rotation_around_center(R, c); // Apply the transformation to some coordinates vec3 p = T * vec3{ 1.1f, 2.1f, 1.5f };