Skip to content

Commit

Permalink
Reorganized the Project
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyQBD committed Aug 7, 2014
1 parent 60a928a commit db01f4b
Show file tree
Hide file tree
Showing 62 changed files with 277 additions and 170 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
20 changes: 10 additions & 10 deletions src/3DEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 0 additions & 44 deletions src/aabb.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/freeLook.cpp → src/components/freeLook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include "freeLook.h"
#include "window.h"
#include "../rendering/window.h"

void FreeLook::ProcessInput(const Input& input, float delta)
{
Expand Down
4 changes: 2 additions & 2 deletions src/freeLook.h → src/components/freeLook.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/freeMove.h → src/components/freeMove.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/meshRenderer.h → src/components/meshRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreEngine.cpp → src/core/coreEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/coreEngine.h → src/core/coreEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef COREENGINE_H
#define COREENGINE_H

#include "renderingEngine.h"
#include "../rendering/renderingEngine.h"
#include <string>
class Game;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/game.cpp → src/core/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

#include "game.h"
#include "renderingEngine.h"

#include "../rendering/renderingEngine.h"

#include <iostream>

void Game::ProcessInput(const Input& input, float delta)
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/input.cpp → src/core/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

#include "input.h"
#include "window.h"

#include "../rendering/window.h"

#include <SDL2/SDL.h>
#include <cstring>

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/mappedValues.h → src/core/mappedValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <map>

#include "texture.h"
#include "../rendering/texture.h"
#include "math3d.h"

class MappedValues
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
83 changes: 10 additions & 73 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 <iostream>
#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);

Expand Down
94 changes: 94 additions & 0 deletions src/physics/aabb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* @file
* @author Benny Bobaganoosh <[email protected]>
* @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 <cassert>

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;
}
5 changes: 4 additions & 1 deletion src/aabb.h → src/physics/aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef AABB_INCLUDED_H
#define AABB_INCLUDED_H

#include "math3d.h"
#include "../core/math3d.h"
#include "intersectData.h"

/**
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit db01f4b

Please sign in to comment.