# Implementing a matrix and applying it

Hi Im new to using OpenGl. I need to perform a shear translation on a 2D Graphic along the x axis.

I have found the following matrix but im not sure how to implement it within my code.

{
1 h 0;
0 1 0;
0 0 1;
}

Any help with this would be much appreciated.
Thanks.

Hi,

Sheering, in 3D, incidentally is defined:

``````| 1  Kxy Kxz 0 |
| 0    1 Kyz 0 |
| 0    0   1 0 |
| 0    0   0 1 |
``````

The subscripts on K define the plane for the sheering. (I think)

Remember, OpenGL uses homogeneous coordinates, so there is actually 4X4.

How to apply it? Well, OpenGL has a glMultMatrix() function that can be used.

OGL represents matrices as float or double arrays, see THE RED BOOK for details.

Basically, it might go something like this:

``````double xySheer, xzSheer, yzSheer;
double sheerMatrix;
memset( sheerMatrix, 0, 16 * sizeof(double) );
sheerMatrix = sheerMatrix =
sheerMatrix = sheerMatrix = 1.0;
sheerMatix = xySheer;
sheerMatix = xzSheer;
sheerMatix = yzSheer;

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glMultMatrixd( sheerMatrix );
// Draw sheered geometry
glPopMatrix();
``````

Hope that helps
-Rawk

Thanks for your help!