The Matrix Builder

The matrix builder works like OpenGL's stack of transformations. You can design a transformation (let's say T). Then, you can get it and use it. You can also push it on the stack. Then, start designing other transformations without pushing anymore. If at the end you call the pop() method of your MatrixBuilder, the transformation T you previously saved gets the current transformation of your MatrixBuilder object. So a call to getMatrix() will return T.

In other words, the MatrixBuilder is usefull to design transformation matrices easily, while offering the possibility to build procedural objects.

It works with 4x4 matrices (homogeneous coordinates).

The constructor takes no arguments. The methods are :

	
	void rotate(Real, Real, Real, Real);  // The current matrix gets multiplied by a rotation matrix
(parameters are the angle and the direction vector composants of the axis we'll be turning around)
	
	void translate(Real, Real, Real);  // The current matrix gets multiplied by a translation matrix
(parameters are the translation vector composants we'll be translation by)
	
	void scale(Real);  // The current matrix gets multiplied by an uniform scaling matrix
(parameter is the scaling factor)
	
	void pushMatrix();  // Pushes the current Matrix onto the stack
	
	void popMatrix();  // The matrix on top of the stack has been poped and is now the current matrix
	
	const Matrix44& getMatrix();  // Get the current matrix
	
	void setId(); // Reset the current matrix (makes it be Identity)

 

Example of use :

    MatrixBuilder mb;
    mb.setId();
	mb.rotate(10,0,1,0);
	mb.translate(0, 0, 5);
    
    Plane p;
	p.setMatrix(mb.getMatrix());
	// set p 's material
	scene.addObject(&p);