PDA

View Full Version : Implementing a matrix and applying it

Jack99
11-04-2004, 12:46 PM
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
11-04-2004, 01:36 PM
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 (http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html) 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

Jack99
11-04-2004, 02:07 PM
Thanks for your help!