Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
500a4fe
fixed compilation under Windows
f-tischler Jan 23, 2018
c6999c6
refactoring & code cleanup
f-tischler Jan 23, 2018
924f987
fixed game loop timing
f-tischler Jan 24, 2018
c4dcf73
file cleanup
f-tischler Jan 24, 2018
29d4dff
create circles only to keep it simple
f-tischler Jan 24, 2018
7273dd2
refactoring
f-tischler Jan 24, 2018
2c18e8c
fixed polygon update
f-tischler Jan 24, 2018
bad6175
added world scale
f-tischler Jan 24, 2018
c55fe8d
uniform_real_distribution<> didn't work for me
csaq5507 Jan 24, 2018
09512dd
fixed uniform_real_distribution again
f-tischler Jan 24, 2018
f4c6b05
added Console, variable game loop, fps counters
cpp-tools Jan 24, 2018
43ff230
circle collision detection
csaq5507 Jan 25, 2018
5936014
Merge remote-tracking branch 'origin/FinalProject' into FinalProject
csaq5507 Jan 25, 2018
4320861
fixed uniform distribution again...
f-tischler Jan 27, 2018
6ab18ad
add collision detection
cpp-tools Jan 27, 2018
9e55d83
Merge branch 'FinalProject' of https://github.com/Beliaz/PhysicallyBa…
cpp-tools Jan 27, 2018
e9e0d2a
fixed merge
f-tischler Jan 27, 2018
75937d0
updated git ignore
f-tischler Jan 27, 2018
906932e
added eigen3 library
f-tischler Jan 27, 2018
12b4b13
moved physical calculations to separate class
f-tischler Jan 27, 2018
b41b3a6
updated render call
f-tischler Jan 27, 2018
f750b77
fixed center of mass and added indicator
f-tischler Jan 27, 2018
b63db95
added colors
f-tischler Jan 28, 2018
d640229
fixed shape transform origin
f-tischler Jan 28, 2018
cdce67b
added points velocity update
f-tischler Jan 28, 2018
4f68d66
explicit conversion between screen coordinates and world coordinates
f-tischler Jan 28, 2018
e485ac6
see last commit
f-tischler Jan 28, 2018
37cd07e
Merge branch 'physical_object' into FinalProject
f-tischler Jan 28, 2018
7b1892f
added object types (fixed, dynamic, kinematic)
f-tischler Jan 28, 2018
6729ae3
added scale to physical object
f-tischler Jan 28, 2018
7e7abb2
added bounding sphere test
f-tischler Jan 28, 2018
d165742
refactoring
f-tischler Jan 28, 2018
3320a5d
reworked collision detection to give additional info
f-tischler Jan 29, 2018
e37e5f3
fixed warnings
f-tischler Jan 29, 2018
f586c3e
added linear collision resolution
f-tischler Jan 29, 2018
99686c6
remove const qualifier from uniform_real_distribution
f-tischler Jan 29, 2018
874d0ec
added position correction
f-tischler Jan 29, 2018
d7ba3a8
stimmp des?
csaq5507 Jan 29, 2018
88420a7
added angular impulse resolution (not correct, rotates around center …
f-tischler Jan 29, 2018
ba973ab
Merge branch 'FinalProject' of https://github.com/Beliaz/PhysicallyBa…
f-tischler Jan 29, 2018
d4d9b4f
fixed rotation/inertia bug
f-tischler Jan 30, 2018
2aafa45
added friction
f-tischler Jan 30, 2018
ef3329a
new scene
f-tischler Jan 30, 2018
bf0e973
implemented symplectic euler
f-tischler Jan 30, 2018
80fca7a
added contact count scaling
f-tischler Jan 30, 2018
68e4f07
fixed line normal vector calculation
f-tischler Jan 30, 2018
7781616
added more detailed time measurements
f-tischler Jan 30, 2018
91aa32a
toggle debug info
f-tischler Jan 30, 2018
c70c0ad
code clean up & refactoring
f-tischler Jan 30, 2018
639f4f9
updated visuals
f-tischler Jan 30, 2018
362a4b9
fixed some warnings and
csaq5507 Jan 30, 2018
f14a35b
Merge remote-tracking branch 'origin/FinalProject' into FinalProject
csaq5507 Jan 30, 2018
41ca9c1
fixed some warnings and
csaq5507 Jan 30, 2018
e59ab0f
adjusted custom polygon scaling
f-tischler Jan 30, 2018
a283e4b
tweaked custom polygon scaling
f-tischler Jan 30, 2018
9c113ca
added scene resetting
f-tischler Jan 30, 2018
f87d20e
u can now move fixed objects
csaq5507 Jan 30, 2018
ad9c175
also added possibility to create fixed objects by pressing space inst…
csaq5507 Jan 30, 2018
c088cb8
fix vector pass by value
cpp-tools Jan 31, 2018
7125248
remove printf
cpp-tools Jan 31, 2018
89f931d
Merge branch 'FinalProject' of https://github.com/Beliaz/PhysicallyBa…
cpp-tools Jan 31, 2018
ef01e43
fix pass by value; release working now
cpp-tools Jan 31, 2018
05b6b73
fix missing pass by value
cpp-tools Jan 31, 2018
0de6322
fixed global center of mass accessor
f-tischler Jan 31, 2018
6d28478
improve collision resolution stability
f-tischler Jan 31, 2018
f6e3997
circles if u scroll up to 10 vertices & center points for moving objects
csaq5507 Jan 31, 2018
8d76094
fixed normals used by position correction
f-tischler Jan 31, 2018
0644a15
disable eigen3 alignment for debugging
f-tischler Jan 31, 2018
743a358
Merge branch 'FinalProject' of https://github.com/Beliaz/PhysicallyBa…
f-tischler Jan 31, 2018
b2cfe7c
added contact scaling to position correction
f-tischler Jan 31, 2018
f690c5d
removed cof indicator in normal mode
f-tischler Jan 31, 2018
5b5f953
fixed bug in custom polygon
f-tischler Jan 31, 2018
1319508
fixed duplicate application of contact scaling
f-tischler Jan 31, 2018
f4982fb
refactored collision resolution
f-tischler Jan 31, 2018
0688f2b
fixed warnings
f-tischler Jan 31, 2018
3f1200a
refactored integration
f-tischler Jan 31, 2018
178a941
fix previous commit
f-tischler Jan 31, 2018
29a116f
reworked contact info
f-tischler Jan 31, 2018
0b305b9
OpenMP parallelization
f-tischler Jan 31, 2018
7d41159
refactoring
f-tischler Feb 1, 2018
f038c73
fixed debug output in release
f-tischler Feb 1, 2018
1e1bdf8
fixed center of mass
f-tischler Feb 1, 2018
51e56a2
restitution slop
f-tischler Feb 1, 2018
11394a7
fixed penetration depth
f-tischler Feb 1, 2018
083a9b2
fixed collision detection
f-tischler Feb 1, 2018
29d9bce
revert penetration depth fix
f-tischler Feb 1, 2018
14962e0
added presentation
f-tischler Feb 1, 2018
c9b7ff7
fix center of mass
f-tischler Feb 1, 2018
f510f9c
added fullscreen mode for presentation
f-tischler Feb 1, 2018
e16a159
updated presentation
f-tischler Feb 1, 2018
aa025dc
OpenMP flags
f-tischler Feb 4, 2018
3f44197
force integration fix
f-tischler Feb 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ Assignment1/CMakeSettings.json
**/.vs/VSWorkspaceState.json
.idea/
cmake-build-debug/


Final/SFML-2.4.2
Final/.vs
**/.vs/
**/CMakeSettings.json
File renamed without changes.
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.6)
project(PhysicallyBasedSimulation LANGUAGES CXX)

