コード例 #1
0
ファイル: Stem.cpp プロジェクト: JohnEz/Dissertation
void Stem::Update(float msec)
{

	mesh->Update(msec);

	SceneNode::Update(msec);

	if (mesh->GetDrawIndices() > branchAdd && numBranches < maxBranches)
	{
		int tempsize = (((rand() % (stemSize/2)) + stemSize/4));
		SceneNode* branch = new Branch(tempsize);

		float branchpos = (float)((branchAdd / 24) / 5);
		branchpos -= (branchpos / 9);
		
		branch->SetTransform(Matrix4::Translation(Vector3(0, branchpos * maxScale.y, 0)));


		float branchAngle = (float)((rand() % 180) - 90);
		while (branchAngle < 20 && branchAngle > -20)
		{
			branchAngle = (float)((rand() % 180) - 90);
		}
		branch->SetTransform(branch->GetTransform() * Matrix4::Rotation(branchAngle, Vector3(0, 0, 1)));
		branchAngle = (float)((rand() % 180) - 90);
		while (branchAngle < 20 && branchAngle > -20)
		{
			branchAngle = (float)((rand() % 180) - 90);
		}
		branch->SetTransform(branch->GetTransform() * Matrix4::Rotation(branchAngle, Vector3(1, 0, 0)));

		AddChild(branch);

		numBranches++;
		branchAdd += (((stemSize - stemSize / maxBranches) * 24) / maxBranches);

	}

	Vector3 endPos = myNode->GetPosition();
	float v = mesh->GetDrawIndices();
	float z = v / (stemSize * 24);
	endPos.y += 200 * z;

	myNode->SetCollisionVolume(new CollisionCylinder(2, myNode->GetPosition(), endPos));

	if (modelScale.x < maxScale.x)
	{
		modelScale.x += 0.0001;
		modelScale.z += 0.0001;
	}

		

}
コード例 #2
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;
}
コード例 #3
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;
}
コード例 #4
0
ファイル: Renderer.cpp プロジェクト: cxhaizxm/RenderingEngine
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
void Plant::CreateTree(SceneNode* arg, float branchLen) {
	float outBranchLen = branchLen - 1.0f;
	if (outBranchLen >= 1.0f) 
	{
		for (unsigned int a = 0; a < branches; ++a) 
		{
			SceneNode* branch = new SceneNode();
			branch->SetMesh(cylinder);
			branch->SetModelScale(Vector3(0,0,0));
			arg->AddChild(branch);
			arg->GetChildAt(a)->SetTransform(Matrix4::Translation(Vector3(0, GetHeight(branchLen, 14.0f), 0)) *
											(Matrix4::Rotation(((a * (360/branches)) + (rand() % (360/branches))), Vector3(0,1,0)) *
											 Matrix4::Rotation(40, Vector3(0,0,1))));
			memUsage += sizeof(*branch);
			CreateTree(arg->GetChildAt(a), outBranchLen);
		}
	}
	else
	{
		for (int i = 0; i < ((rand() % 5 + 1) * 2); ++i) {
			if (rand() % 30 == 0) {
				SceneNode* fruit = new SceneNode();
				fruit->SetMesh(sphere);
				fruit->SetModelScale(Vector3(0,0,0));
				fruit->SetTransform(Matrix4::Translation(Vector3(0, (GetHeight(branchLen, 14.0f) / (rand() % 4 + 1)), 0)));
				memUsage += sizeof(*fruit);
				arg->AddChild(fruit);
			} 
			else {
				SceneNode* leafNode = new SceneNode();
				leafNode->SetMesh(leaf);
				leafNode->SetModelScale(Vector3(0,0,0));
				leafNode->SetTransform(Matrix4::Translation(Vector3(0, (GetHeight(branchLen, 14.0f)/i + 1), 0)) *
								   Matrix4::Rotation(90, Vector3(1,1,0)) *
								   Matrix4::Rotation(rand() % 360, Vector3(1,0,0)) *
								   Matrix4::Translation(Vector3(0, 5, 0)) );
				memUsage += sizeof(*leafNode);
				arg->AddChild(leafNode);
			}
		}
	}
}
コード例 #6
0
CubeRobot::CubeRobot(void) {
	//optional -- create a local origin marker
	//SetMesh(cube);

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

	head = new SceneNode(cube, Vector4(0, 1, 0, 1));
	head->SetModelScale(Vector3(5, 5, 5));
	head->SetTransform(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->SetTransform(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->SetTransform(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->SetTransform(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->SetTransform(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);
}
コード例 #7
0
ファイル: Renderer.cpp プロジェクト: GSDan/CSCGAMES2013
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;
}
コード例 #8
0
ファイル: Branch.cpp プロジェクト: JohnEz/Dissertation
void Branch::Update(float msec)
{
	mesh->Update(msec);

	SceneNode::Update(msec);

	if (mesh->GetDrawIndices() == (branchSize * 24) && numLeafs < maxLeafs)
	{

		SceneNode* leaf = new SceneNode(sphere);

		float leafpos = (float)((mesh->GetDrawIndices() / 24) / 5);
		leaf->SetTransform(Matrix4::Translation(Vector3(0, leafpos * maxScale.y, 0)));
		leaf->SetModelScale(Vector3(20,20,20));

		AddChild(leaf);

		leaf->Update(msec);

		///////
		PhysicsNode*p = new PhysicsNode();

		float elements[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
		Matrix4 mat = Matrix4(elements);
		p->SetInverseInertia(mat);
		p->SetUseGravity(false);
		p->SetInverseMass(0.0f);

		p->SetPosition(leaf->GetWorldTransform().GetPositionVector());

		p->SetCollisionVolume(new CollisionLeaf(20));

		Vector3 startPos = GetWorldTransform().GetPositionVector();
		Vector3 endPos = leaf->GetWorldTransform().GetPositionVector();

		PhysicsSystem::GetPhysicsSystem().AddNode(p);

		/////////

		Light l = Light();

		l.SetPosition(leaf->GetWorldTransform().GetPositionVector());

		l.SetColour(Vector4 (0, 1, 0, 1.0f));

		l.SetRadius(150);

		LightStorage::GetInstance()->addLight(l);

		numLeafs++;

	}

	if (modelScale.x < maxScale.x)
	{
		modelScale.x += 0.000001;
		modelScale.z += 0.000001;
	}

	if (!hasPhysics && GetWorldTransform().GetPositionVector().Length() != 0)
	{

		SceneNode* leaf = new SceneNode(sphere);

		float leafpos = (float)((mesh->getNumInd() / 24) / 5);
		leaf->SetTransform(Matrix4::Translation(Vector3(0, leafpos * maxScale.y, 0)));

		AddChild(leaf);

		leaf->Update(msec);

		///////
		PhysicsNode*p = new PhysicsNode();

		float elements[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
		Matrix4 mat = Matrix4(elements);
		p->SetInverseInertia(mat);
		p->SetUseGravity(false);
		p->SetInverseMass(0.0f);

		p->SetPosition(leaf->GetWorldTransform().GetPositionVector());

		Vector3 startPos = GetWorldTransform().GetPositionVector();
		Vector3 endPos = leaf->GetWorldTransform().GetPositionVector();

		endBranch = endPos;

		p->SetCollisionVolume(new CollisionCylinder(1, startPos, endPos));

		myNode = p;

		PhysicsSystem::GetPhysicsSystem().AddNode(p);

		/////////

		hasPhysics = true;
		RemoveChild(leaf);
	}

	if (myNode)
	{
		float v = mesh->GetDrawIndices();
		float z = v / (branchSize * 24);
		Vector3 posDif = endBranch - GetWorldTransform().GetPositionVector();
		Vector3 endPos = GetWorldTransform().GetPositionVector() + (posDif * z);

		myNode->SetCollisionVolume(new CollisionCylinder(2, GetWorldTransform().GetPositionVector(), endPos));
	}

}