Jack99
1
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.
Rawk
2
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[16];
memset( sheerMatrix, 0, 16 * sizeof(double) );
sheerMatrix[0] = sheerMatrix[5] =
sheerMatrix[10] = sheerMatrix[15] = 1.0;
sheerMatix[4] = xySheer;
sheerMatix[8] = xzSheer;
sheerMatix[8] = yzSheer;
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glMultMatrixd( sheerMatrix );
// Draw sheered geometry
glPopMatrix();
Hope that helps
-Rawk