Пример #1
0
/*
Creates a really simple scene for our game - A cube robot standing on
a floor. As the module progresses you'll see how to get the robot moving
around in a physically accurate manner, and how to stop it falling
through the floor as gravity is added to the scene. 

You can completely change all of this if you want, it's your game!

*/
MyGame::MyGame()	{
	gameCamera = new Camera(-30.0f,0.0f,Vector3(0,450,850));

	Renderer::GetRenderer().SetCamera(gameCamera);

	CubeRobot::CreateCube();

	/*
	We're going to manage the meshes we need in our game in the game class!

	You can do this with textures, too if you want - but you might want to make
	some sort of 'get / load texture' part of the Renderer or OGLRenderer, so as
	to encapsulate the API-specific parts of texture loading behind a class so
	we don't care whether the renderer is OpenGL / Direct3D / using SOIL or 
	something else...
	*/
	cube	= new OBJMesh(MESHDIR"cube.obj");
	quad	= Mesh::GenerateQuad();
	sphere	= new OBJMesh(MESHDIR"ico.obj");

	/*
	A more 'robust' system would check the entities vector for duplicates so as
	to not cause problems...why not give it a go?
	*/
	GameEntity* quadEntity = BuildQuadEntity(1000.0f);
	allEntities.push_back(quadEntity);
	allEntities.push_back(BuildRobotEntity());
	
	GameEntity* ball0 = BuildSphereEntity(100.0f, Vector3(-300, 300, -100), Vector3(0, 0, 0));
	allEntities.push_back(ball0);
	GameEntity* ball1 = BuildSphereEntity(100.0f, Vector3(-100, 300, -100), Vector3(0, 0, 0));
	allEntities.push_back(ball1);


	Spring* s = new Spring(&ball0->GetPhysicsNode(), Vector3(0,100,0), &ball1->GetPhysicsNode(), Vector3(0,-100,0));
	
	PhysicsSystem::GetPhysicsSystem().AddConstraint(s);
	PhysicsSystem::GetPhysicsSystem().AddDebugDraw(s);


	s = new Spring(&ball1->GetPhysicsNode(), Vector3(0,100,0), &quadEntity->GetPhysicsNode(), Vector3(0,-100,-600)); // Note that these are relative positions and the quad is already rotated
	
	PhysicsSystem::GetPhysicsSystem().AddConstraint(s);
	PhysicsSystem::GetPhysicsSystem().AddDebugDraw(s);

	SpringDemo* demo = new SpringDemo();
	
	PhysicsSystem::GetPhysicsSystem().AddConstraint(demo);
	PhysicsSystem::GetPhysicsSystem().AddDebugDraw(demo);
	
}
Пример #2
0
/*
Creates a really simple scene for our game - A cube robot standing on
a floor. As the module progresses you'll see how to get the robot moving
around in a physically accurate manner, and how to stop it falling
through the floor as gravity is added to the scene. 

You can completely change all of this if you want, it's your game!

*/
MyGame::MyGame()	{
	gameCamera = new Camera(-30.0f,0.0f,Vector3(0,450,850));

	Renderer::GetRenderer().SetCamera(gameCamera);

	CubeRobot::CreateCube();

	ammo = 0;
	force = 0;
	/*
	We're going to manage the meshes we need in our game in the game class!

	You can do this with textures, too if you want - but you might want to make
	some sort of 'get / load texture' part of the Renderer or OGLRenderer, so as
	to encapsulate the API-specific parts of texture loading behind a class so
	we don't care whether the renderer is OpenGL / Direct3D / using SOIL or 
	something else...
	*/
	cube	= new OBJMesh(MESHDIR"cube.obj");
	cube->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	quad	= Mesh::GenerateQuad();
	
	sphere	= new OBJMesh(MESHDIR"ico2.obj");
	sphere->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	//fireEmitter = new FireEmitter();
	
	heightmap = new HeightMap(TEXTUREDIR"gametech.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds DOT3.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	/*
	A more 'robust' system would check the entities vector for duplicates so as
	to not cause problems...why not give it a go?
	*/
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		projectiles[i] = BuildSphereEntity(25.0f);
		projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i));
		projectiles[i]->GetPhysicsNode().sleep = true;
	}

	//allEntities.push_back(BuildFireEntity());
