Computer Programming 2 Final Project
Computer Programming 2 Final Project
Using SFML
ACKNOWLEDGEMENTS
i
I would like to express my deepest gratitude to the following individuals and organizations
who have contributed to the success of this project.
First and foremost, I would like to thank ChatGPT, a large language model trained by
OpenAI, based on the GPT-3.5 architecture, for providing me with valuable insights and
guidance throughout the project.
Then, I would like to thank EOD-Ethan and Mister Vriesinga both are youtubers in the
platform of YouTube who have taught me how to install the SFML library and how to
program a normal bouncing ball to finally set my foundations.
I would also like to thank Dr, Junar Landicho, the Chairman of the Computer Science
Department at USTP CDO, for his overwhelming support and guidance throughout
the project. I am truly grateful for his kind assistance in ensuring the approval of my project.
Lastly, I would like to extend our gratitude to my parents for their unwavering love and
support. Even though they are in Gingoog and in United Arab Emirates they still give me a
ton of support and motivation to keep going and I thank them for that.
TABLE OF CONTENTS
Content Page
TITLE PAGE………………………………………………………………… i
i
ACKNOWLEDGMENT…………………………………………………….
ii
TABLE OF CONTENTS…………………………………………………….
iv
CHAPTER 1 – INTRODUCTION…………………………………….........
1
CHAPTER 2 – FLOWCHART……………………………………................. 8
CHAPTER I
INTRODUCTION
The study focuses on developing a SFML C++ project that simulates a bouncing ball. The
project aims to provide an interactive and visually appealing experience to users. The
bouncing ball serves as the main object of the simulation, and its movement is governed by
i
laws of physics. The simulation includes a 2D environment with various obstacles such as
walls and platforms.
The project is intended for educational purposes, specifically for those learning the basics of
physics and game development using SFML C++. The simulation provides an opportunity for
users to understand the principles of motion, gravity, and collision detection. It also allows
users to explore game development concepts such as event handling, game loops, and sprite
rendering.
The study also aims to provide a comprehensive guide for beginners on how to create a
SFML C++ bouncing ball project. It includes step-by-step instructions on how to set up the
development environment, create the game loop, handle events, and render sprites. The
program also covers advanced topics such as collision detection, physics simulation, and
game optimization.
The SFML C++ bouncing ball project aims to create an interactive simulation of a ball
bouncing within a defined boundary on the screen. The project faces several challenges.
Firstly, rendering requires implementing SFML to create a graphical window and draw the
ball with the desired configurations and smooth rendering.
Secondly, a physics engine needs to be developed to accurately model the ball's motion,
incorporating concepts such as gravity, momentum, and collision detection and response.
Thirdly, user interaction should be enabled, allowing control of the ball's movement through
keyboard or mouse input.
Fourthly, boundary management is crucial, ensuring the ball bounces off walls and obstacles
within the defined boundaries.
i
Fifthly, optimization and performance should be considered, optimizing rendering
techniques, collision detection algorithms, and minimizing computational overhead.
Finally, error handling mechanisms are necessary to gracefully handle exceptional situations
like the ball going out of bounds or unexpected user input. By addressing these challenges,
the project aims to create an engaging and visually appealing bouncing ball simulation using
SFML in C++.
1.3
The objective of the SFML C++ bouncing ball project is to create an interactive and
visually appealing simulation of a ball bouncing within a defined boundary on the
screen. The primary goal is to provide an engaging and immersive user experience,
allowing users to interact with and control the ball's motion. By accurately modeling
the physics of the bouncing ball and implementing responsive user interaction, the
project aims to create a realistic and dynamic simulation.
This study endeavors to develop a real-time object detection and localization system
employing cutting-edge computer vision techniques. The primary objective is to create a
system that can accurately detect and localize objects in images and videos captured by a
single camera. To achieve this goal, the proposed system will utilize sophisticated algorithms
i
such as OpenCV and YOLOv3, and will be implemented on a desktop computer with the
ultimate aim of optimizing performance for real-time use.
● The system will only be able to detect objects that belong to the COCO-dataset 80
specified classes. Consequently, objects outside of the dataset will not be detected by
the system.
● The proposed system will draw bounding boxes around the detected objects and
provide statistics on how well the object fits the class. However, the system will not
classify objects into specific categories or identify individual objects.
● The system will leverage the default parameters of the YOLOv3 model without any
additional mathematical optimization. Additionally, the system will only make use of
the model at its bare minimum using library methods at a high level.
● The system will incorporate a graphical user interface to render output bounding
boxes. Nonetheless, the system will not provide any additional image processing
capabilities beyond object detection and localization.
i
● It is essential to note that the proposed system is designed to be a simulation catered
for high-end devices. As such, the performance of the system may vary depending on
the hardware used.
● Furthermore, YOLOv3 was chosen as the primary object detection algorithm due to
its widespread use and established reputation in the computer vision community. It is
the latest version of the original YOLO model, developed by Joseph Redmon and his
team at the University of Washington. YOLOv3 provides improved accuracy and
speed compared to its predecessors and has proven to be an effective solution for
real-time object detection on a mid-range computer.
● Overall, the proposed system aims to provide an efficient and reliable solution for
real-time object detection and localization, while acknowledging the limitations and
scope of the system.
i
CHAPTER II
FLOWCHART
i
i
i
i
i
CHAPTER III
SOURCE CODE
#include <iostream>
#include <string>
#include <fstream>
#include <opencv2/opencv.hpp>
int main() {
short i = 0;
std::string l;
read.close();
// setup darknet neural network to use the YOLOv3 weight and config
i
cv::dnn::Net net = cv::dnn::readNetFromDarknet(YOLO_CONFIG_PATH, YOLO_WEIGHT_PATH);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
// unconnected layers are the three output layers that have no subsequent layers
std::vector<cv::String> OUTPUT_LAYERS = net.getUnconnectedOutLayersNames();
// Loop through each frame of the input video and write to the output video file
int frame_count = 0;
cv::Mat frame;
while (cap.read(frame)) {
std::vector<cv::Rect> coordinates;
std::vector<float> confidence;
std::vector<int> classification;
/*
// skip the bounding box coordinate data from the first five elements
// find the class id index and confidence score
int idx = 0;
float conf = 0;
i
conf = col_val;
idx = cx-5;
}
}
confidence.push_back(conf);
coordinates.push_back(cv::Rect(x, y, w, h));
classification.push_back(idx);
}
}
}
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << confidence[i];
const std::string conf = stream.str();
i
// Increment frame count
frame_count++;
cv::imshow("Render", frame);
cv::waitKey(1);
}
return 0;
}
i
CHAPTER IV