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];
	memset(m,0,sizeof(m));
	m[10] = 1;
	m[15] = 1;
	m[0] = 1;
	m[5] = 1;
	double trans = off * SPREADIMAGE;
	
	double f = off * FLANKSPREAD;
	if (f  FLANKSPREAD) {
		f = FLANKSPREAD;
	}
	m[3] = -f;
	m[0] = 1-fabs(f);
	double sc = 0.45 * (1 - fabs(f));
	trans += f * 1;
	
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D,fcr.texture);

	glTranslatef(trans, 0, 0);

	glScalef(sc,sc,1.0);


	glMultMatrixf(m);

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]

http://www.opengl.org/resources/faq/technical/transformations.htm

“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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s