Example #1
0
// Creates a player
GameObject* GameManager::CreatePlayer( uint32_t index, const XMFLOAT3& position, const XMFLOAT3& scale )
{
    Scene* scene = Scene::GetInstance();
    GameObject* player = scene->AddGameObject( "Player_" + std::to_string( index ) );
    ID3D11Device* device = player->GetDevice();
    ID3D11DeviceContext* deviceContext = player->GetDeviceContext();

    // Set the player's transform info
    Transform* transform = player->GetTransform();
    transform->SetPosition( position );
    transform->SetScale( scale );

    // Add the collider to the player
    BoxCollider* collider = player->AddComponent<BoxCollider>();
    collider->SetSize( XMFLOAT3( 1, 1, 1 ) );

    // Add the rigid body to the player
    Rigidbody* rigidbody = player->AddComponent<Rigidbody>();
    rigidbody->SetMass( 0 );

    // Add the default material to the player
    DefaultMaterial* material = player->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\Rocks2.jpg" );
    material->LoadNormalMap( "Textures\\Rocks2Normals.jpg" );
    material->SetDirectionalLight( StageLight );

    // Add the mesh renderer to the player
    MeshRenderer* meshRenderer = player->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\cube.obj", device, deviceContext ) );

    return player;
}
Example #2
0
int main(int argc, char** argv)
{
	// Create freeglut window
	GlutWindowManager* windowMgr = GlutWindowManager::GetInstance();
	//StaticData::SetWindowManager(windowManager);
	windowMgr->Init(argc, argv);
	Window* window = windowMgr->NewWindow(1, 500, 500, 200, 200, "Window 1");

	// Create mesh renderer (init openGL)
	MeshRenderer* meshRenderer = new MeshRenderer(WINDOW_WIDTH, WINDOW_HEIGHT);
	//StaticData::SetMeshRenderer(meshRenderer);
	meshRenderer->Init();

	// Load mesh
	Mesh* mesh = NULL;
	Rendering::Operators::ObjReader::LoadMesh("Models\\cube.obj", mesh, true);

	Rendering::Operators::MeshTransformation::Triangulate(mesh);
	mesh->ComputeNormals();
	mesh->color = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);

	meshRenderer->SetMesh(mesh);

	meshRenderer->SetRenderMode((RenderMode)(RenderMode::VERTICES | RenderMode::WIREFRAME));
	meshRenderer->SetLightType(LightType::POINT_LIGHT);
	meshRenderer->SetLightColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));

	//Operators::MeshTransformation::Inflate(mesh, 0.1f);
	//meshRenderer->UpdateMeshConnectivity();

	// Create a WindowRenderer and link it to the window
	WindowRenderer winRenderer(meshRenderer);
	window->Attach(&winRenderer);

	// Create manipulators
	MouseManipulator mouseManip(meshRenderer);
	Mouse* mouse = windowMgr->GetMouse();
	mouse->Attach(&mouseManip);

	// Start main loop
	windowMgr->Display();

	//delete windowManager;
	delete meshRenderer;

	return 0;	
}
Example #3
0
// Creates an arrow game object
GameObject* GameManager::CreateArrow( const XMFLOAT3& position, const XMFLOAT3& force )
{
    static const XMFLOAT3 ArrowSize = { 1, 0.1f, 1.0f };

    Scene* scene = Scene::GetInstance();
    ID3D11Device* device = _gameObject->GetDevice();
    ID3D11DeviceContext* deviceContext = _gameObject->GetDeviceContext();

    // Create the arrow object
    GameObject* arrow = scene->AddGameObject( _gameObject->GetName() + "_Arrow_" + std::to_string( _arrowCount++ ) );
    
    // Set some transform info
    Transform* transform = arrow->GetTransform();
    transform->SetPosition( position );

    // Add the arrow's collider
    BoxCollider* collider = arrow->AddComponent<BoxCollider>();
    collider->SetSize( ArrowSize );

    // Add the arrow's rigidbody
    Rigidbody* rigidbody = arrow->AddComponent<Rigidbody>();
    rigidbody->SetMass( 1.0f );

    // Set the arrow's collision callback
    GameObject::CollisionCallback callback = std::bind( &GameManager::OnArrowCollide, this, _1 );
    arrow->AddEventListener( "OnArrowCollide", callback );

    // Add a default material
    DefaultMaterial* material = arrow->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\SolidWhite.png" );
    material->SetDirectionalLight( StageLight );

    // Add a mesh renderer
    MeshRenderer* meshRenderer = arrow->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\arrow.obj", device, deviceContext ) );

    return arrow;
}
void Scene::Render( RenderPass renderPass, Viewport* viewport )
{
	static Mesh* skyboxMesh = ResourceManager::GetGenMesh(GenMeshes::Cube);

	std::string viewportName = viewport != NULL ? viewport->GetName() : "";

	bool ignoreShadowCast = true;
	if (renderPass == RenderPass::ShadowPass)
	{
		ignoreShadowCast = false;
	}

	for (uint rank = 0; rank < m_layers.size(); rank++)
	{
		if ( !m_layers[rank]->IsEnabled() )	continue;

		RenderManager::UseNewLayer(renderPass);

		if (rank == 0)
		{
			if ( m_skyboxMaterial != NULL && renderPass != RenderPass::PickingPass )
			{
				Transform transform(NULL);
				transform.SetPositionWorld( RenderManager::GetRenderCamera()->GetComponent<Transform>()->GetPositionWorld() );
				transform.SetScaleWorld( Vector3(m_skyboxSize) );

				MeshRenderer renderer;
				renderer.SetMaterial(m_skyboxMaterial);
				renderer.SetMesh(skyboxMesh);
				renderer.SetFaceCulling( FaceCulling::CULL_FRONT );

				RenderManager::ObjectToRender objectToRender;
				objectToRender.transform = &transform;
				objectToRender.meshRenderer = &renderer;
				objectToRender.renderPass = renderPass;

				RenderManager::RenderObject( objectToRender );
			}

			GizmoManager::RenderGrid( renderPass );
		}

#if (ME3D_SHADING_MODE == ME3D_CLASSIC_SHADING)
	
		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						RenderManager::AddActiveLight( activeLight );
					}
				}
			}
		}
