diff options
-rw-r--r-- | CMakeLists.txt | 41 | ||||
-rw-r--r-- | CTestTestfile.cmake | 7 | ||||
-rw-r--r-- | Testing/Temporary/CTestCostData.txt | 3 | ||||
-rw-r--r-- | Testing/Temporary/LastTest.log | 18 | ||||
-rw-r--r-- | Testing/Temporary/LastTestsFailed.log | 1 | ||||
-rw-r--r-- | include/YAGE/Physics/body.hpp | 30 | ||||
-rw-r--r-- | include/YAGE/Physics/collider.hpp | 26 | ||||
-rw-r--r-- | include/YAGE/Physics/collisionbody.hpp | 6 | ||||
-rw-r--r-- | include/YAGE/Physics/rectanglecollider.hpp | 22 | ||||
-rw-r--r-- | include/YAGE/Physics/rigidbody.hpp | 23 | ||||
-rw-r--r-- | src/rectanglecollider.cpp | 24 | ||||
-rw-r--r-- | src/resourcemanager.cpp | 2 | ||||
-rw-r--r-- | src/rigidbody.cpp | 16 | ||||
-rw-r--r-- | test/rigid_body_test.cpp | 6 |
14 files changed, 216 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bbe8a259..58161830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,27 @@ +cmake_minimum_required(VERSION 3.7) + # zedengine library cmakelists.txt +project(yage) + +# set version numbers +set(YAGE_MAJOR_VERSION 0) +set(YAGE_MINOR_VERSION 1) +set(YAGE_PATCH_VERSION 0) +set(YAGE_VERSION + ${YAGE_MAJOR_VERSION}.${YAGE_MINOR_VERSION}${YAGE_PATCH_VERSION}) + +# set standard +set(CMAKE_CXX_STANDARD 14) + +# set the test sources +set(YAGE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) +set(YAGE_TEST_DIR ${CMAKE_SOURCE_DIR}/test) + +# add include directory +set(YAGE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/YAGE) -project(YAGE) +# set binary directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # add sources to library set(YAGE_SOURCES @@ -16,8 +37,24 @@ set(YAGE_SOURCES ${PROJECT_SOURCE_DIR}/src/texturecache.cpp ${PROJECT_SOURCE_DIR}/src/window.cpp) +# find libraries +find_package(OpenGL REQUIRED) +find_package(GLEW REQUIRED) + # set include directory -include_directories(${YAGE_INCLUDE_DIRS}/YAGE/) +include_directories(${YAGE_INCLUDE_DIR}) # make it a static library add_library(${PROJECT_NAME} ${YAGE_SOURCES}) + +# add tests +add_executable(rigid_body_test + ${YAGE_TEST_DIR}/rigid_body_test.cpp) + +target_link_libraries(rigid_body_test + ${YAGE_LIBRARIES} + ${OPENGL_LIBRARIES} + ${GLEW_LIBRARIES}) + +enable_testing() +add_test(RigidBodyTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rigid_body_test) diff --git a/CTestTestfile.cmake b/CTestTestfile.cmake new file mode 100644 index 00000000..100d5804 --- /dev/null +++ b/CTestTestfile.cmake @@ -0,0 +1,7 @@ +# CMake generated Testfile for +# Source directory: /home/yannherklotz/Github/Arider/YAGE +# Build directory: /home/yannherklotz/Github/Arider/YAGE +# +# This file includes the relevant testing commands required for +# testing this directory and lists subdirectories to be tested as well. +add_test(RigidBodyTest "/home/yannherklotz/Github/Arider/YAGE/bin/rigid_body_test") diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 00000000..d0c83f0a --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1,3 @@ +RigidBodyTest 0 0 +--- +RigidBodyTest diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log new file mode 100644 index 00000000..ea8c5964 --- /dev/null +++ b/Testing/Temporary/LastTest.log @@ -0,0 +1,18 @@ +Start testing: Apr 15 14:01 BST +---------------------------------------------------------- +1/1 Testing: RigidBodyTest +1/1 Test: RigidBodyTest +Command: "/home/yannherklotz/Github/Arider/YAGE/bin/rigid_body_test" +Directory: /home/yannherklotz/Github/Arider/YAGE +"RigidBodyTest" start time: Apr 15 14:01 BST +Output: +---------------------------------------------------------- +<end of output> +Test time = 0.00 sec +---------------------------------------------------------- +Test Failed. +"RigidBodyTest" end time: Apr 15 14:01 BST +"RigidBodyTest" time elapsed: 00:00:00 +---------------------------------------------------------- + +End testing: Apr 15 14:01 BST diff --git a/Testing/Temporary/LastTestsFailed.log b/Testing/Temporary/LastTestsFailed.log new file mode 100644 index 00000000..4d8050f9 --- /dev/null +++ b/Testing/Temporary/LastTestsFailed.log @@ -0,0 +1 @@ +1:RigidBodyTest diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index 70ff2528..9806f4e3 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -3,15 +3,37 @@ #include <glm/glm.hpp> +namespace yage +{ + class Body { -private: - glm::vec2 centerOfMass_; +protected: + // current velocity of the object + glm::vec2 velocity_; + + // center of mass of the object + glm::vec2 center_of_mass_; + + // mass of the object double mass_; + + // boolean that defines if gravity can act on the object + bool gravity_; public: - virtual ~Body(); - + virtual ~Body() {} + + // apply force to the object and update the velocity + virtual void applyForce(const glm::vec2 &force)=0; +protected: + // protected constructor to initialize member variables + Body(const glm::vec2 ¢er_of_mass, double mass, const glm::vec2 &velocity, bool gravity) : + velocity_(velocity), center_of_mass_(center_of_mass), + mass_(mass), gravity_(gravity) + {} }; +} // yage + #endif diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp index ff074f14..234ff57f 100644 --- a/include/YAGE/Physics/collider.hpp +++ b/include/YAGE/Physics/collider.hpp @@ -1,13 +1,35 @@ #ifndef YAGE_COLLIDER_HPP #define YAGE_COLLIDER_HPP -// The Collider class helps collision detection +#include <glm/glm.hpp> +namespace yage +{ + +// The Collider class helps collision detection by providing a general shape +// for different shapes to have their own collision algorithms. class Collider { +protected: + // position of the object + glm::vec2 position_; + + // size of the object + glm::vec2 size_; + public: - virtual ~Collider(); + Collider(const glm::vec2 &position, const glm::vec2 &size) : position_(position), size_(size) {} + + // virtual deconstructor for classes that inherits + virtual ~Collider() {} + + // function that checks if two colliders are colliding + virtual bool collides(const Collider &collider) const=0; + + // function that returns if a point is inside the shape + virtual bool inside(const glm::vec2 &point) const=0; }; +} // yage #endif diff --git a/include/YAGE/Physics/collisionbody.hpp b/include/YAGE/Physics/collisionbody.hpp index ecbd22dc..c5f8e1f6 100644 --- a/include/YAGE/Physics/collisionbody.hpp +++ b/include/YAGE/Physics/collisionbody.hpp @@ -3,6 +3,11 @@ #include "Physics/body.hpp" +namespace yage +{ + +// a collision body will be a body that is static and not affected by gravity, +// with infinite mass class CollisionBody : public Body { public: @@ -10,5 +15,6 @@ public: virtual ~CollisionBody(); }; +} // yage #endif diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp new file mode 100644 index 00000000..b4762ea6 --- /dev/null +++ b/include/YAGE/Physics/rectanglecollider.hpp @@ -0,0 +1,22 @@ +#ifndef YAGE_RECTANGLE_COLLIDER_HPP +#define YAGE_RECTANGLE_COLLIDER_HPP + +#include "Physics/collider.hpp" + +#include <glm/glm.hpp> + +namespace yage +{ + +class RectangleCollider : public Collider +{ +public: + RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); + + virtual bool collides(const Collider &collider) const; + virtual bool inside(const glm::vec2 &point) const; +}; + +} // yage + +#endif diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp new file mode 100644 index 00000000..47f3bc01 --- /dev/null +++ b/include/YAGE/Physics/rigidbody.hpp @@ -0,0 +1,23 @@ +#ifndef YAGE_RIGID_BODY_HPP +#define YAGE_RIGID_BODY_HPP + +#include "Physics/body.hpp" + +namespace yage +{ + +class RigidBody : public Body +{ +public: + RigidBody(const glm::vec2 ¢er_of_mass, + double mass, + const glm::vec2 &velocity=glm::vec2(0.f, 0.f), + bool gravity=true); + + // apply a force to the rigid body + virtual void applyForce(const glm::vec2 &force); +}; + +} // yage + +#endif diff --git a/src/rectanglecollider.cpp b/src/rectanglecollider.cpp new file mode 100644 index 00000000..812b10d1 --- /dev/null +++ b/src/rectanglecollider.cpp @@ -0,0 +1,24 @@ +#include "Physics/rectanglecollider.hpp" + +namespace yage +{ + +RectangleCollider::RectangleCollider(const glm::vec2 &position, const glm::vec2 &size) : + Collider(position, size) +{} + +bool RectangleCollider::collides(const Collider &collider) const +{ + for(int i=position_.x; i<position_.x+size_.x; ++i) + for(int j=position_.y; j<position_.y+size_.y; ++j) + return collider.inside(glm::vec2(i, j)); + return false; +} + +inline bool RectangleCollider::inside(const glm::vec2 &point) const +{ + return position_.x<point.x && position_.x+size_.x>point.x && + position_.y<point.y && position_.y+size_.y>point.y; +} + +} // yage diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp index 06f71078..4105f4e4 100644 --- a/src/resourcemanager.cpp +++ b/src/resourcemanager.cpp @@ -7,7 +7,7 @@ TextureCache ResourceManager::texture_cache_; Texture ResourceManager::getTexture(const std::string &texture_path) { - return texture_cache_.getTexture(texture_path); + return texture_cache_.getTexture(texture_path); } } // yage diff --git a/src/rigidbody.cpp b/src/rigidbody.cpp new file mode 100644 index 00000000..3f719784 --- /dev/null +++ b/src/rigidbody.cpp @@ -0,0 +1,16 @@ +#include "Physics/rigidbody.hpp" + +namespace yage +{ + +RigidBody::RigidBody(const glm::vec2 ¢er_of_mass, double mass, const glm::vec2 &velocity, bool gravity) : + Body(center_of_mass, mass, velocity, gravity) +{} + +void RigidBody::applyForce(const glm::vec2 &force) +{ + // a=F/m + glm::vec2 acceleration(force.x/mass_, force.y/mass_); +} + +} // yage diff --git a/test/rigid_body_test.cpp b/test/rigid_body_test.cpp new file mode 100644 index 00000000..b0b1d1d6 --- /dev/null +++ b/test/rigid_body_test.cpp @@ -0,0 +1,6 @@ +#include "Physics/rigidbody.hpp" + +int main(int, char**) +{ + +} |