Example #1
0
// Update the position matrices, and
// update the world-space bounding box and hotspots.
// This is called once whenever the gate's position
// or angle changes.
void guiGate::updateBBoxes(bool noUpdateWires) {
	// Get the translation vars:
	float x, y;
	this->getGLcoords(x, y);

	// Get the angle vars:
	istringstream iss(gparams["angle"]);
	GLfloat angle;
	iss >> angle;

	loadidentitym(mModel);
	translatem(mModel, x, y);
	rotatem(mModel, angle);

	// Update all of the hotspots' world coordinates:
	map< string, gateHotspot* >::iterator hs = hotspots.begin();
	while(hs != hotspots.end()) {
		(hs->second)->worldLocation = modelToWorld((hs->second)->modelLocation);
		(hs->second)->calcBBox();
		hs++;
	}

	// Convert bbox to world-space:
	klsBBox worldBBox;
	worldBBox.addPoint(modelToWorld( modelBBox.getTopLeft()    ) );
	worldBBox.addPoint(modelToWorld( modelBBox.getTopRight()   ) );
	worldBBox.addPoint(modelToWorld( modelBBox.getBottomLeft() ) );
	worldBBox.addPoint(modelToWorld( modelBBox.getBottomRight()) );
	this->setBBox(worldBBox);

	// Update the connected wires' shapes to accomidate the new gate position:
	map < string, guiWire* >::iterator connWalk = connections.begin();
	while(!noUpdateWires && connWalk != connections.end()) {
		(connWalk->second)->updateConnectionPos(this->getID(), connWalk->first);
		connWalk++;
	}
}
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());
	}
}