#endif


		for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
		{
			GameObject* obj = m_layers[rank]->GetObjectAt(j);

			if ( !obj->IsIgnoringViewport(viewportName)
				&& obj->IsFullyActive() )
			{
				GizmoManager::RenderFollower( obj, renderPass );

				MeshRenderer* renderer = obj->GetComponent<MeshRenderer>();
				GuiTexture* guiTexture = obj->GetComponent<GuiTexture>();

				glEnable(GL_DEPTH_TEST);
				glDepthMask(GL_TRUE);

				glEnable(GL_BLEND);
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

				if (renderer != NULL &&
					renderer->GetMaterial() != NULL &&
					renderer->GetMesh() != NULL &&
					(ignoreShadowCast || renderer->IsCastingShadows()) )
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.transform = obj->GetComponent<Transform>();
					objectToRender.meshRenderer = renderer;
					objectToRender.renderPass = renderPass;

					RenderManager::RenderObject( objectToRender );
				}

				if (guiTexture != NULL)
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.guiTexture = guiTexture;

					RenderManager::RenderObject( objectToRender );
				}
			}
		}


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)

		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						switch (lightComp->GetType())
						{
						case LightType::Directional:
							RenderManager::DeferredDirectional(activeLight);
							break;
						case LightType::Point:
						case LightType::Spot:
							RenderManager::DeferredPointAndSpot(activeLight);
							break;
						}
					}
				}
			}
		}
#endif


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
		if (renderPass != RenderPass::PickingPass)
		{
			RenderManager::DeferredUnlit();
		}
#endif

		RenderManager::CollapseLayer(renderPass);

	} // end for
	 


	// layer for gizmo
	RenderManager::UseNewLayer(renderPass);
		
	GizmoManager::RenderTools(renderPass);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);



	// layer for menu
	RenderManager::UseNewLayer(renderPass);
		
	MenuManager::Render(renderPass, viewportName);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);

}