Exemplo n.º 1
0
///
//Renders the OctTree
//
//Parameters:
//	nodeToRender: THe node of the oct tree being rendered
//	modelViewProjectionMatrix: THe modelViewProjectionMatrix to send to the shader
//	viewMatrix: THe view matrix of the camera
//	projectionMatrix: The projection matrix of the camera
//	mesh: The mesh to draw as a representation of the oct tree
void RenderingManager_RenderOctTree(OctTree_Node* nodeToRender, Matrix* modelViewProjectionMatrix, Matrix* viewMatrix, Matrix* projectionMatrix, Mesh* mesh)
{
	//Only render trees which contain objects?

	//If this node has children, draw them too
	if(nodeToRender->children != NULL)
	{
		for(int i = 0; i < 8; i++)
		{
			RenderingManager_RenderOctTree(nodeToRender->children + i, modelViewProjectionMatrix, viewMatrix, projectionMatrix, mesh);
		}
	}
	else
	{
		//Set modelViewMatrix to identity
		Matrix_ToIdentity(modelViewProjectionMatrix);

		//Set the scale values of the modelViewProjection Matrix
		*Matrix_Index(modelViewProjectionMatrix, 0, 0) = nodeToRender->right;
		*Matrix_Index(modelViewProjectionMatrix, 1, 1) = nodeToRender->top;
		*Matrix_Index(modelViewProjectionMatrix, 2, 2) = nodeToRender->front;

		//Set modelMatrix uniform
		glProgramUniformMatrix4fv(renderingBuffer->shaderPrograms[0]->shaderProgramID, renderingBuffer->shaderPrograms[0]->modelMatrixLocation, 1, GL_TRUE, modelViewProjectionMatrix->components);

		//Construct modelViewProjection
		Matrix_TransformMatrix(viewMatrix, modelViewProjectionMatrix);
		Matrix_TransformMatrix(projectionMatrix, modelViewProjectionMatrix);
		//Set modelViewProjectionMatrix uniform
		glProgramUniformMatrix4fv(renderingBuffer->shaderPrograms[0]->shaderProgramID, renderingBuffer->shaderPrograms[0]->modelViewProjectionMatrixLocation, 1, GL_TRUE, modelViewProjectionMatrix->components);

		//Render node
		Mesh_Render(mesh, GL_LINES);
	}
}
Exemplo n.º 2
0
///
//Initializes a matrices components and sets as identity matrix
//
//Parameters:
//	mat: Matrix to initialize
void Matrix_Initialize(Matrix* mat, const uint16_t numRows, const uint16_t numCols)
{
	mat->numRows = numRows;
	mat->numColumns = numCols;
	mat->components = (float*)calloc(sizeof(float), mat->numRows * mat->numColumns);
	if (mat->numRows == mat->numColumns)
	{
		Matrix_ToIdentity(mat);
	}
}