cmake_minimum_required(VERSION 3.5.1)
project(FinalProject LANGUAGES CXX)

add_subdirectory(
Final
)

Final
)
33 changes: 20 additions & 13 deletions Final/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
cmake_minimum_required(VERSION 3.5.1)
project(FinalProject LANGUAGES CXX)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH})

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /wd4141")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:strict /std:c++latest /wd4141")
set(CMAKE_CXX_FLAGS_RELEASE "/Ox /Ot /DNDEBUG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
endif()

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Polygon.cpp
file(GLOB SOURCE_FILES
"*.h"
"*.cpp"
)

add_executable(FinalProject ${SOURCE_FILES})
add_executable(FinalProject ${SOURCE_FILES} ${HEADERS})

target_include_directories(FinalProject PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH})
set(SFML_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/SFML-2.4.2)

find_package(SFML 2 REQUIRED network audio graphics window system)

if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(FinalProject ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(FinalProject ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
target_link_libraries(FinalProject ${EIGEN3_LIBRARIES} ${EIGEN3_DEPENDENCIES})

FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
122 changes: 122 additions & 0 deletions Final/Console.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#pragma once

#include <SFML/Graphics.hpp>

#include <iomanip>
#include <mutex>
#include <sstream>
#include <unordered_map>

class console
{
public:
static console& instance()
{
static console console;
return console;
}

void init()
{
if (!font.loadFromFile("arial.ttf"))
{
// error...
}

m_text.setFont(font);
m_text.setCharacterSize(12);
m_text.setFillColor(sf::Color::White);
}

template<typename T>
void set_param(const std::string& name, const T& value)
{
std::stringstream stm;
stm << std::fixed << std::setprecision(2) << value;

m_params[name] = stm.str();
update();
}

void print(sf::RenderWindow& window)
{
std::lock_guard <decltype(m_lock)> ga{ m_lock };

window.draw(m_text);
}

private:
console()
{

}

void update()
{
std::stringstream stm;

for (auto itr : m_params)
stm << itr.first + ": " + itr.second << std::endl;

{
std::lock_guard <decltype(m_lock)> ga{ m_lock };
m_text.setString(stm.str());
}
}

std::mutex m_lock;
sf::Text m_text;
std::unordered_map<std::string, std::string> m_params;
sf::Font font;
};

template<class SmootherType, class FuncType>
void measure(const std::string name, SmootherType& smoother, const FuncType& func)
{
using namespace std::chrono;
using clock = high_resolution_clock;

const auto start_frame = clock::now();

func();

const auto elapsed = duration_cast<milliseconds>(clock::now() - start_frame);

smoother.add(static_cast<double>(elapsed.count()));

console::instance().set_param(name, smoother.get());
};

template<class FuncType, typename =
std::enable_if_t<std::is_void_v<std::result_of_t<std::decay_t<FuncType>()>>>>
void measure(const std::string name, const FuncType& func)
{
using namespace std::chrono;
using clock = high_resolution_clock;

const auto start_frame = clock::now();

func();

const auto elapsed = duration_cast<milliseconds>(clock::now() - start_frame);

console::instance().set_param(name, elapsed.count());
};

template<class FuncType, typename =
std::enable_if_t<!std::is_void_v<std::result_of_t<std::decay_t<FuncType>()>>>>
auto measure(const std::string name, const FuncType& func)
{
using namespace std::chrono;
using clock = high_resolution_clock;

const auto start_frame = clock::now();

auto result = func();

const auto elapsed = duration_cast<milliseconds>(clock::now() - start_frame);

console::instance().set_param(name, elapsed.count());

return result;
};
63 changes: 63 additions & 0 deletions Final/ContactInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include "physical_object.h"


class contact_info
{
public:
contact_info(physical_object& point_owner,
const point_t& point,
physical_object& line_owner,
const line_t& line,
const double penetration_depth,
const Vector2d& point_of_intersection)
: point_owner_(point_owner),
point_(point),
line_owner_(line_owner),
line_(line),
penetration_depth_(penetration_depth),
point_of_intersection_(point_of_intersection)
{
}

physical_object& line_owner() const { return line_owner_; }
physical_object& point_owner() const { return point_owner_; }

const point_t& line_start_point() const { return line_owner_.points()[std::get<0>(line_)]; }
const point_t& line_end_point() const { return line_owner_.points()[std::get<1>(line_)]; }

Vector2d line_start_offset() const { return std::get<0>(line_start_point()); }
Vector2d line_end_offset() const { return std::get<0>(line_end_point()); }
Vector2d line_offset() const { return (line_start_offset() + line_end_offset()) / 2.0; }

const point_t& contact_point() const { return point_; }
const Vector2d& contact_point_offset() const { return std::get<0>(point_); }
const Vector2d& contact_point_velocity() const { return std::get<1>(point_); }

Vector2d relative_velocity() const
{
const Vector2d line_velocity =
(std::get<1>(line_start_point())
+ std::get<1>(line_end_point())) / 2.0;

return contact_point_velocity() - line_velocity;
}

Vector2d normal() const
{
return ::normal(line_start_offset(), line_end_offset());
}

double penetration_depth() const { return penetration_depth_; }

private:
physical_object& point_owner_;
point_t point_;

physical_object& line_owner_;
line_t line_;

double penetration_depth_;
Vector2d point_of_intersection_;
};
Loading