# 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

*, 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*

**Fig. 1***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.

**Adding it all up
**

All buffered vertices reach their final clip space position after undergoing transforms in the vertex shader. This is achieved by multiplying their position vector by the matrix formed when the model, view, and projection matrices were *concatenated* (this will be covered in the following tutorial). In computer graphics, and perhaps in numerous mathematical applications, in order to eliminate the ambiguity of transform addition solved through multiplication, the term “concatenate” is preferred.

**In conclusion
**The transformation pipeline manipulates mesh data by taking it from one coordinate system to another in order to be correctly displayed on screens. The model matrix in conjunction with the view matrix (coming up in the next tutorial) allow you to position mesh data at the desired location in the scene.