Skip to content

Commit

Permalink
Created Frustum Culling Example Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyQBD committed Aug 22, 2014
1 parent 7e0022e commit c53a5f8
Showing 1 changed file with 93 additions and 48 deletions.
141 changes: 93 additions & 48 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,63 +52,108 @@ void TestGame::Init(const Window& window)
}
Mesh customMesh("square", square.Finalize());

// AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f))
// ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks"))));

// AddToScene((new Entity(Vector3f(7,0,7)))
// ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1))));
//// AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f))
//// ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks"))));
//
//// AddToScene((new Entity(Vector3f(7,0,7)))
//// ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1))));
////
//// AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f))))
//// ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f)));
//
// AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f))))
// ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f)));

AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45))))
->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f)));

AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f))
->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
->AddChild((new Entity(Vector3f(0, 0, 25)))
->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
->AddChild((new Entity())
->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f)))
->AddComponent(new FreeLook(window.GetCenter()))
->AddComponent(new FreeMove(10.0f)))));

// AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f))))
// ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))));

// AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f))
// ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2"))));

// AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45))))
// ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f)));
//
// AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f))
// ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
// ->AddChild((new Entity(Vector3f(0, 0, 25)))
// ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
// ->AddChild((new Entity())
// ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f)))
// ->AddComponent(new FreeLook(window.GetCenter()))
// ->AddComponent(new FreeMove(10.0f)))));
//
//// AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f))))
//// ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))));
//
//// AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f))
//// ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2"))));
//
//
// //TODO: Temporary Physics Engine Code!
// PhysicsEngine physicsEngine;
//
// physicsEngine.AddObject(PhysicsObject(
// new BoundingSphere(Vector3f(0.0f, 0.0f, 0.0f), 1.0f),
// Vector3f(0.0f, 0.0f, 1.141f/2.0f)));
//
// physicsEngine.AddObject(PhysicsObject(
// new BoundingSphere(Vector3f(1.414f/2.0f * 7.0f, 0.0f, 1.414f/2.0f * 7.0f), 1.0f),
// Vector3f(-1.414f/2.0f, 0.0f, -1.414f/2.0f)));
//
//
// PhysicsEngineComponent* physicsEngineComponent
// = new PhysicsEngineComponent(physicsEngine);
//
// for(unsigned int i = 0;
// i < physicsEngineComponent->GetPhysicsEngine().GetNumObjects();
// i++)
// {
//
// AddToScene((new Entity(Vector3f(0,0,0), Quaternion(),
// 1.0f))
// ->AddComponent(new PhysicsObjectComponent(
// &physicsEngineComponent->GetPhysicsEngine().GetObject(i)))
// ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))));
// }
//
// AddToScene((new Entity())
// ->AddComponent(physicsEngineComponent));

//TODO: Temporary Physics Engine Code!
PhysicsEngine physicsEngine;

physicsEngine.AddObject(PhysicsObject(
new BoundingSphere(Vector3f(0.0f, 0.0f, 0.0f), 1.0f),
Vector3f(0.0f, 0.0f, 1.141f/2.0f)));
// AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45))))
// ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f)));

physicsEngine.AddObject(PhysicsObject(
new BoundingSphere(Vector3f(1.414f/2.0f * 7.0f, 0.0f, 1.414f/2.0f * 7.0f), 1.0f),
Vector3f(-1.414f/2.0f, 0.0f, -1.414f/2.0f)));
AddToScene((new Entity())
->AddComponent(new CameraComponent(Matrix4f().InitPerspective(
ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f)))
->AddComponent(new FreeLook(window.GetCenter()))
->AddComponent(new FreeMove(10.0f)));

static const int CUBE_SIZE = 3;

PhysicsEngineComponent* physicsEngineComponent
= new PhysicsEngineComponent(physicsEngine);
AddToScene((new Entity())
->AddComponent(new PointLight(Vector3f(1,1,1),
(CUBE_SIZE * CUBE_SIZE) * 2, Attenuation(0,0,1))));

for(unsigned int i = 0;
i < physicsEngineComponent->GetPhysicsEngine().GetNumObjects();
i++)
for(int i = -CUBE_SIZE; i <= CUBE_SIZE; i++)
{

AddToScene((new Entity(Vector3f(0,0,0), Quaternion(),
1.0f))
->AddComponent(new PhysicsObjectComponent(
&physicsEngineComponent->GetPhysicsEngine().GetObject(i)))
->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))));
for(int j = -CUBE_SIZE; j <= CUBE_SIZE; j++)
{
for(int k = -CUBE_SIZE; k <= CUBE_SIZE; k++)
{
if(i == -CUBE_SIZE || i == CUBE_SIZE ||
j == -CUBE_SIZE || j == CUBE_SIZE ||
k == -CUBE_SIZE || k == CUBE_SIZE)
{
if(i == 0 || j == 0 || k == 0)
{
AddToScene((new Entity(Vector3f(i * 2, j * 2, k * 2)))
->AddComponent(new MeshRenderer(Mesh("sphere.obj"),
Material("bricks"))));
}
else
{
AddToScene((new Entity(Vector3f(i * 2, j * 2, k * 2)))
->AddComponent(new MeshRenderer(Mesh("cube.obj"),
Material("bricks2"))));
}

}
}
}
}

AddToScene((new Entity())
->AddComponent(physicsEngineComponent));

}

#include <iostream>
Expand Down

0 comments on commit c53a5f8

Please sign in to comment.