Introduction to Matrixes and Their Applications
(updated in 16/05/2001)

Previous | Index | Next

The same way matrixes have a large use in many 3D and 2D libraries and applications, they play a fundamental role in HOpenGL. They are very important in rotation, translation and to describe some program behaviors, for example. There exists three kind of matrixes in HOpenGL: Projection, Modelview and Texture.

  • Projection Matrix - Used to describe some main parameters of the world in which we are working (such as the way we'll "see" the objects).
  • Modelview Matrix - This matrix concerns about rotation, translation and scaling, among other things.
  • Texture Matrix - As the name says, it is related to textures. We'll talk about it later.

Our HOpenGL program is always working with a current matrix, which can be one of the three kind of matrixes listed above. When we wish the current matrix to be swtiched from one type to another, the function matrixMode is used. For example, if we were working with the current matrix being a Modelview Matrix, the following code:

	matrixMode Projection

says that now the current matrix will be the Projection Matrix. Of course, calling

	matrixMode Modelview

will switch our current matrix back to the Modelview Matrix. When calling a HOpenGL function that works with matrixes, such as the rotation or translation function, the matrix to be modified is the one indicated by the current matrix. Hence, you need to be careful in order to do not change the wrong matrix.



The function loadIdentity (which has no parametes) assigns the identity matrix to the current matrix. In other words, this functions "clears" (initialize) the current matrix. The following code "clears" all three HOpenGL matrixes, making all of them equal to the identity matrix:

	matrixMode Projection
	loadIdentity
	matrixMode Modelview
	loadIdentity
	matrixMode Texture
	loadIdentity

You do not need to worry about doing the above procedure every time you start to write a program. Only when there is a necessity to lead with a specific type of matrix you'll need to initialize it. Both functions matrixMode and loadIdentity are defined in module GL_CoordTrans, which is automatically imported if your program already imports module GL.

Since you understood this introduction to matrixes in HOpenGL, we'll talk about their uses in the following lessons.



HOpenGL Tutorial - Andre W B Furtado
Introduction to Matrixes and Their Applications
www.cin.ufpe.br/~haskell/hopengl/matrixes.html
Last updated in 16/05/2001
Informatics Center (CIn) - UFPE
Recife - PE - Brazil