Example #1
0
const mat4 & Camera::viewProjectionInverted() const
{
    if (m_dirty)
        update();

    if (!m_viewProjectionInverted.isValid())
        m_viewProjectionInverted.setValue(inverse(viewProjection()));

    return m_viewProjectionInverted.value();
}
Example #2
0
void SceneBuffers::Draw()
{
	rendererGL.ClearGLFlags();

	Matrix3D MVP, viewMatrix, modelViewMatrix, modelMatrix, rotationMatrix,
		translateMatrix, rotationMatrixX, rotationMatrixY, rotationMatrixZ,
		modelToWorld, viewProjection;

	Matrix3D::BuildLookAtMatrix(0.0, 1.0, -5.0,	//camera position
								0.0, 0.0, 0.0,	//point that camera looks at
								0.0, 1.0, 0.0,	//camera up vector
								viewMatrix);

	//create identity matrices
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, modelMatrix);
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, translateMatrix);
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, rotationMatrix);
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, rotationMatrixX);
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, rotationMatrixY);
	Matrix3D::MakeScaleMatrix(1.0, 1.0, 1.0, rotationMatrixZ);

	//call each object in the list draw function
	for (unsigned int i = 0; i < list.size(); i++)
	{
		float* tempSpace = list[i]->GetScale();
		Matrix3D::MakeScaleMatrix(tempSpace[0], tempSpace[1], tempSpace[2], modelMatrix);

		tempSpace = list[i]->GetPosition();
		Matrix3D::MakeTranslateMatrix(tempSpace[0], tempSpace[1], tempSpace[2], translateMatrix);

		//calculate rotation on all 3 axis
		tempSpace = list[i]->GetRotation();
		Matrix3D::MakeRotateMatrix(tempSpace[0], 1.0, 0.0, 0.0, rotationMatrixX);
		Matrix3D::MakeRotateMatrix(tempSpace[1], 0.0, 1.0, 0.0, rotationMatrixY);
		Matrix3D::MakeRotateMatrix(tempSpace[2], 0.0, 0.0, 1.0, rotationMatrixZ);
		Matrix3D::MultMatrix(rotationMatrix, rotationMatrixX, rotationMatrixY);
		Matrix3D::MultMatrix(rotationMatrix, rotationMatrix, rotationMatrixZ);

		Matrix3D::MultMatrix(modelMatrix, rotationMatrix, modelMatrix);

		Matrix3D::MultMatrix(modelMatrix, translateMatrix, modelMatrix);	//calculate world position
		Matrix3D::MultMatrix(modelToWorld, translateMatrix, modelMatrix);	//calculate world position

		Matrix3D::MultMatrix(modelViewMatrix, viewMatrix, modelMatrix);		//model - view matrix
		Matrix3D::MultMatrix(MVP, Engine::perspective, modelViewMatrix);	//model - view - projection matrix
		Matrix3D::MultMatrix(viewProjection, Engine::perspective, viewMatrix);	//model - view - projection matrix

		//bind CG program
		rendererGL.BindProgram(vertexLightVS.GetProgram());
		rendererGL.BindProgram(vertexLightFS.GetProgram());

		//Enable VS & FS profiles
		rendererGL.EnableProfile(rendererGL.GetVertexProfile());
		rendererGL.EnableProfile(rendererGL.GetFragmentProfile());

		//update shaders parameters

		vertexLightVS.UpdateModelViewMatrix(MVP());
		vertexLightVS.UpdateMatrixModelWorld(modelToWorld());
		vertexLightVS.UpdateMatrixViewProj(viewProjection());
		vertexLightVS.UpdateLightPosition(lightPos);

		if (i != 1)
			vertexLightFS.SetDecalMap(textureManager.getTextureId("../Images/bricks_diffuse.bmp"));
		else
			vertexLightFS.SetDecalMap(textureManager.getTextureId("../Images/bricks_normal.bmp"));

		//update shaders
		vertexLightVS.UpdateParameters();
		vertexLightFS.UpdateParameters();

		list[i]->DrawBuffers();

		//disable Vertex CGprofile
		rendererGL.DisableProfile(rendererGL.GetVertexProfile());
		rendererGL.DisableProfile(rendererGL.GetFragmentProfile());
	}
}