My e-mail bag: The Flowcover transformation matrix

I just downloaded your flow cover library and its a fantastic piece of work especially for a beginner who is trying to learn opengl like me. I have a couple of doubts in that.

In this piece of code.

GLfloat m[16];
	m[10] = 1;
	m[15] = 1;
	m[0] = 1;
	m[5] = 1;
	double trans = off * SPREADIMAGE;
	double f = off * FLANKSPREAD;
	if (f  FLANKSPREAD) {
	m[3] = -f;
	m[0] = 1-fabs(f);
	double sc = 0.45 * (1 - fabs(f));
	trans += f * 1;

	glTranslatef(trans, 0, 0);



How did you calculate the matrix m. Since I suppose m[0] and m[3] is in a column major format how did you calculate the math to use it to skew the objects ?

Thanks and regards,
[name withheld]

“For programming purposes, OpenGL matrices are 16-value arrays with base vectors laid out contiguously in memory. The translation components occupy the 13th, 14th, and 15th elements of the 16-element matrix, where indices are numbered from 1 to 16 as described in section 2.11.2 of the OpenGL 2.1 Specification.”

Normally m[3] is not used directly in standard OpenGL operations, though transformations may result in m[3] being populated. It essentially adds x in the source (x,y,z,w) vector into w’ in the destination (x’,y’,z’,w’) vector, which is then used to divide through to get the final [pmath](x_r, y_r, z_r) = ({x{prime}}/{w{prime}}, {y{prime}}/{w{prime}}, {z{prime}}/{w{prime}})[/pmath]. So in this case, m[3] = -f and m[15] = 1, so [pmath]w{prime}=1-f*x[/pmath] (since w = 1), which is then divided through x’,y’,z’ to give the final points.

In other words, I’m using the x position on the tile to divide through the points of the tile to give the perspective skewing effect.

I then multiply m[0] by 1 – fabs(f) to shorten the tile in x a little more.

Hope this helps.

– Bill

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s