Пример #1
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;
}
Пример #2
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);
			}
		}
	}
}
Пример #3
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;
}
Пример #4
0
void TerrainClass::BuildFloorEntity() {
	for (int i = 0; i < ChunckManager::NUM_VOXEL_CHUNCKS; i++) {
		SceneNode* sNode = new SceneNode();
		sNode->SetMesh(terrain->getMeshAt(i));
		sNode->SetModelScale(Vector3(SCALE_TERRAIN, SCALE_TERRAIN, SCALE_TERRAIN));

		PhysicsNode* pNode = new PhysicsNode();
		pNode->SetPosition(START_TERRAIN_POSITION);
		pNode->SetLinearVelocity(Vector3(0, 0, linearVelocityZ));
		pNode->setLD(false);
		pNode->setSkyBox(true);
		terrainPhysicsNodes.push_back(pNode);
		countTerrainEntities++;

		GameEntity* geFirst = new GameEntity(sNode, pNode);
		geFirst->ConnectToSystems();
		terrainEntities.push_back(geFirst);

		//add the id of the chunck just created
		//terrainChuncksId.push_back(geFirst->getId());
		//reset the chunck id to be the same as the entity added; for consistency purposes
		//terrain->getChunckAt(i)->setId(i);
	}
}