GLUSvoid GLUSAPIENTRY glusTransposef(GLUSfloat matrix[16])
{
	GLUSuint column; 
	GLUSuint row; 

	GLUSfloat temp[16];

	glusCopyMatrixf(temp, matrix);

	for (column = 0; column < 4; column++)
	{
		for (row = 0; row < 4; row++)
		{
			matrix[row*4+column] = temp[column*4+row];
		}
	}
}
示例#2
0
/**
 * Function to render and display content.
 */
GLUSboolean update(GLUSfloat time)
{
	// Angle for rotation
	static GLfloat angle = 0.0f;

	// Matrix for the model
	GLfloat model[16];

	// http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/clear.html
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Calculate the model matrix ...
	glusLoadIdentityf(model);
	glusRotateRzRyRxf(model, 45.0f, angle, 0.0f);
	// ... and the view matrix ...
	glusLookAtf(g_modelView, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	glusCopyMatrixf(g_inverseCamera, g_modelView, GLUS_TRUE);
	glusInverseMatrixf(g_inverseCamera, g_inverseCamera);

	// ... to get the final model view matrix
	glusMultMatrixf(g_modelView, g_modelView, model);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniformMatrix4fv(g_inverseCameraLocation, 1, GL_FALSE, g_inverseCamera);

	// http://www.opengl.org/sdk/docs/man/xhtml/glDrawElements.xml
	glDrawElements(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_INT, 0);

	angle += 20.0f * time;

	return GLUS_TRUE;
}
示例#3
0
/**
 * Renders the water
 */
GLUSvoid renderWater(GLUSfloat passedTime, GLUSfloat angle)
{
	static WaveParameters waveParameters[NUMBERWAVES];
	static WaveDirections waveDirections[NUMBERWAVES];

	static GLfloat overallSteepness = 0.2f;

	GLfloat model[16];

	// Calculate the model matrix ...
	glusLoadIdentityf(model);
	// ... and the view matrix ...
	glusLookAtf(g_modelView, 0.0f, 1.0f, 0.0f, (GLfloat)0.5f * sinf(angle), 1.0f, -(GLfloat)0.5f * cosf(angle), 0.0f, 1.0f, 0.0f);
	// ... to get the final model view matrix
	glusMultMatrixf(g_modelView, g_modelView, model);

	// Copy the original view matrix ...
	glusCopyMatrixf(g_inverseCamera, g_modelView, GLUS_TRUE);
	// ... and inverse it
	glusInverseMatrixf(g_inverseCamera, g_inverseCamera);

	memset(waveParameters, 0, sizeof(waveParameters));
	memset(waveDirections, 0, sizeof(waveDirections));

	// Waves can be faded in and out.

	// Wave One
	waveParameters[0].speed = 1.0f;
	waveParameters[0].amplitude = 0.01f;
	waveParameters[0].wavelength = 4.0f;
	waveParameters[0].steepness = overallSteepness/(waveParameters[0].wavelength*waveParameters[0].amplitude*(GLfloat)NUMBERWAVES);
	waveDirections[0].x = +1.0f;
	waveDirections[0].z = +1.0f;

	// Wave Two
	waveParameters[1].speed = 0.5f;
	waveParameters[1].amplitude = 0.02f;
	waveParameters[1].wavelength = 3.0f;
	waveParameters[1].steepness = overallSteepness/(waveParameters[1].wavelength*waveParameters[1].amplitude*(GLfloat)NUMBERWAVES);
	waveDirections[1].x = +1.0f;
	waveDirections[1].z = +0.0f;

	// Wave Thre
	waveParameters[2].speed = 0.1f;
	waveParameters[2].amplitude = 0.015f;
	waveParameters[2].wavelength = 2.0f;
	waveParameters[2].steepness = overallSteepness/(waveParameters[1].wavelength*waveParameters[1].amplitude*(GLfloat)NUMBERWAVES);
	waveDirections[2].x = -0.1f;
	waveDirections[2].z = -0.2f;

	// Wave Four
	waveParameters[3].speed = 1.1f;
	waveParameters[3].amplitude = 0.008f;
	waveParameters[3].wavelength = 1.0f;
	waveParameters[3].steepness = overallSteepness/(waveParameters[1].wavelength*waveParameters[1].amplitude*(GLfloat)NUMBERWAVES);
	waveDirections[3].x = -0.2f;
	waveDirections[3].z = -0.1f;

	// http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml
	glUseProgram(g_program.program);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniformMatrix4fv(g_modelViewLocation, 1, GL_FALSE, g_modelView);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniformMatrix4fv(g_inverseCameraLocation, 1, GL_FALSE, g_inverseCamera);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniform1f(g_passedTimeLocation, passedTime);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniform4fv(g_waveParametersLocation, 4*NUMBERWAVES, (GLfloat*)waveParameters);

	// http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
	glUniform2fv(g_waveDirectionsLocation, 2*NUMBERWAVES, (GLfloat*)waveDirections);

	// ToDo:
	glBindVertexArray(g_vao);

	// ToDo:
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	//http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/disable.html
	glDisable(GL_CULL_FACE);

	// http://www.opengl.org/sdk/docs/man/xhtml/glDrawElements.xml
	glDrawElements(GL_TRIANGLE_STRIP, WATER_PLANE_LENGTH*(WATER_PLANE_LENGTH-1)*2, GL_UNSIGNED_INT, 0);
}