Skip to content

Commit a362907

Browse files
authored
Merge pull request #47 from SpaceYoshi/dev
First release
2 parents a544d12 + ee68d8d commit a362907

1,044 files changed

Lines changed: 475126 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 440 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
1-
# augmented-reality
1+
<p align="center">
2+
<a href="https://github.com/SpaceYoshi/traffic-tactician/" rel="noopener">
3+
<img width=400px height=400px src="logo.png" alt="Project logo"></a>
4+
</p>
5+
6+
<h3 align="center">Traffic Tactician</h3>
7+
8+
<div align="center">
9+
10+
[![Stars](https://img.shields.io/github/stars/SpaceYoshi/traffic-tactician.svg)](https://github.com/SpaceYoshi/traffic-tactician/stargazers)
11+
[![GitHub Issues](https://img.shields.io/github/issues/SpaceYoshi/traffic-tactician.svg)](https://github.com/SpaceYoshi/traffic-tactician/issues)
12+
[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/SpaceYoshi/traffic-tactician.svg)](https://github.com/SpaceYoshi/traffic-tactician/pulls)
13+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE)
14+
15+
</div>
16+
17+
---
18+
19+
<p align="center"> A traffic controller training program in C++ using <a href="https://opencv.org/">OpenCV</a> & <a href="https://www.opengl.org/">OpenGL</a>.
20+
<br>
21+
</p>
22+
23+
## 📝 Table of Contents
24+
- [About](#about)
25+
- [Built Using](#built_using)
26+
- [Authors](#authors)
27+
28+
## 🧐 About <a name = "about"></a>
29+
Traffic Tactician is a training program made in C++ for a uni assignment. The software uses <a href="https://opencv.org/">OpenCV</a> & <a href="https://www.opengl.org/">OpenGL</a>.
30+
31+
⚠ Note: Ensure that your environment variables are configured correctly for OpenCV. This includes a variable "OPENCV" that leads to your OpenCV build folder (e.g. *C:\opencv*). Your Path variable should also contain the *C:\opencv\build\x64\vc16\bin* directory or equivalent.
32+
33+
⚠ Note: Make sure to download the *pose_iter_440000.caffemodel* from the [CMU School of Computer Science](https://www.cs.cmu.edu/), and put it in *${SolutionDir}\TrafficTactician\pose\coco*.
34+
35+
⚠ Note: In case of getting the "could not find opencv_world490d.lib" error, check that you have installed (the right version of) OpenCV correctly, and have configured it in your environment variables. Alternatively, you can drag the .dll files manually into *${SolutionDir}\TrafficTactician\x64\${ConfigurationName}*.
36+
37+
⚠ Note: Make sure to build the solution when making changes to *settings.json* to ensure having the updated header file.
38+
39+
## ⛏️ Built Using <a name = "built_using"></a>
40+
- [OpenGL](https://opengl.org/) - The Industry's Foundation for High Performance Graphics
41+
- [OpenCV](https://opencv.org/) - World's biggest computer vision library
42+
- [GLFW](https://www.glfw.org/) - Open Source, multi-platform library for OpenGL
43+
- [GLM](https://github.com/g-truc/glm/) - OpenGL Mathematics (GLM)
44+
- [GLEW](https://github.com/nigels-com/glew/) - The OpenGL Extension Wrangler Library
45+
- [Dear ImGui](https://github.com/ocornut/imgui/) - The bloat-free graphical user interface library for C++
46+
- [Easylogging++](https://github.com/abumq/easyloggingpp/) - Single header efficient logging library for C++ applications
47+
- [json2hpp](https://github.com/KaixoCode/json2hpp/) - CMake module that converts a json file straight into a C++ header containing a constexpr object
48+
- [utest.h](https://github.com/sheredom/utest.h) - Single header unit testing framework for C and C++
49+
50+
## ✍️ Authors <a name = "authors"></a>
51+
- [@OnsPetruske](https://github.com/pkg-dot-zip)
52+
- [@SpaceYoshi](https://github.com/SpaceYoshi)
53+
- [@lrstolk](https://github.com/lrstolk)
54+
- [@Mosu5](https://github.com/Mosu5)
55+
- [@Sam-D-C](https://github.com/Sam-D-C)
56+
- [@Yuichi135](https://github.com/Yuichi135)
57+
58+
See also the list of [contributors](https://github.com/SpaceYoshi/traffic-tactician/contributors) who participated in this project.

TrafficTactician/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!json2hpp.exe
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <mutex>
2+
#include "easylogging++.h"
3+
#include "poseChecker.h"
4+
#include "poseRetriever.h"
5+
#include "SettingsRetriever.h"
6+
7+
Pose currentPose;
8+
std::mutex mtx;
9+
10+
namespace cameraInputHandler
11+
{
12+
int cameraToUseForInput = GetDNNSettings().cameraToUse;
13+
14+
int getCameraToUse()
15+
{
16+
return cameraToUseForInput;
17+
}
18+
19+
void setCameraToUse(int camera)
20+
{
21+
LOG(INFO) << "Setting camera to initialize the input with to camera " << cameraToUseForInput << "!" << std::endl;
22+
cameraToUseForInput = camera;
23+
}
24+
25+
void setInputPose(const Pose& poseToSetTo)
26+
{
27+
std::lock_guard lck(mtx);
28+
currentPose = poseToSetTo;
29+
}
30+
31+
Pose& getInputPose()
32+
{
33+
std::lock_guard lck(mtx);
34+
return currentPose;
35+
}
36+
37+
void initCameraInput(int cameraDevice = -1)
38+
{
39+
LOG(INFO) << "Launching thread for camera detection." << std::endl;
40+
std::thread thread_object(runPoseRetriever, cameraDevice);
41+
thread_object.detach();
42+
}
43+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include "poseChecker.h"
3+
namespace cameraInputHandler
4+
{
5+
int getCameraToUse();
6+
void setCameraToUse(int camera);
7+
void setInputPose(const Pose& poseToSetTo);
8+
Pose& getInputPose();
9+
void initCameraInput(int cameraDevice);
10+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "ControllerComponent.h"
2+
#include "GameObject.h"
3+
#include "CameraInputHandler.h"
4+
#include <iostream>
5+
#include <memory>
6+
7+
#include "easylogging++.h"
8+
#include "Scene.h"
9+
#include "SoundHandler.h"
10+
#include "Timer.h"
11+
12+
ControllerComponent::ControllerComponent(Pose pose, Scene* scene) : scene(scene), correctPose(pose)
13+
{
14+
this->timer = std::make_shared<Timer>([this] { timerCallback(); });
15+
}
16+
17+
bool ControllerComponent::checkPose() const
18+
{
19+
return cameraInputHandler::getInputPose() == correctPose;
20+
}
21+
22+
void ControllerComponent::changeCarState(RouteComponent::RouteState state) const
23+
{
24+
if (gameObject->getComponent<RouteComponent>().has_value())
25+
{
26+
gameObject->getComponent<RouteComponent>().value()->crossed = true;
27+
gameObject->getComponent<RouteComponent>().value()->state = state;
28+
}
29+
else
30+
{
31+
LOG(ERROR) << "Error: Can not update UI when no RouteComponent can be found." << std::endl;
32+
throw std::exception("Error: Can not update UI when no RouteComponent can be found.");
33+
}
34+
}
35+
36+
void ControllerComponent::timerCallback() const
37+
{
38+
// If pose was wrong, points --.
39+
if (!checkPose())
40+
{
41+
scene->data.points--;
42+
SoundHandler::getInstance().playSoundSnippet("sounds/points_minus.wav");
43+
return;
44+
}
45+
46+
47+
// If pose was wrong, points ++.
48+
changeCarState(RouteComponent::RouteState::Moving);
49+
timer->toggleTimer(false);
50+
scene->data.points++;
51+
SoundHandler::getInstance().playSoundSnippet("sounds/points_plus.wav");
52+
}
53+
54+
void ControllerComponent::update(float deltaTime)
55+
{
56+
timer->update(deltaTime);
57+
58+
// Update overlay data
59+
scene->data.remainingTime = timer->getTimeRemaining();
60+
scene->data.progress = timer->getTimeRemaining() / timer->rolloverTime;
61+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include "Component.h"
3+
#include <memory>
4+
#include <string>
5+
#include "CameraInputHandler.h"
6+
#include "Scene.h"
7+
#include "Timer.h"
8+
#include "RouteComponent.h"
9+
10+
11+
class ControllerComponent : public Component
12+
{
13+
Scene* scene;
14+
public:
15+
std::shared_ptr<Timer> timer;
16+
Pose correctPose;
17+
18+
ControllerComponent(Pose pose, Scene* scene);
19+
~ControllerComponent() = default;
20+
21+
bool checkPose() const;
22+
void changeCarState(RouteComponent::RouteState state) const;
23+
void timerCallback() const;
24+
25+
virtual void update(float deltaTime) override;
26+
};
27+

TrafficTactician/GLFW.props

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ImportGroup Label="PropertySheets" />
4+
<PropertyGroup Label="UserMacros" />
5+
<PropertyGroup />
6+
<ItemDefinitionGroup>
7+
<ClCompile>
8+
<AdditionalIncludeDirectories>$(SolutionDir)lib\glm;$(SolutionDir)lib\glew-2.1.0\include;$(SolutionDir)lib\glfw-3.3.8\include;$(OPENCV)\build\include;$(SolutionDir)lib\imgui-docking;$(OPENGL)\lib\glm;$(OPENGL)\lib\glew-2.1.0\include;$(OPENGL)\lib\glfw-3.3.8\include;$(SolutionDir)components;$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9+
<PreprocessorDefinitions>GLEW_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
10+
</ClCompile>
11+
<Link>
12+
<AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.8\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);$(OPENCV)\build\x64\vc16\lib;$(OPENGL)\lib\glew-2.1.0\lib\Release\$(Platform);$(OPENGL)\lib\glfw-3.3.8\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
13+
<AdditionalDependencies>opencv_world490d.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
14+
<SubSystem>NotSet</SubSystem>
15+
</Link>
16+
</ItemDefinitionGroup>
17+
<ItemGroup />
18+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "KeyboardInputHandler.h"
2+
3+
#include <ostream>
4+
5+
#include "easylogging++.h"
6+
#include "CameraInputHandler.h"
7+
8+
extern bool drawDebugMenu;
9+
bool enableWireframe = false;
10+
11+
void initKeyCallback(GLFWwindow* window)
12+
{
13+
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
14+
{
15+
if (key == GLFW_KEY_ESCAPE)
16+
{
17+
glfwSetWindowShouldClose(window, true);
18+
}
19+
20+
if (key == GLFW_KEY_1 && action == GLFW_RELEASE)
21+
{
22+
cameraInputHandler::setInputPose(POSE_MOVE_FORWARD);
23+
}
24+
25+
if (key == GLFW_KEY_2 && action == GLFW_RELEASE)
26+
{
27+
cameraInputHandler::setInputPose(POSE_MOVE_LEFT);
28+
}
29+
30+
if (key == GLFW_KEY_3 && action == GLFW_RELEASE)
31+
{
32+
cameraInputHandler::setInputPose(POSE_MOVE_RIGHT);
33+
}
34+
35+
if (key == GLFW_KEY_4 && action == GLFW_RELEASE)
36+
{
37+
cameraInputHandler::setInputPose(POSE_STOP);
38+
}
39+
40+
if (key == GLFW_KEY_5 && action == GLFW_RELEASE)
41+
{
42+
cameraInputHandler::setInputPose(POSE_OTHER);
43+
}
44+
45+
if (key == GLFW_KEY_8 && action == GLFW_RELEASE)
46+
{
47+
enableWireframe = !enableWireframe;
48+
glPolygonMode(GL_FRONT_AND_BACK, enableWireframe ? GL_FILL : GL_LINE);
49+
}
50+
51+
if (key == GLFW_KEY_9 && action == GLFW_RELEASE)
52+
{
53+
drawDebugMenu = !drawDebugMenu;
54+
}
55+
});
56+
57+
58+
LOG(INFO) << "Initialized input callback." << std::endl;
59+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
#include <GLFW/glfw3.h>
3+
void initKeyCallback(GLFWwindow* window);

0 commit comments

Comments
 (0)