void MyGame::CreateSphereToCameraPosition()
{
	SceneNode* s = new SceneNode(sphere);
	s->SetRotation(Matrix4::Translation(gameCamera->GetPosition()));
	//s->SetTranslation(Vector3());

	s->SetModelScale(Vector3(SPHERE_INITIAL_SIZE * sizeFactor, SPHERE_INITIAL_SIZE * sizeFactor, SPHERE_INITIAL_SIZE * sizeFactor));
	//s->SetModelScale(Vector3(1000.0f, 1000.0f , 1000.0f));

	s->SetBoundingRadius(SPHERE_INITIAL_SIZE * sizeFactor);
	s->SetColour(Vector4((((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, (((int)rand()) % 100) / 100.0f, 1.0f));

	GameEntity*g = new GameEntity(s, new SpherePhysicsNode());
	((SpherePhysicsNode&)(g->GetPhysicsNode())).SetRadius(SPHERE_INITIAL_SIZE*sizeFactor);

	g->GetPhysicsNode().SetPosition(gameCamera->GetPosition());

	cout << "sphere created on position " << gameCamera->GetPosition() << endl;

	g->GetPhysicsNode().SetInvMass(SPHERE_INITIAL_INVMASS / sizeFactor);
	Vector3 speedVec = gameCamera->GetViewVector();
	speedVec = speedVec * SPHERE_INITIAL_SPEED * (const float)speedFactor;
	g->GetPhysicsNode().SetLinearVelocity(speedVec);
	g->GetPhysicsNode().SetGravityFactor(EARTH_GRAVITY_FACTOR);
	g->GetPhysicsNode().ActivateNode();

	g->GetPhysicsNode().BuildInertiaMatrix();
	g->ConnectToSystems();
	allEntities.push_back(g);
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
Renderer::Renderer(Window &parent) : OGLRenderer(parent) {
	CubeRobot::CreateCube();
	projMatrix = Matrix4::Perspective(1.0f, 10000.0f, (float)width/(float)height, 45.0f);
	camera = new Camera();
	camera->SetPosition(Vector3(0, 100, 750.0f));

	currentShader = new Shader("../../Shaders/SceneVertex.glsl", "../../Shaders/SceneFragment.glsl");
	quad = Mesh::GenerateQuad();
	quad->SetTexture(SOIL_load_OGL_texture("../../Textures/stainedglass.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));

	if (!currentShader->LinkProgram() || !quad->GetTexture()){
		return;
	}
	
	root = new SceneNode();

	for (int i = 0; i < 5; ++i){
		SceneNode* s = new SceneNode();
		s->SetColour(Vector4(1.0f, 1.0f, 1.0f, 0.5f));
		s->SetTransform(Matrix4::Translation(Vector3(0,100.0f, -300.0f + 100.0f + 100 * i)));
		s->SetModelScale(Vector3(100.0f, 100.0f, 100.0f));
		s->SetBoundingRadius(100.0f);
		s->SetMesh(quad);
		root->AddChild(s);
	}

	root->AddChild(new CubeRobot());

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	init = true;
}
Пример #5
0
MyGame::MyGame()	{

	gameCamera = new Camera(-30.0f,0.0f,Vector3(0,450,850));
	gameCamera -> SetYaw(180);
	gameCamera -> SetPitch(-40);
	gameCamera -> SetPosition(Vector3(2000.0,1300.0f,-400.0f));

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

	CubeRobot::CreateCube();
	KPAXNode::KPAXNode();

	FirstProjectile::CreateCube();
	Cube::CreateCube();
	//////////////////////////For the SpaceShips///////////////////////////////////////////////////

	KPAXNode::DeployShips();

	///////////////////////////////////////////////////////////////////////////////////////////////
	SceneNode* s = new Cube();
	s->SetModelScale(Vector3(500.0f,500.0f,500.0f));
	s->SetBoundingRadius(100); 
	cubeObj = new MoveCube(s, new PhysicsNode());


	////////////////////////////////////////////////////////////////////////////////////////////////

	SceneNode* s2 = new Cube();
	sphereObj = new MoveSphere(s2, new MoveSpherePhy(Quaternion::AxisAngleToQuaterion(Vector3(1, 0, 0), 90.0f),Vector3(100,0,0)));
	
	////////////////////////////////////////////////////////////////////////////////////////////////


	cube			= new OBJMesh("../../Meshes/cube.obj");
	quad			= Mesh::GenerateQuad();
	sphere			= new OBJMesh("../../Meshes/ico.obj");
	sphere2			= new OBJMesh("../../Meshes/sphere.obj");
	
	heightMap2		= new HeightMap("../../Textures/KPAX-Fin2.raw");


	// Connect to the system.
	allEntities.push_back(BuildCubeEntity(10));
	allEntities.push_back(BuildCube2(10));

	allEntities.push_back(BuildSpaceShip(Vector3(0, 300, 0)));
	allEntities.push_back(BuildSpaceShip(Vector3(2000, 1000, 300)));
	allEntities.push_back(BuildSpaceShip(Vector3(1000, 300, 800)));
	allEntities.push_back(BuildSpaceShip(Vector3(500, 700, 3000)));





}
Пример #6
0
/*
Makes a sphere.
*/
GameEntity* MyGame::BuildSphereEntity(float radius) {
	SceneNode* s = new SceneNode(sphere2);

	s->SetModelScale(Vector3(radius,radius,radius));
	s->SetBoundingRadius(radius);
	
	PhysicsNode*p = new PhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1,0,0), 90.0f), Vector3(0, 100, 0));
	GameEntity*g = new GameEntity(s, p);
	g->ConnectToSystems();
	return g;
}
Пример #7
0
CubeRobot::CubeRobot(void) {
	//optional -- create a local origin marker
	//SetMesh(cube);

	SceneNode*body = new SceneNode(cube, Vector4(1, 0, 0, 1)); 
	body->SetModelScale(Vector3(10, 15, 5));
	body->SetLocalTransform(Matrix4::Translation(Vector3(0, 35, 0)));
	AddChild(body);

	head = new SceneNode(cube, Vector4(0, 1, 0, 1));
	head->SetModelScale(Vector3(5, 5, 5));
	head->SetLocalTransform(Matrix4::Translation(Vector3(0, 30, 0)));
	body->AddChild(head);

	leftArm = new SceneNode(cube, Vector4(0, 0, 1, 1));
	leftArm->SetModelScale(Vector3(3, -18, 3));
	leftArm->SetLocalTransform(Matrix4::Translation(Vector3(-12, 30, -1)));
	body->AddChild(leftArm);

	rightArm = new SceneNode(cube, Vector4(0, 0, 1, 1));
	rightArm->SetModelScale(Vector3(3, -18, 3));
	rightArm->SetLocalTransform(Matrix4::Translation(Vector3(12, 30, -1)));
	body->AddChild(rightArm);

	SceneNode* leftLeg = new SceneNode(cube, Vector4(0, 0, 1, 1));
	leftLeg->SetModelScale(Vector3(3, -17.5, 3));
	leftLeg->SetLocalTransform(Matrix4::Translation(Vector3(-8, 0, 0)));
	body->AddChild(leftLeg);

	SceneNode* rightLeg = new SceneNode(cube, Vector4(0, 0, 1, 1));
	rightLeg->SetModelScale(Vector3(3, -17.5, 3));
	rightLeg->SetLocalTransform(Matrix4::Translation(Vector3(8, 0, 0)));
	body->AddChild(rightLeg);

	body->SetBoundingRadius(15.0f);
	head->SetBoundingRadius(5.0f);
	leftArm->SetBoundingRadius(18.0f);
	rightArm->SetBoundingRadius(18.0f);
	leftLeg->SetBoundingRadius(18.0f);
	rightLeg->SetBoundingRadius(18.0f);
}
Пример #8
0
/*
Makes a flat quad
*/
GameEntity* MyGame::BuildQuadEntity(float size) {
	SceneNode* s = new SceneNode(quad);

	s->SetModelScale(Vector3(size,size,size));
	s->SetBoundingRadius(size);
	PhysicsNode*p = new PhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1,0,0), 90.0f), Vector3());
	GameEntity*g = new GameEntity(s, p);

	p->isPlane = true;
	g->ConnectToSystems();
	return g;
}
/*
Makes a flat quad, initially oriented such that we can use it as a simple
floor. 
*/
GameEntity* MyGame::BuildQuadEntity(float size, const Quaternion& direction, const Vector3& position) {
	SceneNode* s = new SceneNode(quad);

	s->SetModelScale(Vector3(size,size,size));
	//Oh if only we had a set texture function...we could make our brick floor again WINK WINK
	s->SetBoundingRadius(size * 2.0f);

	SquarePhysicsNode*p = new SquarePhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1, 0, 0), 90.0f), position);
	
	p->ActivateNode();
	GameEntity*g = new GameEntity(s, p);
	p->BuildInertiaMatrix();
	g->ConnectToSystems();
	return g;
}
Пример #10
0
GameEntity* MyGame::DrawMyAnything() {

	SceneNode*	s =  new FirstProjectile();

	s->SetModelScale(Vector3(50.0f, 50.0f, 50.0f));
	s->SetBoundingRadius(50.0f);

	PhysicsNode *p = new PhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1, 0, 0), 90.0f), Vector3(1,1,1));

	GameEntity* g =  new GameEntity(s, p);
	g->ConnectToSystems();

	return g;

}
GameEntity* MyGame::BuildHeightmapEntity(float size, Vector3& position)
{
	SceneNode* s = new SceneNode(heightmap);

	s->SetModelScale(Vector3(size, size / 4, size));
	s->SetBoundingRadius(size * 5000.0f);

	HeightmapPhysicsNode *p = new HeightmapPhysicsNode(position);
	p->SetTarget(s);
	p->ActivateNode();
	GameEntity*g = new GameEntity(s, p);
	p->BuildInertiaMatrix();
	g->ConnectToSystems();
	return g;
}
Пример #12
0
/*
Makes a flat quad, initially oriented such that we can use it as a simple
floor. 
*/
GameEntity* MyGame::BuildQuadEntity(float size) {
	SceneNode* s = new SceneNode(quad);

	s->SetModelScale(Vector3(size,size,size));
	//Oh if only we had a set texture function...we could make our brick floor again WINK WINK
	s->SetBoundingRadius(size);

	PhysicsNode*p = new PhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1,0,0), 90.0f), Vector3());
	p->SetUseGravity(false);
	p->SetInverseMass(0.0f);
	p->SetInverseInertia(InertialMatrixHelper::createImmovableInvInertial());
	p->SetCollisionVolume(new CollisionPlane(Vector3(0,1,0), 0));
	GameEntity*g = new GameEntity(s, p);
	g->ConnectToSystems();
	return g;
}
Пример #13
0
/*
Makes a sphere.
*/
GameEntity* MyGame::BuildSphereEntity(float radius, Vector3 pos, Vector3 vel) {
	SceneNode* s = new SceneNode(sphere);

	s->SetModelScale(Vector3(radius,radius,radius));
	s->SetBoundingRadius(radius);
	s->SetColour(Vector4(0.2,0.2,0.5,1));
	PhysicsNode*p = new PhysicsNode();
	p->SetPosition(pos);
	p->SetLinearVelocity(vel);
	p->SetAngularVelocity(Vector3(0,0,0.01f));
	p->SetInverseInertia(InertialMatrixHelper::createSphereInvInertial(1.0f, radius));
	p->SetInverseMass(1.0f);
	p->SetCollisionVolume(new CollisionSphere(radius));
	GameEntity*g = new GameEntity(s, p);
	g->ConnectToSystems();
	return g;
}
Пример #14
0
/*
Makes a flat quad, initially oriented such that we can use it as a simple
floor. 
*/
GameEntity* MyGame::BuildQuadEntity(float size) {
	SceneNode* s = new SceneNode(quad);

	s->SetModelScale(Vector3(size,size,size));
	s->SetBoundingRadius(size);
	//s->SetColour(Vector4(0.0f,1.0f,0.0f,1.0f));
	s->SetTexture(TEXTUREDIR"grass.jpg");
	
	PhysicsNode*p = new PhysicsNode(Quaternion::AxisAngleToQuaterion(Vector3(1,0,0), 90.0f), Vector3(), false);
	p->setInvMass(0);
	GameEntity*g = new GameEntity(s, p);
	g->GetPhysicsNode().addCV(new CollisionPlane(Vector3(0.0f,-1.0f,0.0f),0.0f));
	g->GetPhysicsNode().dynamic = false;
	
	g->ConnectToSystems();
	return g;
}
/*
Makes a sphere.
*/
GameEntity* MyGame::BuildSphereEntity(float radius, const Vector3& position) {
	SceneNode* s = new SceneNode(sphere);

	s->SetRotation(Matrix4::Translation(position));

	s->SetModelScale(Vector3(radius,radius,radius));
	s->SetBoundingRadius(radius);

	GameEntity*g = new GameEntity(s, new SpherePhysicsNode());
	((SpherePhysicsNode&)(g->GetPhysicsNode())).SetRadius(radius);
	g->GetPhysicsNode().SetPosition(position);
	g->GetPhysicsNode().SetGravityFactor(EARTH_GRAVITY_FACTOR);
	float massFactor = radius / SPHERE_INITIAL_SIZE;
	g->GetPhysicsNode().SetInvMass(SPHERE_INITIAL_INVMASS / massFactor);
	g->GetPhysicsNode().ActivateNode();
	g->GetPhysicsNode().BuildInertiaMatrix();
	g->ConnectToSystems();
	return g;
}
Пример #16
0
Renderer::Renderer(Window &parent) : OGLRenderer(parent)	{
	camera		= new Camera(0,0,Vector3(0,0,100));
	cube		= new OBJMesh(MESHDIR"centeredCube.obj");	//A cube surrounding the origin!
	triangle    = Mesh::GenerateTriangle();	//And a triangle to use as the mouse pointer...

	cube->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"brick.tga",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	if(!cube->GetTexture()) {
		return;
	}
	//We don't need to do anything fancy with shaders this time around, so we're
	//going to borrow the scene shader from tutorial 6
	currentShader = new Shader(SHADERDIR"SceneVertex.glsl", SHADERDIR"SceneFragment.glsl");

	if(!currentShader->LinkProgram()) {
		return;
	}

	//Our renderer's root node!
	root  = new SceneNode();
	root->SetBoundingRadius(0.0f);

	//To show off picking, we're going to Make a 10 by 10 grid of cubes.
	//As they're all going to be children of the root node, all 100
	//of them will be drawn using a single draw call on the root. 
	for(int x = 0; x < 10; ++x) {
		for(int z = 0; z < 10; ++z) {
			SceneNode* n = new SceneNode();
			n->SetMesh(cube);
			n->SetModelScale(Vector3(10,10,10));
			n->SetBoundingRadius(10.0f);
			n->SetTransform(Matrix4::Translation(Vector3(x*50.0f,0,-z*50.0f)));
			root->AddChild(n);
		}
	}

	glEnable(GL_DEPTH_TEST);
	init = true;
}
void MyGame::BuildDodgingEntities(float size, Vector3& initialPosition)
{
	SceneNode* s = new SceneNode(sphere);

	s->SetColour(Vector4(1.0f, 1.0f, 1.0f, 1.0f));

	s->SetRotation(Matrix4::Translation(initialPosition));

	s->SetModelScale(Vector3(size, size, size));
	s->SetBoundingRadius(size);
	
	SpherePhysicsNode* g = new SpherePhysicsNode();
	g->SetRadius(size);
	g->SetPosition(initialPosition);
	g->SetGravityFactor(NON_GRAVITY);
	float massFactor = size / SPHERE_INITIAL_SIZE;
	g->SetInvMass(SPHERE_INITIAL_INVMASS / massFactor);
	g->ActivateNode();
	g->BuildInertiaMatrix();
	g->SetTarget(s);
	g->dumpingFactor = 0.9f;
	Renderer::GetRenderer().AddNode(s);
	PhysicsSystem::GetPhysicsSystem().SetDodgingEntity(g);
}
Пример #18
0
void MyGame::BuildSprings() {
	
	float radius = 50.0f;
	int nrt = 7;
	int n= nrt*nrt;
	float space = 40.0f;
	float mass = 2.0f;
	float ks = 5.0f; //5.0
	float kd = 0.99f;

	cloth = new PhysicsCloth(7, 7);
	
	//CHANGE THIS EVERYTIME YOU CHANGE NRT
	SpringNode* springmesh[7][7];
	vector<GameEntity*> gv;
	vector<Spring*> s;
	for(int i = 0; i < n; i++) {
		SceneNode* rn = new SceneNode();

		rn->SetModelScale(Vector3(radius,radius,radius));
		rn->SetBoundingRadius(radius);
		rn->SetColour(Vector4(1.0f,1.0f,1.0f,1.0f));

		
		float temp = (1.0) / ((0.2f) * (2 * mass * radius * radius));
		SpringNode* sn = new SpringNode(Vector3(space * (i%nrt), 1000.0f,space*(i/nrt)));
		springmesh[i%nrt][i/nrt] = sn;
		sn->SetInvInertia(temp);
		sn->setInvMass(mass);
		sn->addCV(new CollisionSphere(Vector3(0,0,0),radius));
		sn->dynamic = true;
		sn->sleep = false;
		
		//FOR CONTAINER EFFECT 
		//if(i == 0 || i == nrt-1 || i == n -1 || i == n - nrt) sn->fixed = true;
		if(i == 0 || i == nrt-1 ) sn->fixed = true;

		GameEntity*g = new GameEntity(rn, sn);
		g->ConnectToSystems();
		gv.push_back(g);
		cloth->nodes.push_back(sn);
		
		//allEntities.push_back(g);
	}
	int c = 0;
	/*
	vector<GameEntity*>::iterator i2 = gv.begin();
	i2++;
	for(vector<GameEntity*>::iterator i = gv.begin(); i2!= gv.end(); i++, i2++) {
		c++;
		
		Spring* s = new Spring(
			(SpringNode*)&(*i)->GetPhysicsNode(),(*i)->GetPhysicsNode().GetPosition(),
			(SpringNode*)&(*i2)->GetPhysicsNode(),(*i)->GetPhysicsNode().GetPosition()
			);
		 //0.6f
		//s->m_length = 50.0f;

		//if(i==gv.begin()) ((SpringNode*)&(*i)->GetPhysicsNode())->fixed = true;
		//if(i==gv.end()-1) ((SpringNode*)&(*i)->GetPhysicsNode())->fixed = true;
		((SpringNode*)&(*i)->GetPhysicsNode())->AddSpring(s);
		if(i2!=gv.end())
		((SpringNode*)&(*i2)->GetPhysicsNode())->AddSpring(s);
	}
	*/
	for(int x = 0; x < nrt; x++) {
		for(int y = 0; y< nrt; y++) {
			Spring* s;
			
			if(y!=nrt-1){
				s = new Spring(
					springmesh[x][y],
					springmesh[x][y]->GetPosition(),
					springmesh[x][y+1],
					springmesh[x][y+1]->GetPosition());

					s->m_ks = ks;
					s->m_kd = kd;

					springmesh[x][y]->AddSpring(s);
					springmesh[x][y+1]->AddSpring(s);
					springs.push_back(s);
					PhysicsSystem::GetPhysicsSystem().AddSpring(s);
			}
			if(x!=nrt-1) {
				s = new Spring(
					springmesh[x][y],
					springmesh[x][y]->GetPosition(),
					springmesh[x+1][y],
					springmesh[x+1][y]->GetPosition());

				s->m_ks = ks;
				s->m_kd = kd;

				springmesh[x][y]->AddSpring(s);
				springmesh[x+1][y]->AddSpring(s);
				springs.push_back(s);
				PhysicsSystem::GetPhysicsSystem().AddSpring(s);
			}
			if(x!=nrt-1 && y!=nrt-1) {
				s = new Spring(
					springmesh[x][y],
					springmesh[x][y]->GetPosition(),
					springmesh[x+1][y+1],
					springmesh[x+1][y+1]->GetPosition());

				s->m_ks = ks;
				s->m_kd = kd;

				springmesh[x][y]->AddSpring(s);
				springmesh[x+1][y+1]->AddSpring(s);
				springs.push_back(s);
				PhysicsSystem::GetPhysicsSystem().AddSpring(s);
			}
		}
	}
	clothEntities = gv;
	
}