Esempio n. 1
0
int main(int argc, char* argv[])
{
	bool bIsbowlingMode = false;
	std::wstring input2 = L"Hello! Please enter 1 if you wish to try the bowling mode. Enter anything else to play checkpoint mode";
	std::wcout << input2 << std::endl;
	std::wstring input;
	std::getline(std::wcin, input);
	if (input == L"1")
	{
		bIsbowlingMode = true;
	}

	bool bLoadTires = false;
	std::wstring input3 = L"Would you like to load the tire models? (loading tires may cause slowdown) y/n";
	std::wcout << input3 << std::endl;
	std::wstring input4;
	std::getline(std::wcin, input4);
	if (input4 == L"y")
	{
		bLoadTires = true;
	}


	printTheWhatsThisProgramAboutBlurb();

	::g_gameState.currentGameMode = CGameState::GAME_LOADING;

	::OpenGL_Initialize( argc, argv, 1200, 800 );		// Initialize(argc, argv);
	//::OpenGL_Initialize( argc, argv, 640, 480 );		// Initialize(argc, argv);


	// CModelLoaderManager
	g_pModelLoader = new CModelLoaderManager();
	g_pModelLoader->SetRootDirectory( "assets/models" );

	std::vector< CModelLoaderManager::CLoadInfo > vecModelsToLoad;

	if (bIsbowlingMode)
		ReadInModelsInfo("assets/BowlingScene.txt");
	else 
		ReadInModelsInfo("assets/Scene.txt");

	for (unsigned int i = 0; i < vecModelsInfo.size(); i++)
	{
		::g_mapModelTypes[vecModelsInfo[i].type] = vecModelsInfo[i].file;
		if (vecModelsInfo[i].tex.size() > 0)
			::g_mapTextures[i] = vecModelsInfo[i].tex[0];
		//vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(vecModelsInfo[i].file, 1.0f, true));
	}
	for (unsigned int i = 0; i < vecModelsInfo.size(); i++)
	{
		for (std::map<std::string, std::string>::iterator jIterator = g_mapModelTypes.begin(); jIterator != ::g_mapModelTypes.end(); jIterator++)
		{
			if (vecModelsInfo[i].type == jIterator->first){
				if (vecModelsInfo[i].isEnvironment){
					vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(jIterator->second));
				}
				else
					vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(jIterator->second, 1.0f, true));
			}
		}
	}

	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("sphere_UV_xyz.ply", 1.0f, true) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("Cube.ply", 1.0f, true ) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("Cube2.ply", 1.0f, true));
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("1x1_6_Star_2_Sided.ply", 1.0f, true ) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("truck.ply", 1.0f, true));
	//vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("truck2.ply", 1.0f, true));
	if (bLoadTires)
		vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("tire.ply", 1.0f, true));

	if ( ! g_pModelLoader->LoadModels( vecModelsToLoad ) )
	{
		std::cout << "Can't load one or more models. Sorry it didn't work out." << std::endl;
		return -1;
	}

	g_pShaderManager = new CGLShaderManager();
	//LoadShaders();		// Moved from CreateCube
	CShaderDescription uberVertex;
	uberVertex.filename = "assets/shaders/OpenGL.LightTexSkyUber.vertex.glsl";
	uberVertex.name = "UberVertex";

	CShaderDescription uberFragment;
	uberFragment.filename = "assets/shaders/OpenGL.LightTexSkyUber.fragment_texture.glsl";
	uberFragment.name = "UberFragment";

	CShaderProgramDescription uberShader("UberShader", uberVertex, uberFragment );

	if ( !g_pShaderManager->CreateShaderProgramFromFile( uberShader ) )
	{
		std::cout << "Error compiling one or more shaders..." << std::endl;
		std::cout << g_pShaderManager->getLastError() << std::endl;
		std::cout << uberShader.getErrorString() << std::endl;
		return -1;
	}

	::SetUpTextures();

	std::cout << "Starting Havok" << std::endl;
	g_pFactoryMediator = new CFactoryMediator();
	// ******************************************************
	// Set up the Havok physics thing
	// Create a Havok Physic thingie:
	// Passing "Havok" gives us a physics manager using Havok. 
	// Anything else is an error...
	// if crashing on release, right click on Desktop->NVIDIA Contol Panel->Set PhysX configuration. Select a PhysX dropdown menu->CPU
	//::g_pPhysicsManager = CPhysicsManagerFactory::CreatePhysicsMananger( L"Havok" ); 

	if ((::g_pPhysicsManager = CPhysicsManagerFactory::CreatePhysicsMananger(L"Havok")) == 0){
		std::cout << "Failed Creating Havok" << std::endl;  std::cout.flush();
	}
	// 
	std::cout << "Havok Created" << std::endl; std::cout.flush();
	std::vector< CNameValuePair2 > vecParams;
	vecParams.push_back( CNameValuePair2( L"VisualDebugger", true ) );

	::g_pPhysicsManager->Init(vecParams); 
	// ******************************************************************
	
	std::cout << "Done with physics." << std::endl;	std::cout.flush();

	static const float oneDegreeInRadians = static_cast<float>(PI) / 180.0f;

	for (unsigned i = 0; i < vecModelsInfo.size(); i++)
	{
		CPhysicalProp physicalProp;
		physicalProp.position = vecModelsInfo[i].pos;
		physicalProp.setOrientationEulerAngles(CVector3f(oneDegreeInRadians * vecModelsInfo[i].rot.x, oneDegreeInRadians * vecModelsInfo[i].rot.y, oneDegreeInRadians * vecModelsInfo[i].rot.z));
		physicalProp.rotStep = vecModelsInfo[i].rot;

		CMeshDesc mesh(vecModelsInfo[i].file);
		mesh.scale = vecModelsInfo[i].scale;
		mesh.bIsSkybox = vecModelsInfo[i].isSkybox;
		mesh.bIsPlayer = vecModelsInfo[i].isPlayer;
		mesh.modelID = i;
		mesh.blend = vecModelsInfo[i].blend;
		mesh.debugColour = CVector4f(vecModelsInfo[i].col.x, vecModelsInfo[i].col.y, vecModelsInfo[i].col.z, 1.0f);
		mesh.bIsParticle = vecModelsInfo[i].isParticle;

		if (vecModelsInfo[i].isTransparent){
			mesh.bIsTransparent = true;
			mesh.tranparency = vecModelsInfo[i].transparency;
		}
		else{
			mesh.bIsTransparent = false;
			mesh.tranparency = 1.0f;
		}

		if (vecModelsInfo[i].tex.size() > 0)
		{
			mesh.bHasTexture = true;
			mesh.firstTex = vecModelsInfo[i].firstTex;
		}


		mesh.ObjectType = vecModelsInfo[i].type;
		if (vecModelsInfo[i].isSkybox || vecModelsInfo[i].isParticle)
			mesh.bIsHavok = false;

		vecModelsInfo[i].ID = g_pFactoryMediator->CreateObjectByType(vecModelsInfo[i].type, physicalProp, mesh);

		makeHavokObject(vecModelsInfo[i].ID);

		if (vecModelsInfo[i].isPlayer)
			::g_FloorHavokID = vecModelsInfo[i].ID;
		if (vecModelsInfo[i].isSkybox)
			::g_skyBoxID = vecModelsInfo[i].ID;
		//if (vecModelsInfo[i].isLightBall)
		//	::g_lightModelID = vecModelsInfo[i].ID;
		if (vecModelsInfo[i].isParticle)
			::g_vecParticleID.push_back(vecModelsInfo[i].ID);
	}
	
	

	CMeshDesc sphereMesh("sphere_UV_xyz.ply");
	sphereMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	sphereMesh.bIsTransparent = true;
	sphereMesh.tranparency = 0.4f;
	CPhysicalProp sphereProps( CVector3f( 0.0f, 5.0f, 4.0f ) );
	sphereProps.position = (CVector3f(0.0f, 5.0f, 0.0f));
	::g_lightModelID = g_pFactoryMediator->CreateObjectByType( "Sphere UV", sphereProps, sphereMesh );

	CMeshDesc sphereHavokMesh("sphere_UV_xyz.ply");
	sphereHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	sphereHavokMesh.ObjectType = "Star";
	sphereHavokMesh.bIsHavok = false;
	CPhysicalProp sphereHavokProps( CVector3f( 0.0f, 5.0f, -10.0f ) );
	::g_StarHavokID = g_pFactoryMediator->CreateObjectByType( "Sphere UV", sphereHavokProps, sphereHavokMesh );

	//makeHavokObject(::g_StarHavokID);




	//for (int i = 1; i < 4; i++){
	//	for (int j = 1; j < 4; j++){
	//		CMeshDesc floorHavokMesh("Cube2.ply");
	//		floorHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);

	//		floorHavokMesh.bHasTexture = true;
	//		if (i == 2 && j == 2){
	//			floorHavokMesh.ObjectType = "IceFloor";
	//		}
	//		else {
	//			floorHavokMesh.ObjectType = "GroundFloor";
	//		}
	//		floorHavokMesh.scale = floorSize;
	//		//CPhysicalProp floorHavokProps(CVector3f(-(floorSize / 2.0f), -floorSize, -(floorSize / 2.0f)));
	//		CVector3f floorPosition;
	//		floorPosition.x = i*(-(floorSize / 2.0f));
	//		floorPosition.z = j*(-(floorSize / 2.0f));
	//		floorPosition.y = -floorSize;
	//		CPhysicalProp floorHavokProps(floorPosition);
	//		unsigned int floorID = g_pFactoryMediator->CreateObjectByType("Cube UV", floorHavokProps, floorHavokMesh);

	//		makeHavokObject(floorID);
	//	}
	//}

	CMeshDesc truckMesh("truck.ply");
	truckMesh.ObjectType = "Vehicle";
	truckMesh.scale = 5.0f;

	CPhysicalProp truckProps(CVector3f(0.0f, 5.0f, 4.0f));
	truckProps.position = (CVector3f(0.0f, 5.0f, 0.0f));
	::g_Player_ID = g_pFactoryMediator->CreateObjectByType("Player", truckProps, truckMesh);

	makeHavokObject(::g_Player_ID);

	if (bLoadTires){
		CMeshDesc tireMesh("tire.ply");
		tireMesh.bIsHavok = false;
		tireMesh.scale = 1.0f;
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
	}
	



	/*CMeshDesc checkpointHavokMesh("Cube2.ply");
	checkpointHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	checkpointHavokMesh.ObjectType = "CheckPoint";
	CPhysicalProp checkpointHavokProps(CVector3f(0.0f, 0.0f, 0.0f));
	unsigned int checkpoint_ID = g_pFactoryMediator->CreateObjectByType("Sphere UV", checkpointHavokProps, checkpointHavokMesh);

	makeHavokObject(checkpoint_ID);*/

	



	g_pPhysicsManager->SetCheckPoints(vecCheckPointsInfo);

	//g_pPhysicsManager

	//GenerateAABBWorld();

	// Added October 3, 2014
	g_pCamera = new CCamera();
	// Camera expects an IMediator*, so cast it as that
	g_pCamera->SetMediator( (IMediator*)g_pFactoryMediator );

	g_pCamera->eye.x = 0.0f;		// Centred (left and right)
	g_pCamera->eye.y = 5.0f;		// 2.0 units "above" the "ground"
	g_pCamera->eye.z = -20.0f;		// .0funits0 from "back" the origin    .  1, 2.5, 1.8
	g_pCamera->target.x = 50.0f;		// Centred (left and right)
	g_pCamera->target.y = 350.0f;		// 2.0 units "above" the "ground"
	g_pCamera->target.z = 50.0f;		// 0.0 units "back" from the origin
	g_pCamera->cameraAngleYaw = 2.8f;
	g_pCamera->cameraAnglePitch = -0.2f;

	g_pCamera->up.x = 0.0f;
	g_pCamera->up.y = 1.0f;				// The Y axis is "up and down"

	g_pCamera->m_LEFPLookupMode = CCamera::LERP;

	g_pCamera->setMode_FollowAtDistance( ::g_Player_ID );
	float followSpeed = 30.0f;		// 1.0f whatever per second
	float followMinDistance = 3.0f;
	float followMaxSpeedDisance = 100.0f;
	g_pCamera->setFollowDistances( followMinDistance, followMaxSpeedDisance );
	g_pCamera->setFollowMaxSpeed( followSpeed );

	// A "fly through" camera
	// These numbers are sort of in the direction of the original camera
	g_pCamera->orientation = glm::fquat( 0.0960671529f, 0.972246766f, -0.0900072306f, -0.193443686f );
	glm::normalize( g_pCamera->orientation );
	//g_pCamera->setMode_IndependentFreeLook();


	g_pMouseState = new CMouseState();

	// Set up the basic lighting
	ExitOnGLError("Error setting light values");
	SetupLights();

		//
	if ( !::g_p_LightManager->initShadowMaps( 1, CLightManager::DEFAULT_SHADOW_DEPTH_TEXTURE_SIZE ) )
	{
		std::cout << "Error setting up the shadow textures: " << std::endl;
		std::cout << ::g_p_LightManager->getLastError();
	}

	setUpShadowTexture();


	g_p_GameControllerManager = CGameControllerManager::getGameControllerManager();
	g_p_GameController_0 = g_p_GameControllerManager->getController(0);
	if ( ( g_p_GameController_0 != 0 ) && 
		 ( g_p_GameController_0->bIsConnected() ) )
	{
		g_p_GameController_0->AddVibrationSequence( IGameController::CVibStep::LEFT, 0.5f, 2.0f );
		g_p_GameController_0->AddVibrationSequence( IGameController::CVibStep::RIGHT, 0.5f, 1.0f );
		std::cout << "Game controller 0 found!" << std::endl;
	}
	else 
	{
		std::cout << "Didn't get an ID for the game controller; is there one plugged in?" << std::endl;
	}


	//***************************************
	g_p_checkpointEmitter = new CParticleEmitter();
	g_p_timerEmitter = new CParticleEmitter();
	//**************************************

	CPhysicalProp starProps;
	::g_pFactoryMediator->getPhysicalPropertiesByID(::g_StarHavokID, starProps);
	g_p_checkpointEmitter->SetLocation(starProps.position);
	::g_p_checkpointEmitter->GenerateParticles(1, /*number of particles*/
		CVector3f(0.0f, 0.0f, 0.0f), /*Init veloc.*/
		0.1f, /*dist from source */
		5.0f, /*seconds*/
		true);
	::g_p_checkpointEmitter->SetAcceleration(CVector3f(0.0f, 0.0f, 0.0f));

	g_p_timerEmitter->SetLocation(truckProps.position);
	::g_p_timerEmitter->GenerateParticles(1, /*number of particles*/
		CVector3f(0.0f, 1.0f, 0.0f), /*Init veloc.*/
		0.01f, /*dist from source */
		1.0f, /*seconds*/
		true);
	::g_p_timerEmitter->SetAcceleration(CVector3f(0.0f, 1.0f, 0.0f));



	::g_p_PhysicsThingy = new CPhysicsCalculatron();


	// Added in animation on Sept 19
	::g_simTimer.Reset();
	::g_simTimer.Start();		// Start "counting"

	if (bIsbowlingMode)
	{
		::g_gameState.currentGameMode = CGameState::GAME_BOWLING;
	}
	else
		::g_gameState.currentGameMode = CGameState::GAME_RUNNING;
	
	// FULL SCREEN, Mr. Data!
	//::glutFullScreen();

	ExitOnGLError("Error getting uniform light variables");

	glutMainLoop();

	std::cout << "Shutting down..." << std::endl;

	ShutDown();
  
	exit(EXIT_SUCCESS);
}
Esempio n. 2
0
bool NzMaterial::Initialize()
{
	bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);

	// Basic shader
	{
		std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
		uberShader->SetPersistent(false);

		NzString fragmentShader;
		NzString vertexShader;
		if (glsl140)
		{
			const nzUInt8 coreFragmentShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/Basic/core.frag.h>
			};

			const nzUInt8 coreVertexShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/Basic/core.vert.h>
			};

			fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
			vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
		}
		else
		{
			const nzUInt8 compatibilityFragmentShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.frag.h>
			};

			const nzUInt8 compatibilityVertexShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.vert.h>
			};

			fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
			vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
		}

		uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
		uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_INSTANCING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");

		NzUberShaderLibrary::Register("Basic", uberShader.get());
		uberShader.release();
	}

	// PhongLighting shader
	{
		std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
		uberShader->SetPersistent(false);

		NzString fragmentShader;
		NzString vertexShader;
		if (glsl140)
		{
			const nzUInt8 coreFragmentShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
			};

			const nzUInt8 coreVertexShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
			};

			fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
			vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
		}
		else
		{
			const nzUInt8 compatibilityFragmentShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.frag.h>
			};

			const nzUInt8 compatibilityVertexShader[] = {
				#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.vert.h>
			};

			fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
			vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
		}

		uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED ALPHA_MAPPING ALPHA_TEST DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
		uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_DEFERRED FLAG_INSTANCING COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");

		NzUberShaderLibrary::Register("PhongLighting", uberShader.get());
		uberShader.release();
	}

	s_defaultMaterial = new NzMaterial;
	s_defaultMaterial->SetPersistent(true);

	s_defaultMaterial->Enable(nzRendererParameter_FaceCulling, false);
	s_defaultMaterial->SetFaceFilling(nzFaceFilling_Line);

	return true;
}