From db01f4b2b757ab185a5c5af29014ffbe0f180bba Mon Sep 17 00:00:00 2001 From: BennyQBD Date: Thu, 7 Aug 2014 06:22:07 -0400 Subject: [PATCH] Reorganized the Project --- CMakeLists.txt | 4 +- src/3DEngine.h | 20 +++--- src/aabb.cpp | 44 ------------ src/{ => components}/freeLook.cpp | 2 +- src/{ => components}/freeLook.h | 4 +- src/{ => components}/freeMove.cpp | 0 src/{ => components}/freeMove.h | 4 +- src/{ => components}/meshRenderer.h | 4 +- src/{ => core}/coreEngine.cpp | 2 +- src/{ => core}/coreEngine.h | 2 +- src/{ => core}/entity.cpp | 0 src/{ => core}/entity.h | 0 src/{ => core}/entityComponent.h | 0 src/{ => core}/game.cpp | 4 +- src/{ => core}/game.h | 0 src/{ => core}/input.cpp | 4 +- src/{ => core}/input.h | 0 src/{ => core}/mappedValues.cpp | 0 src/{ => core}/mappedValues.h | 2 +- src/{ => core}/math3d.cpp | 0 src/{ => core}/math3d.h | 0 src/{ => core}/profiling.cpp | 0 src/{ => core}/profiling.h | 0 src/{ => core}/referenceCounter.h | 0 src/{ => core}/timing.cpp | 0 src/{ => core}/timing.h | 0 src/{ => core}/transform.cpp | 0 src/{ => core}/transform.h | 0 src/{ => core}/util.cpp | 0 src/{ => core}/util.h | 0 src/main.cpp | 83 +++------------------- src/physics/aabb.cpp | 94 +++++++++++++++++++++++++ src/{ => physics}/aabb.h | 5 +- src/{ => physics}/boundingSphere.cpp | 29 ++++++++ src/{ => physics}/boundingSphere.h | 5 +- src/{ => physics}/intersectData.h | 0 src/{ => physics}/plane.cpp | 40 +++++++++++ src/{ => physics}/plane.h | 5 +- src/{ => rendering}/camera.cpp | 3 +- src/{ => rendering}/camera.h | 4 +- src/{ => rendering}/lighting.cpp | 2 +- src/{ => rendering}/lighting.h | 5 +- src/{ => rendering}/material.cpp | 0 src/{ => rendering}/material.h | 4 +- src/{ => rendering}/mesh.cpp | 4 +- src/{ => rendering}/mesh.h | 5 +- src/{ => rendering}/renderingEngine.cpp | 6 +- src/{ => rendering}/renderingEngine.h | 6 +- src/{ => rendering}/shader.cpp | 5 +- src/{ => rendering}/shader.h | 6 +- src/{ => rendering}/texture.cpp | 8 ++- src/{ => rendering}/texture.h | 2 +- src/{ => rendering}/window.cpp | 2 +- src/{ => rendering}/window.h | 2 +- src/{ => staticLibs}/simdaccel.h | 0 src/{ => staticLibs}/simddefines.h | 0 src/{ => staticLibs}/simdemulator.h | 0 src/{ => staticLibs}/stb_image.c | 0 src/{ => staticLibs}/stb_image.h | 0 src/{ => staticLibs}/x86simdaccel.h | 0 src/testing.cpp | 17 +++++ src/testing.h | 9 +++ 62 files changed, 277 insertions(+), 170 deletions(-) delete mode 100644 src/aabb.cpp rename src/{ => components}/freeLook.cpp (97%) rename src/{ => components}/freeLook.h (94%) rename src/{ => components}/freeMove.cpp (100%) rename src/{ => components}/freeMove.h (94%) rename src/{ => components}/meshRenderer.h (94%) rename src/{ => core}/coreEngine.cpp (99%) rename src/{ => core}/coreEngine.h (97%) rename src/{ => core}/entity.cpp (100%) rename src/{ => core}/entity.h (100%) rename src/{ => core}/entityComponent.h (100%) rename src/{ => core}/game.cpp (95%) rename src/{ => core}/game.h (100%) rename src/{ => core}/input.cpp (97%) rename src/{ => core}/input.h (100%) rename src/{ => core}/mappedValues.cpp (100%) rename src/{ => core}/mappedValues.h (97%) rename src/{ => core}/math3d.cpp (100%) rename src/{ => core}/math3d.h (100%) rename src/{ => core}/profiling.cpp (100%) rename src/{ => core}/profiling.h (100%) rename src/{ => core}/referenceCounter.h (100%) rename src/{ => core}/timing.cpp (100%) rename src/{ => core}/timing.h (100%) rename src/{ => core}/transform.cpp (100%) rename src/{ => core}/transform.h (100%) rename src/{ => core}/util.cpp (100%) rename src/{ => core}/util.h (100%) create mode 100644 src/physics/aabb.cpp rename src/{ => physics}/aabb.h (95%) rename src/{ => physics}/boundingSphere.cpp (51%) rename src/{ => physics}/boundingSphere.h (95%) rename src/{ => physics}/intersectData.h (100%) rename src/{ => physics}/plane.cpp (53%) rename src/{ => physics}/plane.h (95%) rename src/{ => rendering}/camera.cpp (98%) rename src/{ => rendering}/camera.h (97%) rename src/{ => rendering}/lighting.cpp (99%) rename src/{ => rendering}/lighting.h (98%) rename src/{ => rendering}/material.cpp (100%) rename src/{ => rendering}/material.h (97%) rename src/{ => rendering}/mesh.cpp (99%) rename src/{ => rendering}/mesh.h (98%) rename src/{ => rendering}/renderingEngine.cpp (99%) rename src/{ => rendering}/renderingEngine.h (98%) rename src/{ => rendering}/shader.cpp (99%) rename src/{ => rendering}/shader.h (97%) rename src/{ => rendering}/texture.cpp (98%) rename src/{ => rendering}/texture.h (98%) rename src/{ => rendering}/window.cpp (99%) rename src/{ => rendering}/window.h (98%) rename src/{ => staticLibs}/simdaccel.h (100%) rename src/{ => staticLibs}/simddefines.h (100%) rename src/{ => staticLibs}/simdemulator.h (100%) rename src/{ => staticLibs}/stb_image.c (100%) rename src/{ => staticLibs}/stb_image.h (100%) rename src/{ => staticLibs}/x86simdaccel.h (100%) create mode 100644 src/testing.cpp create mode 100644 src/testing.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ecea0d0..2149312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,10 +47,10 @@ add_definitions( -O2 ) endif ( CMAKE_BUILD_TYPE STREQUAL "Release" ) # Lets LOAD app our headers! -file(GLOB HDRS ${3DEngineCpp_SOURCE_DIR}/src/*.h) +file(GLOB_RECURSE HDRS ${3DEngineCpp_SOURCE_DIR}/src/*.h) # Lets LOAD app our sources! -file(GLOB SRCS +file(GLOB_RECURSE SRCS ${3DEngineCpp_SOURCE_DIR}/src/*.cpp ${3DEngineCpp_SOURCE_DIR}/src/*.c ) diff --git a/src/3DEngine.h b/src/3DEngine.h index a29f652..2a16a90 100644 --- a/src/3DEngine.h +++ b/src/3DEngine.h @@ -19,16 +19,16 @@ //This header is just a convinient way to include all necessary files to use the engine. -#include "mesh.h" -#include "shader.h" -#include "transform.h" -#include "camera.h" -#include "lighting.h" -#include "entity.h" -#include "meshRenderer.h" -#include "window.h" -#include "coreEngine.h" -#include "game.h" +#include "rendering/mesh.h" +#include "rendering/shader.h" +#include "core/transform.h" +#include "rendering/camera.h" +#include "rendering/lighting.h" +#include "core/entity.h" +#include "components/meshRenderer.h" +#include "rendering/window.h" +#include "core/coreEngine.h" +#include "core/game.h" //SDL2 defines a main macro, which can prevent certain compilers from finding the main function. #undef main diff --git a/src/aabb.cpp b/src/aabb.cpp deleted file mode 100644 index d50ee56..0000000 --- a/src/aabb.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * @file - * @author Benny Bobaganoosh - * @section LICENSE - * - * Copyright (C) 2014 Benny Bobaganoosh - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "aabb.h" - -IntersectData AABB::IntersectAABB(const AABB& other) const -{ - //The distance between the AABB's on the X, Y, and Z axis. - //Computed twice because there are two possible valid distances, depending - //on the location of the AABB's. - Vector3f distances1 = other.GetMinExtents() - m_maxExtents; - Vector3f distances2 = m_minExtents - other.GetMaxExtents(); - - //The correct distances will be whichever distance is larger for that - //particular axis. - Vector3f distances = Vector3f(distances1.Max(distances2)); - - float maxDistance = distances.Max(); - - //If there is any distance between the two AABB's, then max distance will - //be greather than or equal to 0. If there is distance between the two - //AABBs, then they aren't intersecting. - // - //Therefore, if the AABBs are intersecting, then the distance between them - //must be less than zero. - return IntersectData(maxDistance < 0, maxDistance); -} diff --git a/src/freeLook.cpp b/src/components/freeLook.cpp similarity index 97% rename from src/freeLook.cpp rename to src/components/freeLook.cpp index a926d92..bb05cd6 100644 --- a/src/freeLook.cpp +++ b/src/components/freeLook.cpp @@ -15,7 +15,7 @@ */ #include "freeLook.h" -#include "window.h" +#include "../rendering/window.h" void FreeLook::ProcessInput(const Input& input, float delta) { diff --git a/src/freeLook.h b/src/components/freeLook.h similarity index 94% rename from src/freeLook.h rename to src/components/freeLook.h index 8e674a2..d7745f5 100644 --- a/src/freeLook.h +++ b/src/components/freeLook.h @@ -17,8 +17,8 @@ #ifndef FREELOOK_H #define FREELOOK_H -#include "math3d.h" -#include "entityComponent.h" +#include "../core/math3d.h" +#include "../core/entityComponent.h" class FreeLook : public EntityComponent { diff --git a/src/freeMove.cpp b/src/components/freeMove.cpp similarity index 100% rename from src/freeMove.cpp rename to src/components/freeMove.cpp diff --git a/src/freeMove.h b/src/components/freeMove.h similarity index 94% rename from src/freeMove.h rename to src/components/freeMove.h index b6e022c..0f11b0e 100644 --- a/src/freeMove.h +++ b/src/components/freeMove.h @@ -17,8 +17,8 @@ #ifndef FREEMOVE_H #define FREEMOVE_H -#include "math3d.h" -#include "entityComponent.h" +#include "../core/math3d.h" +#include "../core/entityComponent.h" class FreeMove : public EntityComponent { diff --git a/src/meshRenderer.h b/src/components/meshRenderer.h similarity index 94% rename from src/meshRenderer.h rename to src/components/meshRenderer.h index 9931561..f56b5fc 100644 --- a/src/meshRenderer.h +++ b/src/components/meshRenderer.h @@ -17,8 +17,8 @@ #ifndef MESHRENDERER_H_INCLUDED #define MESHRENDERER_H_INCLUDED -#include "entityComponent.h" -#include "mesh.h" +#include "../core/entityComponent.h" +#include "../rendering/mesh.h" class MeshRenderer : public EntityComponent { diff --git a/src/coreEngine.cpp b/src/core/coreEngine.cpp similarity index 99% rename from src/coreEngine.cpp rename to src/core/coreEngine.cpp index 5c2a861..ee860b0 100644 --- a/src/coreEngine.cpp +++ b/src/core/coreEngine.cpp @@ -16,7 +16,7 @@ #include "coreEngine.h" #include "timing.h" -#include "window.h" +#include "../rendering/window.h" #include "input.h" #include "util.h" #include "game.h" diff --git a/src/coreEngine.h b/src/core/coreEngine.h similarity index 97% rename from src/coreEngine.h rename to src/core/coreEngine.h index cf22361..32daec4 100644 --- a/src/coreEngine.h +++ b/src/core/coreEngine.h @@ -17,7 +17,7 @@ #ifndef COREENGINE_H #define COREENGINE_H -#include "renderingEngine.h" +#include "../rendering/renderingEngine.h" #include class Game; diff --git a/src/entity.cpp b/src/core/entity.cpp similarity index 100% rename from src/entity.cpp rename to src/core/entity.cpp diff --git a/src/entity.h b/src/core/entity.h similarity index 100% rename from src/entity.h rename to src/core/entity.h diff --git a/src/entityComponent.h b/src/core/entityComponent.h similarity index 100% rename from src/entityComponent.h rename to src/core/entityComponent.h diff --git a/src/game.cpp b/src/core/game.cpp similarity index 95% rename from src/game.cpp rename to src/core/game.cpp index 2439b6d..6cdba5d 100644 --- a/src/game.cpp +++ b/src/core/game.cpp @@ -15,7 +15,9 @@ */ #include "game.h" -#include "renderingEngine.h" + +#include "../rendering/renderingEngine.h" + #include void Game::ProcessInput(const Input& input, float delta) diff --git a/src/game.h b/src/core/game.h similarity index 100% rename from src/game.h rename to src/core/game.h diff --git a/src/input.cpp b/src/core/input.cpp similarity index 97% rename from src/input.cpp rename to src/core/input.cpp index 37a6a5c..8b90a51 100644 --- a/src/input.cpp +++ b/src/core/input.cpp @@ -15,7 +15,9 @@ */ #include "input.h" -#include "window.h" + +#include "../rendering/window.h" + #include #include diff --git a/src/input.h b/src/core/input.h similarity index 100% rename from src/input.h rename to src/core/input.h diff --git a/src/mappedValues.cpp b/src/core/mappedValues.cpp similarity index 100% rename from src/mappedValues.cpp rename to src/core/mappedValues.cpp diff --git a/src/mappedValues.h b/src/core/mappedValues.h similarity index 97% rename from src/mappedValues.h rename to src/core/mappedValues.h index 0ccdf2a..39fa85d 100644 --- a/src/mappedValues.h +++ b/src/core/mappedValues.h @@ -19,7 +19,7 @@ #include -#include "texture.h" +#include "../rendering/texture.h" #include "math3d.h" class MappedValues diff --git a/src/math3d.cpp b/src/core/math3d.cpp similarity index 100% rename from src/math3d.cpp rename to src/core/math3d.cpp diff --git a/src/math3d.h b/src/core/math3d.h similarity index 100% rename from src/math3d.h rename to src/core/math3d.h diff --git a/src/profiling.cpp b/src/core/profiling.cpp similarity index 100% rename from src/profiling.cpp rename to src/core/profiling.cpp diff --git a/src/profiling.h b/src/core/profiling.h similarity index 100% rename from src/profiling.h rename to src/core/profiling.h diff --git a/src/referenceCounter.h b/src/core/referenceCounter.h similarity index 100% rename from src/referenceCounter.h rename to src/core/referenceCounter.h diff --git a/src/timing.cpp b/src/core/timing.cpp similarity index 100% rename from src/timing.cpp rename to src/core/timing.cpp diff --git a/src/timing.h b/src/core/timing.h similarity index 100% rename from src/timing.h rename to src/core/timing.h diff --git a/src/transform.cpp b/src/core/transform.cpp similarity index 100% rename from src/transform.cpp rename to src/core/transform.cpp diff --git a/src/transform.h b/src/core/transform.h similarity index 100% rename from src/transform.h rename to src/core/transform.h diff --git a/src/util.cpp b/src/core/util.cpp similarity index 100% rename from src/util.cpp rename to src/core/util.cpp diff --git a/src/util.h b/src/core/util.h similarity index 100% rename from src/util.h rename to src/core/util.h diff --git a/src/main.cpp b/src/main.cpp index 0687c27..8064e6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,8 +15,8 @@ */ #include "3DEngine.h" -#include "freeLook.h" -#include "freeMove.h" +#include "components/freeLook.h" +#include "components/freeMove.h" class TestGame : public Game { @@ -76,84 +76,21 @@ void TestGame::Init(const Window& window) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); } -#include "boundingSphere.h" -#include "aabb.h" -#include "plane.h" #include +#include "testing.h" int main() { - BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f); - BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f); - BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f); - BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f); + Testing::RunAllTests(); - IntersectData sphere1IntersectSphere2 = sphere1.IntersectBoundingSphere(sphere2); - IntersectData sphere1IntersectSphere3 = sphere1.IntersectBoundingSphere(sphere3); - IntersectData sphere1IntersectSphere4 = sphere1.IntersectBoundingSphere(sphere4); + TestGame game; + Window window(800, 600, "3D Game Engine"); + RenderingEngine renderer(window); - std::cout << "Sphere1 intersect Sphere2: " << sphere1IntersectSphere2.GetDoesIntersect() - << ", Distance: " << sphere1IntersectSphere2.GetDistance() << std::endl; - std::cout << "Sphere1 intersect Sphere3: " << sphere1IntersectSphere3.GetDoesIntersect() - << ", Distance: " << sphere1IntersectSphere3.GetDistance() << std::endl; - std::cout << "Sphere1 intersect Sphere4: " << sphere1IntersectSphere4.GetDoesIntersect() - << ", Distance: " << sphere1IntersectSphere4.GetDistance() << std::endl; - - std::cout << std::endl; - - AABB aabb1(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(1.0f, 1.0f, 1.0f)); - AABB aabb2(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(2.0f, 2.0f, 2.0f)); - AABB aabb3(Vector3f(1.0f, 0.0f, 0.0f), Vector3f(2.0f, 1.0f, 1.0f)); - AABB aabb4(Vector3f(0.0f, 0.0f, -2.0f), Vector3f(1.0f, 1.0f, -1.0f)); - AABB aabb5(Vector3f(0.0f, 0.5f, 0.0f), Vector3f(1.0f, 1.5f, 1.0f)); - - IntersectData aabb1Intersectaabb2 = aabb1.IntersectAABB(aabb2); - IntersectData aabb1Intersectaabb3 = aabb1.IntersectAABB(aabb3); - IntersectData aabb1Intersectaabb4 = aabb1.IntersectAABB(aabb4); - IntersectData aabb1Intersectaabb5 = aabb1.IntersectAABB(aabb5); - - std::cout << "AABB1 intersect AABB2: " << aabb1Intersectaabb2.GetDoesIntersect() - << ", Distance: " << aabb1Intersectaabb2.GetDistance() << std::endl; - - std::cout << "AABB1 intersect AABB3: " << aabb1Intersectaabb3.GetDoesIntersect() - << ", Distance: " << aabb1Intersectaabb3.GetDistance() << std::endl; - - std::cout << "AABB1 intersect AABB4: " << aabb1Intersectaabb4.GetDoesIntersect() - << ", Distance: " << aabb1Intersectaabb4.GetDistance() << std::endl; - - std::cout << "AABB1 intersect AABB5: " << aabb1Intersectaabb5.GetDoesIntersect() - << ", Distance: " << aabb1Intersectaabb5.GetDistance() << std::endl; - - - std::cout << std::endl; - - Plane plane1(Vector3f(0.0f, 1.0f, 0.0f), 0.0f); - - IntersectData plane1IntersectSphere1 = plane1.IntersectSphere(sphere1); - IntersectData plane1IntersectSphere2 = plane1.IntersectSphere(sphere2); - IntersectData plane1IntersectSphere3 = plane1.IntersectSphere(sphere3); - IntersectData plane1IntersectSphere4 = plane1.IntersectSphere(sphere4); - - std::cout << "Plane1 intersect Sphere1: " << plane1IntersectSphere1.GetDoesIntersect() - << ", Distance: " << plane1IntersectSphere1.GetDistance() << std::endl; - - std::cout << "Plane1 intersect Sphere2: " << plane1IntersectSphere2.GetDoesIntersect() - << ", Distance: " << plane1IntersectSphere2.GetDistance() << std::endl; + //window.SetFullScreen(true); - std::cout << "Plane1 intersect Sphere3: " << plane1IntersectSphere3.GetDoesIntersect() - << ", Distance: " << plane1IntersectSphere3.GetDistance() << std::endl; - - std::cout << "Plane1 intersect Sphere4: " << plane1IntersectSphere4.GetDoesIntersect() - << ", Distance: " << plane1IntersectSphere4.GetDistance() << std::endl; - -// TestGame game; -// Window window(800, 600, "3D Game Engine"); -// RenderingEngine renderer(window); -// -// //window.SetFullScreen(true); -// -// CoreEngine engine(60, &window, &renderer, &game); -// engine.Start(); + CoreEngine engine(60, &window, &renderer, &game); + engine.Start(); //window.SetFullScreen(false); diff --git a/src/physics/aabb.cpp b/src/physics/aabb.cpp new file mode 100644 index 0000000..17f7ff2 --- /dev/null +++ b/src/physics/aabb.cpp @@ -0,0 +1,94 @@ +/* + * @file + * @author Benny Bobaganoosh + * @section LICENSE + * + * Copyright (C) 2014 Benny Bobaganoosh + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "aabb.h" +#include + +IntersectData AABB::IntersectAABB(const AABB& other) const +{ + //The distance between the AABB's on the X, Y, and Z axis. + //Computed twice because there are two possible valid distances, depending + //on the location of the AABB's. + Vector3f distances1 = other.GetMinExtents() - m_maxExtents; + Vector3f distances2 = m_minExtents - other.GetMaxExtents(); + + //The correct distances will be whichever distance is larger for that + //particular axis. + Vector3f distances = Vector3f(distances1.Max(distances2)); + + float maxDistance = distances.Max(); + + //If there is any distance between the two AABB's, then max distance will + //be greather than or equal to 0. If there is distance between the two + //AABBs, then they aren't intersecting. + // + //Therefore, if the AABBs are intersecting, then the distance between them + //must be less than zero. + + //TODO: This might actually need to return the minDistance if they are + //intersecting. + return IntersectData(maxDistance < 0, maxDistance); +} + +void AABB::Test() +{ + AABB aabb1(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(1.0f, 1.0f, 1.0f)); + AABB aabb2(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(2.0f, 2.0f, 2.0f)); + AABB aabb3(Vector3f(1.0f, 0.0f, 0.0f), Vector3f(2.0f, 1.0f, 1.0f)); + AABB aabb4(Vector3f(0.0f, 0.0f, -2.0f), Vector3f(1.0f, 1.0f, -1.0f)); + AABB aabb5(Vector3f(0.0f, 0.5f, 0.0f), Vector3f(1.0f, 1.5f, 1.0f)); + AABB aabb6(Vector3f(0.3f, 0.5f, 0.7f), Vector3f(1.3f, 1.5f, 1.7f)); + + IntersectData aabb1Intersectaabb2 = aabb1.IntersectAABB(aabb2); + IntersectData aabb1Intersectaabb3 = aabb1.IntersectAABB(aabb3); + IntersectData aabb1Intersectaabb4 = aabb1.IntersectAABB(aabb4); + IntersectData aabb1Intersectaabb5 = aabb1.IntersectAABB(aabb5); + IntersectData aabb1Intersectaabb6 = aabb1.IntersectAABB(aabb6); + + assert(aabb1Intersectaabb2.GetDoesIntersect() == false); + assert(aabb1Intersectaabb2.GetDistance() == 0.0f); + + assert(aabb1Intersectaabb3.GetDoesIntersect() == false); + assert(aabb1Intersectaabb3.GetDistance() == 0.0f); + + assert(aabb1Intersectaabb4.GetDoesIntersect() == false); + assert(aabb1Intersectaabb4.GetDistance() == 1.0f); + + assert(aabb1Intersectaabb5.GetDoesIntersect() == true); + assert(aabb1Intersectaabb5.GetDistance() == -0.5f); + + assert(aabb1Intersectaabb6.GetDoesIntersect() == true); + assert(aabb1Intersectaabb6.GetDistance() == -0.3f); + +// std::cout << "AABB1 intersect AABB2: " << aabb1Intersectaabb2.GetDoesIntersect() +// << ", Distance: " << aabb1Intersectaabb2.GetDistance() << std::endl; +// +// std::cout << "AABB1 intersect AABB3: " << aabb1Intersectaabb3.GetDoesIntersect() +// << ", Distance: " << aabb1Intersectaabb3.GetDistance() << std::endl; +// +// std::cout << "AABB1 intersect AABB4: " << aabb1Intersectaabb4.GetDoesIntersect() +// << ", Distance: " << aabb1Intersectaabb4.GetDistance() << std::endl; +// +// std::cout << "AABB1 intersect AABB5: " << aabb1Intersectaabb5.GetDoesIntersect() +// << ", Distance: " << aabb1Intersectaabb5.GetDistance() << std::endl; +// +// std::cout << "AABB1 intersect AABB6: " << aabb1Intersectaabb6.GetDoesIntersect() +// << ", Distance: " << aabb1Intersectaabb6.GetDistance() << std::endl; +} diff --git a/src/aabb.h b/src/physics/aabb.h similarity index 95% rename from src/aabb.h rename to src/physics/aabb.h index 9fcea4e..2452563 100644 --- a/src/aabb.h +++ b/src/physics/aabb.h @@ -21,7 +21,7 @@ #ifndef AABB_INCLUDED_H #define AABB_INCLUDED_H -#include "math3d.h" +#include "../core/math3d.h" #include "intersectData.h" /** @@ -53,6 +53,9 @@ class AABB inline const Vector3f& GetMinExtents() const { return m_minExtents; } /** Basic getter for the max extents */ inline const Vector3f& GetMaxExtents() const { return m_maxExtents; } + + /** Performs a Unit test of this class */ + static void Test(); private: /** The corner of the AABB with the smallest coordinates */ const Vector3f m_minExtents; diff --git a/src/boundingSphere.cpp b/src/physics/boundingSphere.cpp similarity index 51% rename from src/boundingSphere.cpp rename to src/physics/boundingSphere.cpp index 872cfe3..011fc8d 100644 --- a/src/boundingSphere.cpp +++ b/src/physics/boundingSphere.cpp @@ -19,6 +19,7 @@ */ #include "boundingSphere.h" +#include IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& other) const { @@ -39,3 +40,31 @@ IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& othe //than 0. return IntersectData(distance < 0, distance); } + +void BoundingSphere::Test() +{ + BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f); + BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f); + BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f); + BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f); + + IntersectData sphere1IntersectSphere2 = sphere1.IntersectBoundingSphere(sphere2); + IntersectData sphere1IntersectSphere3 = sphere1.IntersectBoundingSphere(sphere3); + IntersectData sphere1IntersectSphere4 = sphere1.IntersectBoundingSphere(sphere4); + + assert(sphere1IntersectSphere2.GetDoesIntersect() == false); + assert(sphere1IntersectSphere2.GetDistance() == 1.0f); + + assert(sphere1IntersectSphere3.GetDoesIntersect() == false); + assert(sphere1IntersectSphere3.GetDistance() == 0.0f); + + assert(sphere1IntersectSphere4.GetDoesIntersect() == true); + assert(sphere1IntersectSphere4.GetDistance() == -1.0f); + +// std::cout << "Sphere1 intersect Sphere2: " << sphere1IntersectSphere2.GetDoesIntersect() +// << ", Distance: " << sphere1IntersectSphere2.GetDistance() << std::endl; +// std::cout << "Sphere1 intersect Sphere3: " << sphere1IntersectSphere3.GetDoesIntersect() +// << ", Distance: " << sphere1IntersectSphere3.GetDistance() << std::endl; +// std::cout << "Sphere1 intersect Sphere4: " << sphere1IntersectSphere4.GetDoesIntersect() +// << ", Distance: " << sphere1IntersectSphere4.GetDistance() << std::endl; +} diff --git a/src/boundingSphere.h b/src/physics/boundingSphere.h similarity index 95% rename from src/boundingSphere.h rename to src/physics/boundingSphere.h index 4c934f5..7a59b6b 100644 --- a/src/boundingSphere.h +++ b/src/physics/boundingSphere.h @@ -21,7 +21,7 @@ #ifndef BOUNDING_SPHERE_INCLUDED_H #define BOUNDING_SPHERE_INCLUDED_H -#include "math3d.h" +#include "../core/math3d.h" #include "intersectData.h" /** @@ -53,6 +53,9 @@ class BoundingSphere inline const Vector3f& GetCenter() const { return m_center; } /** Basic getter for the radius */ inline float GetRadius() const { return m_radius; } + + /** Performs a Unit Test of this class */ + static void Test(); private: /** The center point of the sphere */ const Vector3f m_center; diff --git a/src/intersectData.h b/src/physics/intersectData.h similarity index 100% rename from src/intersectData.h rename to src/physics/intersectData.h diff --git a/src/plane.cpp b/src/physics/plane.cpp similarity index 53% rename from src/plane.cpp rename to src/physics/plane.cpp index 197370b..03656f7 100644 --- a/src/plane.cpp +++ b/src/physics/plane.cpp @@ -19,6 +19,7 @@ */ #include "plane.h" +#include Plane Plane::Normalized() const { @@ -54,3 +55,42 @@ IntersectData Plane::IntersectSphere(const BoundingSphere& other) const //plane and sphere, and they cannot be intersecting. return IntersectData(distanceFromSphere < 0, distanceFromSphere); } + +void Plane::Test() +{ + BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f); + BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f); + BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f); + BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f); + + Plane plane1(Vector3f(0.0f, 1.0f, 0.0f), 0.0f); + + IntersectData plane1IntersectSphere1 = plane1.IntersectSphere(sphere1); + IntersectData plane1IntersectSphere2 = plane1.IntersectSphere(sphere2); + IntersectData plane1IntersectSphere3 = plane1.IntersectSphere(sphere3); + IntersectData plane1IntersectSphere4 = plane1.IntersectSphere(sphere4); + + assert(plane1IntersectSphere1.GetDoesIntersect() == true); + assert(plane1IntersectSphere1.GetDistance() == -1.0f); + + assert(plane1IntersectSphere2.GetDoesIntersect() == false); + assert(plane1IntersectSphere2.GetDistance() == 2.0f); + + assert(plane1IntersectSphere3.GetDoesIntersect() == true); + assert(plane1IntersectSphere3.GetDistance() == -1.0f); + + assert(plane1IntersectSphere4.GetDoesIntersect() == true); + assert(plane1IntersectSphere4.GetDistance() == -1.0f); + +// std::cout << "Plane1 intersect Sphere1: " << plane1IntersectSphere1.GetDoesIntersect() +// << ", Distance: " << plane1IntersectSphere1.GetDistance() << std::endl; +// +// std::cout << "Plane1 intersect Sphere2: " << plane1IntersectSphere2.GetDoesIntersect() +// << ", Distance: " << plane1IntersectSphere2.GetDistance() << std::endl; +// +// std::cout << "Plane1 intersect Sphere3: " << plane1IntersectSphere3.GetDoesIntersect() +// << ", Distance: " << plane1IntersectSphere3.GetDistance() << std::endl; +// +// std::cout << "Plane1 intersect Sphere4: " << plane1IntersectSphere4.GetDoesIntersect() +// << ", Distance: " << plane1IntersectSphere4.GetDistance() << std::endl; +} diff --git a/src/plane.h b/src/physics/plane.h similarity index 95% rename from src/plane.h rename to src/physics/plane.h index 9cc7776..0a7be9c 100644 --- a/src/plane.h +++ b/src/physics/plane.h @@ -21,7 +21,7 @@ #ifndef PLANE_INCLUDED_H #define PLANE_INCLUDED_H -#include "math3d.h" +#include "../core/math3d.h" #include "boundingSphere.h" /** @@ -58,6 +58,9 @@ class Plane inline const Vector3f& GetNormal() const { return m_normal; } inline float GetDistance() const { return m_distance; } + + /** Performs a Unit Test of this class */ + static void Test(); private: /** The "up" direction from the plane's surface. */ const Vector3f m_normal; diff --git a/src/camera.cpp b/src/rendering/camera.cpp similarity index 98% rename from src/camera.cpp rename to src/rendering/camera.cpp index d28be30..22cb121 100644 --- a/src/camera.cpp +++ b/src/rendering/camera.cpp @@ -16,7 +16,8 @@ #include "camera.h" #include "renderingEngine.h" -#include "coreEngine.h" + +#include "../core/coreEngine.h" Matrix4f Camera::GetViewProjection() const { diff --git a/src/camera.h b/src/rendering/camera.h similarity index 97% rename from src/camera.h rename to src/rendering/camera.h index 9804a51..12c8f24 100644 --- a/src/camera.h +++ b/src/rendering/camera.h @@ -17,8 +17,8 @@ #ifndef CAMERA_H #define CAMERA_H -#include "math3d.h" -#include "entityComponent.h" +#include "../core/math3d.h" +#include "../core/entityComponent.h" //Cameras represent a location, orientation, and projection from //which the scene can be rendered. diff --git a/src/lighting.cpp b/src/rendering/lighting.cpp similarity index 99% rename from src/lighting.cpp rename to src/rendering/lighting.cpp index cb57d7e..62cdf25 100644 --- a/src/lighting.cpp +++ b/src/rendering/lighting.cpp @@ -16,7 +16,7 @@ #include "lighting.h" #include "renderingEngine.h" -#include "coreEngine.h" +#include "../core/coreEngine.h" #define COLOR_DEPTH 256 diff --git a/src/lighting.h b/src/rendering/lighting.h similarity index 98% rename from src/lighting.h rename to src/rendering/lighting.h index c24ba4d..2f8d4c6 100644 --- a/src/lighting.h +++ b/src/rendering/lighting.h @@ -17,10 +17,11 @@ #ifndef LIGHTING_H #define LIGHTING_H -#include "math3d.h" -#include "entityComponent.h" #include "shader.h" +#include "../core/math3d.h" +#include "../core/entityComponent.h" + class CoreEngine; class ShadowCameraTransform diff --git a/src/material.cpp b/src/rendering/material.cpp similarity index 100% rename from src/material.cpp rename to src/rendering/material.cpp diff --git a/src/material.h b/src/rendering/material.h similarity index 97% rename from src/material.h rename to src/rendering/material.h index 5e2c507..47f8156 100644 --- a/src/material.h +++ b/src/rendering/material.h @@ -18,8 +18,8 @@ #define MATERIAL_H #include "texture.h" -#include "math3d.h" -#include "mappedValues.h" +#include "../core/math3d.h" +#include "../core/mappedValues.h" #include class MaterialData : public ReferenceCounter, public MappedValues diff --git a/src/mesh.cpp b/src/rendering/mesh.cpp similarity index 99% rename from src/mesh.cpp rename to src/rendering/mesh.cpp index fa78712..9a7f406 100644 --- a/src/mesh.cpp +++ b/src/rendering/mesh.cpp @@ -15,7 +15,9 @@ */ #include "mesh.h" -#include "profiling.h" + +#include "../core/profiling.h" + #include #include diff --git a/src/mesh.h b/src/rendering/mesh.h similarity index 98% rename from src/mesh.h rename to src/rendering/mesh.h index 8b80394..3fc3f47 100644 --- a/src/mesh.h +++ b/src/rendering/mesh.h @@ -17,8 +17,9 @@ #ifndef MESH_H #define MESH_H -#include "math3d.h" -#include "referenceCounter.h" +#include "../core/math3d.h" +#include "../core/referenceCounter.h" + #include #include #include diff --git a/src/renderingEngine.cpp b/src/rendering/renderingEngine.cpp similarity index 99% rename from src/renderingEngine.cpp rename to src/rendering/renderingEngine.cpp index 04bf419..b895c70 100644 --- a/src/renderingEngine.cpp +++ b/src/rendering/renderingEngine.cpp @@ -16,10 +16,12 @@ #include "renderingEngine.h" #include "window.h" -#include "entity.h" +#include "mesh.h" #include "shader.h" + +#include "../core/entity.h" + #include -#include "mesh.h" #include const Matrix4f RenderingEngine::BIAS_MATRIX = Matrix4f().InitScale(Vector3f(0.5, 0.5, 0.5)) * Matrix4f().InitTranslation(Vector3f(1.0, 1.0, 1.0)); diff --git a/src/renderingEngine.h b/src/rendering/renderingEngine.h similarity index 98% rename from src/renderingEngine.h rename to src/rendering/renderingEngine.h index 51988ac..3820009 100644 --- a/src/renderingEngine.h +++ b/src/rendering/renderingEngine.h @@ -19,11 +19,13 @@ #include "camera.h" #include "lighting.h" -#include "mappedValues.h" #include "material.h" #include "mesh.h" #include "window.h" -#include "profiling.h" + +#include "../core/mappedValues.h" +#include "../core/profiling.h" + #include #include class Entity; diff --git a/src/shader.cpp b/src/rendering/shader.cpp similarity index 99% rename from src/shader.cpp rename to src/rendering/shader.cpp index 7ab83c8..05f627d 100644 --- a/src/shader.cpp +++ b/src/rendering/shader.cpp @@ -15,11 +15,12 @@ */ #include "shader.h" -#include "profiling.h" #include "lighting.h" -#include "util.h" #include "renderingEngine.h" +#include "../core/profiling.h" +#include "../core/util.h" + #include #include #include diff --git a/src/shader.h b/src/rendering/shader.h similarity index 97% rename from src/shader.h rename to src/rendering/shader.h index 32bf75d..a5e75c4 100644 --- a/src/shader.h +++ b/src/rendering/shader.h @@ -21,10 +21,10 @@ #include #include -#include "referenceCounter.h" -#include "math3d.h" +#include "../core/referenceCounter.h" +#include "../core/math3d.h" +#include "../core/transform.h" #include "material.h" -#include "transform.h" #include "camera.h" class RenderingEngine; diff --git a/src/texture.cpp b/src/rendering/texture.cpp similarity index 98% rename from src/texture.cpp rename to src/rendering/texture.cpp index 5d08652..a6d5ed2 100644 --- a/src/texture.cpp +++ b/src/rendering/texture.cpp @@ -15,9 +15,11 @@ */ #include "texture.h" -#include "stb_image.h" -#include "math3d.h" -#include "profiling.h" + +#include "../core/math3d.h" +#include "../core/profiling.h" + +#include "../staticLibs/stb_image.h" #include #include diff --git a/src/texture.h b/src/rendering/texture.h similarity index 98% rename from src/texture.h rename to src/rendering/texture.h index 9e2fb83..2483a6d 100644 --- a/src/texture.h +++ b/src/rendering/texture.h @@ -17,7 +17,7 @@ #ifndef TEXTURE_H #define TEXTURE_H -#include "referenceCounter.h" +#include "../core/referenceCounter.h" #include #include #include diff --git a/src/window.cpp b/src/rendering/window.cpp similarity index 99% rename from src/window.cpp rename to src/rendering/window.cpp index f7e3877..75b2f37 100644 --- a/src/window.cpp +++ b/src/rendering/window.cpp @@ -15,7 +15,7 @@ */ #include "window.h" -#include "profiling.h" +#include "../core/profiling.h" #include #include diff --git a/src/window.h b/src/rendering/window.h similarity index 98% rename from src/window.h rename to src/rendering/window.h index 1ecbbcb..8432b0a 100644 --- a/src/window.h +++ b/src/rendering/window.h @@ -19,7 +19,7 @@ #include #include -#include "input.h" +#include "../core/input.h" class Window { diff --git a/src/simdaccel.h b/src/staticLibs/simdaccel.h similarity index 100% rename from src/simdaccel.h rename to src/staticLibs/simdaccel.h diff --git a/src/simddefines.h b/src/staticLibs/simddefines.h similarity index 100% rename from src/simddefines.h rename to src/staticLibs/simddefines.h diff --git a/src/simdemulator.h b/src/staticLibs/simdemulator.h similarity index 100% rename from src/simdemulator.h rename to src/staticLibs/simdemulator.h diff --git a/src/stb_image.c b/src/staticLibs/stb_image.c similarity index 100% rename from src/stb_image.c rename to src/staticLibs/stb_image.c diff --git a/src/stb_image.h b/src/staticLibs/stb_image.h similarity index 100% rename from src/stb_image.h rename to src/staticLibs/stb_image.h diff --git a/src/x86simdaccel.h b/src/staticLibs/x86simdaccel.h similarity index 100% rename from src/x86simdaccel.h rename to src/staticLibs/x86simdaccel.h diff --git a/src/testing.cpp b/src/testing.cpp new file mode 100644 index 0000000..0338c3e --- /dev/null +++ b/src/testing.cpp @@ -0,0 +1,17 @@ +#include "testing.h" + +#include "physics/boundingSphere.h" +#include "physics/aabb.h" +#include "physics/plane.h" + +#include +#include + +void Testing::RunAllTests() +{ + BoundingSphere::Test(); + AABB::Test(); + Plane::Test(); +} + + diff --git a/src/testing.h b/src/testing.h new file mode 100644 index 0000000..bfed892 --- /dev/null +++ b/src/testing.h @@ -0,0 +1,9 @@ +#ifndef TESTING_INCLUDED_H +#define TESTING_INCLUDED_H + +namespace Testing +{ + void RunAllTests(); +}; + +#endif