 | [TOC] Chapter 6: Model Transformations |  |
 | Introduction |  |
In this chapter, we’ll explore model transformations in WebGPU, diving into scaling, translating, and rotating 3D objects and how to apply transformation matrices. Model transformations adjust an object’s position, orientation, and size in 3D space. This chapter will guide you through applying these transformations using the `glMatrix` library, a powerful tool for handling matrix operations in WebGPU.
Basic transformations allow us to adjust an object's geometry in a 3D space. Each transformation type—scaling, translation, and rotation—manipulates vertices in distinct ways. Scaling changes an object's size, translating moves it in space, and rotating changes its orientation. Combining these transformations helps us build complex scenes and animations in WebGPU.
 | Scaling |  |
Scaling transformations adjust an object’s size along its x, y, and z axes. The scale factors define how much an object stretches or shrinks in each direction.
Scaling can be represented by a 4x4 matrix:
\[
\begin{bmatrix}
s_x & 0 & 0 & 0 \\
0 & s_y & 0 & 0 \\
0 & 0 & s_z & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
\]
where \( s_x \), \( s_y \), and \( s_z \) are scaling factors for the x, y, and z axes.
Special Cases and Effects
1. Uniform Scaling: When \( s_x = s_y = s_z \), the object scales uniformly in all directions, preserving its original proportions.
2. Non-Uniform Scaling: Setting different values for \( s_x \), \( s_y \), and \( s_z \) allows for stretching or compressing the object in specific directions. This is useful for transforming an object into an elongated or flattened shape.
3. Negative Scaling: A negative scale factor inverts the object along the respective axis. For example, applying \( -1 \) to the x-axis reflects the object across the y-z plane.
Example code for scaling with `glMatrix`:
|