Commits

Ricky Curtice committed 4b8e189

Potentially improved performance a notch by having the current camera be a member property of RenderEngine.

The any_cast that was used to get the current camera from the gprops was not
worth the ease of changing cameras. Camera's are now spec'd to be changed out
via a Message, providing much more safety checking, and not being a speedbump to
the render process.

Comments (0)

Files changed (2)

src/graphics_core/RenderEngine.cpp

 		// Render Delay
 		this->gprops->AddProperty(GP_RENDER_DELAY, GP_RENDER_DELAY_DEF);
 
-		// Camera
-		this->gprops->AddProperty(GP_ACTIVE_CAMERA, (Camera*) NULL);
-		
-		
 		/* * * * * * * * * * * * * * * * * * * * * */
 		// Define the local globals
 		/* * * * * * * * * * * * * * * * * * * * * */
 		AspectRatio = this->gprops->GetPropertyFloat(GP_CLIENT_ASPECT);
 		AspectRatioInv = this->gprops->GetPropertyFloat(GP_CLIENT_ASPECT_INV);
 		
+		/* * * * * * * * * * * * * * * * * * * * * */
+		// Define the instance properties
+		/* * * * * * * * * * * * * * * * * * * * * */
+		// Camera
+		this->currentCamera = NULL;
 	}
 
 	RenderEngine::~RenderEngine(void) {
 		static D3DXVECTOR3 cameraLookAt, cameraPosition;
 		static Camera* camera;
 		static std::string debugStr;
-		//assert(!this->myRenderableComponents.empty());
-		
 		
 		// Set fill mode
 		this->pd3dDevice->SetRenderState(D3DRS_FILLMODE, gprops->GetPropertyUInt(GP_FILLMODE));
 		if ( SUCCEEDED( pd3dDevice->BeginScene() )) {
 			// Set the perspective camera in the 3D world
 			
-			// Get active camera from gprops //*TODO: this belongs in a private global or property, and then can be changed via a message.
-			camera = boost::any_cast<Camera*>(this->gprops->GetPropertyAny(GP_ACTIVE_CAMERA));
-			assert(camera != NULL);
+			// Verify active camera
+			assert(this->currentCamera != NULL);
 			
-			float fovy = camera->GetFov() * AspectRatioInv; // calculate the vertical FOV from the horizontal FOV stored in the camera.
+			float fovy = this->currentCamera->GetFov() * AspectRatioInv; // calculate the vertical FOV from the horizontal FOV stored in the camera.
 			
 			// Set the projection tranformation
 			D3DXMatrixIdentity(&matrixProj);
-			D3DXMatrixPerspectiveFovLH(&matrixProj, fovy, AspectRatio, camera->GetNearClipRange(), camera->GetFarClipRange());
+			D3DXMatrixPerspectiveFovLH(&matrixProj, fovy, AspectRatio, this->currentCamera->GetNearClipRange(), this->currentCamera->GetFarClipRange());
 			pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrixProj);
 			
 			// Set the view transformation
 			D3DXMatrixIdentity(&matrixView);
 			
 			// Calculate the camera's world position
-			cameraPosition = camera->GetOffset(); // Get and rotate the offset
-			RotateVectorByQuaternion(&cameraPosition, &cameraPosition, &(camera->GetOwner()->GetWorldRotation()));
-			cameraPosition += camera->GetOwner()->GetWorldPosition();
+			cameraPosition = this->currentCamera->GetOffset(); // Get and rotate the offset
+			RotateVectorByQuaternion(&cameraPosition, &cameraPosition, &(this->currentCamera->GetOwner()->GetWorldRotation()));
+			cameraPosition += this->currentCamera->GetOwner()->GetWorldPosition();
 			
 			// Calculate a lookat based on rotation of camera and a unit vector
 			cameraLookAt = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
-			RotateVectorByQuaternion(&cameraLookAt, &cameraLookAt, &(camera->GetOwner()->GetWorldRotation() * camera->GetRotation()));
+			RotateVectorByQuaternion(&cameraLookAt, &cameraLookAt, &(this->currentCamera->GetOwner()->GetWorldRotation() * this->currentCamera->GetRotation()));
 			cameraLookAt += cameraPosition; // the look at position is naturally relative to the camera, so add the camera's position to adjust.
 			
 			D3DXMatrixLookAtLH(
 		//this->renderableComponents // now contains only pointers to objects owned by other people. (Mine were cleared via their destructors by the above)
 		
 		// Invalidate the pointer to the active camera
-		this->gprops->AddProperty(GP_ACTIVE_CAMERA, NULL);
+		this->currentCamera = NULL;
 		
 		if( pd3dDevice != NULL) {
 			pd3dDevice->Release();
 			
 			// Register the first created camera as the active camera
 			if (this->cameraComponents.size() <= 1) {
-				this->gprops->AddProperty(GP_ACTIVE_CAMERA, cam);
+				this->currentCamera = cam;
 			}
 		}
 		else if (type.compare(LIGHT_AMBIENT) == 0) {

src/graphics_core/RenderEngine.h

 			std::set<RenderableComponent*> myRenderableComponents;
 			std::set<Camera*> cameraComponents;
 			
+			Camera* currentCamera;
+			
 			LPDIRECT3D9       pD3D;
 			LPDIRECT3DDEVICE9 pd3dDevice;
 	};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.