GameEntity* MyGame::BackFire(Vector3 pos) {

	GameEntity* g = new MoveSphere(new Cube(), new MoveSpherePhy(Quaternion::AxisAngleToQuaterion(Vector3(0, 1, 0), 90.0f), pos + Vector3(0, 0, 150)));

	SceneNode*		s = &g->GetRenderNode();
	PhysicsNode*	p = &g->GetPhysicsNode();

	Vector3 CamDir = gameCamera->GetCamDir();

	s->SetTransform(Matrix4::Translation(Vector3(1, 1, 1)) * Matrix4::Rotation( 90.0f, Vector3(1, 0, 0)));
	s->SetColour(Vector4(0, 0, 1, 1));
	s->type = 1; // For debug boxes. If 1 = debug boxes ON.
	s->SetBoundingRadius(50);
	
	s->SetModelScale(Vector3(10,10,20));
	p->SetDimension(s->GetModelScale());



	p->SetInverseMass(12.0f);
	p->SetSphereRadius(50);
	p->AddForce(-CamDir * 9000);


	p->SetOrientation(Quaternion::EulerAnglesToQuaternion(gameCamera->GetPitch(), gameCamera->GetYaw(), 0.0));
	p->isMissile = true;
	p->isBackFire = true;


	g->ConnectToSystems();

	return g;
}
GameEntity* MyGame::ShotProjectile(float msec){

	GameEntity* g = new MoveSphere(new Cube(), new MoveSpherePhy(Quaternion::AxisAngleToQuaterion(Vector3(0, 1, 0), 0.0f),Vector3(100,0,0)));

	SceneNode*		s = &g->GetRenderNode();
	PhysicsNode*	p = &g->GetPhysicsNode();

	Vector3 CamDir = gameCamera->GetCamDir();
	

	s->SetColour(Vector4(0, 0, 1, 1));
	s->type = 1; 
	s->SetBoundingRadius(50);
	s->SetTransform(Matrix4::Translation(Vector3(1, 1, 1)) * Matrix4::Rotation( 270.0f, Vector3(1, 0, 0)));
	s->SetModelScale(Vector3(10,10,20));
	p->SetDimension(s->GetModelScale());

	m_speed = m_speed * 1000;

	p->SetInverseMass(9.0f);
	p->SetSphereRadius(50);
	p->AddForce(CamDir * 7000);
	p->SetPosition(gameCamera->GetPosition());
	p->SetOrientation(Quaternion::EulerAnglesToQuaternion(gameCamera->GetPitch(), gameCamera->GetYaw(), 0.0));
	p->isMissile = true;

	g->ConnectToSystems();

	return g;
}
void MyGame::DestroySphereNode(SpherePhysicsNode* node)
{
	node->CollisionCounterToZero();
	for (vector<GameEntity*>::iterator i = allEntities.begin(); i != allEntities.end(); ++i) 
	{
		if (&((*i)->GetPhysicsNode()) == node)
		{
			Renderer::GetRenderer().rootMutex.lock();
			(*i)->DisconnectFromSystems();
			Renderer::GetRenderer().rootMutex.unlock();
			destroyedEntitiesMutex.lock();
			destroyedEntities.push_back(*i);
			destroyedEntitiesMutex.unlock();
			allEntities.erase(i);
			for (int i = 0; i < 27; i++)
			{
				int x = i % 3;
				--x;
				int z = (i / 3) % 3;
				--z;
				int y = (i / 9) % 3;
				--y;
				float size = node->GetRadius() / 3;
				GameEntity* newEntity = BuildSphereEntity(size, node->GetPosition() + (Vector3((float)x, (float)y, (float)z) * size));
				newEntity->GetPhysicsNode().SetLinearVelocity(node->GetLinearVelocity() + (Vector3((float)x, (float)y, (float)z) * REMAINANT_SPEED));
				allEntities.push_back(newEntity);
			}
			break;
		}
	}
	node->SetAngularVelocity(Vector3(0, 0, 0));
	node->SetLinearVelocity(Vector3(0, 0, 0));
}
void MyGame::CreateRestSpheres(Vector3 position, float size)
{
	for (int counter = 0; counter < SPHEPE_PER_AXIS * SPHEPE_PER_AXIS * SPHEPE_PER_AXIS; counter++)
	{
		int x = counter % SPHEPE_PER_AXIS;
		int z = (counter / SPHEPE_PER_AXIS) % SPHEPE_PER_AXIS;
		int y = (counter / (SPHEPE_PER_AXIS * SPHEPE_PER_AXIS)) % SPHEPE_PER_AXIS;

		Vector3 currentPosition = Vector3(position.x + x * 3 * size, position.y + y * 3 * size, position.z + z * 3 * size);

		GameEntity *currentEntity = BuildSphereEntity(size, currentPosition);
		currentEntity->GetPhysicsNode().GetTarget()->SetColour(Vector4((((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, 1.0f));
		currentEntity->GetPhysicsNode().Update(0.0f);
		currentEntity->GetPhysicsNode().DeactivateNode();

		allEntities.push_back(currentEntity);
	}
}
Example #5
0
GameEntity* MyGame::BuildClothEntity() {
	GameEntity* g = new GameEntity(new SceneNode(RenderCloth), new PhysicsNode());
	g->ConnectToSystems();
	
	g->GetRenderNode().useNormal = 0;
	g->GetRenderNode().SetBoundingRadius(5000.0f);
	if(g->GetRenderNode().GetMesh()->GetTexture()){
		glBindTexture(GL_TEXTURE_2D, g->GetRenderNode().GetMesh()->GetTexture());
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	g->GetPhysicsNode().addCV(new CollisionSphere(Vector3(0,0,0),0.0f));
	g->GetPhysicsNode().gravity = false;


	return g;


}
Example #6
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);
	
}