From c53a5f84d9d7a0124dc38c853e1aae2fe09b6935 Mon Sep 17 00:00:00 2001 From: BennyQBD Date: Fri, 22 Aug 2014 17:45:09 -0400 Subject: [PATCH] Created Frustum Culling Example Scene --- src/main.cpp | 141 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 48 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2710c6a..fe04169 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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