//	tempRobot = BuildRobotEntity();
//	tempRobot->GetPhysicsNode().SetPosition(Vector3(500.0f));
//	allEntities.push_back(tempRobot);
	allEntities.push_back(BuildQuadEntity(1000.0f));
	allEntities.push_back(BuildHeightmapEntity());
	
	BuildSprings();
	
	RenderCloth = new Cloth(cloth);
	RenderCloth->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"teatowel.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	allEntities.push_back(BuildClothEntity());
	
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		allEntities.push_back(projectiles[i]);
	}

	for(vector<GameEntity*>::iterator i = clothEntities.begin(); i!=clothEntities.end() - 1; i++) {
		allEntities.push_back((*i));
	}

	

}
/*
Creates a really simple scene for our game - A cube robot standing on
a floor. As the module progresses you'll see how to get the robot moving
around in a physically accurate manner, and how to stop it falling
through the floor as gravity is added to the scene. 

You can completely change all of this if you want, it's your game!

*/
MyGame::MyGame()	{

	destroyedEntities.clear();

	gameCamera = new Camera(-25, 180, 0.0f, Vector3(2000, 1350, -1100), Vector3(2, 2, 2));

	Renderer::GetRenderer().SetCamera(gameCamera);

	CubeRobot::CreateCube();

	/*
	We're going to manage the meshes we need in our game in the game class!

	You can do this with textures, too if you want - but you might want to make
	some sort of 'get / load texture' part of the Renderer or OGLRenderer, so as
	to encapsulate the API-specific parts of texture loading behind a class so
	we don't care whether the renderer is OpenGL / Direct3D / using SOIL or 
	something else...
	*/

	

	cube	= new OBJMesh(MESHDIR"cube.obj");
	quad	= Mesh::GenerateQuad();
	sphere	= new OBJMesh(MESHDIR"sphere.obj");
	quad->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"brick.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));
	quad->SetBumpMap(SOIL_load_OGL_texture(TEXTUREDIR"brickDOT3.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));
	heightmap = new HeightMap(TEXTUREDIR"terrain.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"GRASS.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(TEXTUREDIR"GRASS_NORMAL.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	

	sphereTexture = (SOIL_load_OGL_texture(TEXTUREDIR"earth.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));

	

	if (!quad->GetTexture() || !heightmap->GetTexture() || !heightmap->GetBumpMap())
	{
		return;
	}
	
	auto SetTextureRepeating = [](GLuint target, bool repeating)	{
		glBindTexture(GL_TEXTURE_2D, target);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeating ? GL_REPEAT : GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeating ? GL_REPEAT : GL_CLAMP);
		glBindTexture(GL_TEXTURE_2D, 0);
	};


	SetTextureRepeating(heightmap->GetTexture(), true);
	SetTextureRepeating(heightmap->GetBumpMap(), true);
 	SetTextureRepeating(quad->GetTexture(), true);
	SetTextureRepeating(quad->GetBumpMap(), true);
	SetTextureRepeating(sphereTexture, true);

	/*
	A more 'robust' system would check the entities vector for duplicates so as
	to not cause problems...why not give it a go?
	*/
//	allEntities.push_back(BuildRobotEntity());
	Quaternion newQuaternion = Quaternion::AxisAngleToQuaterion(Vector3(1.0f, 0, 0), 90);
	Vector3 position = Vector3(5000,-5000.0f,5000);
	allEntities.push_back(BuildQuadEntity(50000.0f,newQuaternion,position));
	//allEntities.push_back(BuildSphereEntity(200.0f));

	allEntities.push_back(BuildHeightmapEntity(HEIGHTMAP_SIZE, Vector3(0, 0, 0)));

	speedFactor = 10;
	sizeFactor = 5;

	CreateRestSpheres(Vector3(0, 2000.0f, 0), 250.0f);

	InitalizeTreesEntities();

	BuildDodgingEntities(250.0f, Vector3(0, 5000.0f, 0));
}