# The Model Matrix

The transformation pipeline – a “Spatial Odyssey”

In OpenGL geometric transformations are required in order to describe how the scene looks like. This involves converting from one coordinate system to another (since mesh data is introduced in 3D notation and has to be converted to 2D screen space).

The previous tutorials built a mathematical foundation that will be of great help when discussing the transformation pipeline responsible for taking 3D data to screen space.
The notion of transformation pipeline refers to the transformations that can occur anytime between the initial 3D vertex data was specified and the time that data appears in screen space.

This pipeline can be broken down into 7 main stages as illustrated in Fig. 1: original mesh data is used as input. This data then undergoes transformations enabled by: the model matrix, the view matrix, and the projection matrix. Finally, viewport calculations are carried out in order to correctly display the original data on screen (in window space coordinates).

In the present tutorial we’ll be describing the model matrix, and the remaining tutorials in this series will cover the rest of the pipeline stages.

The Model Matrix
As seen in Fig. 1, the vertex data (perhaps representing the mesh of an object) undergoes transformations in order to be placed in the scene at the desired location and pointing towards a specific point. These transformations are achieved by the model matrix.

In OpenGL the model matrix is used in the shader pipeline, namely by the vertex shader in order to transform each incoming vertex position from the local space to world space. The same model matrix will essentially transform all the incoming vertices representing a model.

In the past, many computer graphics materials presented model and view matrix stacked into one (modelview matrix). In modern computer graphics the model matrix is presented separate from the view matrix, as it does not incorporate a camera transform. It simply deals with positioning a mesh in 3D space, without being influenced by a view point.

Another justification for having a model matrix is for improving pipeline efficiency. Consider the following scenario: you would like to draw multiple spheres in a scene (not necessarily identical to one another). In order to achieve this efficiently, you will input the sphere mesh data set once, and use one model matrix per sphere that you wish to add to the scene. This saves up buffer space, and means that there is less data to send from the CPU to the GPU. Figure 2. a) The standard right-handed 3D coordinate system. b) Textured mesh of the  Stanford Dragon in Model Space.