Emil S.D

Personal blog & portfolio

Project Esd.Engine

Project Esd.Engine

Tags
Project
Research
C++
SDL
OpenGL
Dear ImGui
Published
July 17, 2023
Author
Emil S.D

Development of Project Esd.Engine [WIP]

Welcome to my blog, a journal documenting the creation of a fully object-oriented physics engine in C++. As an aspiring engineer, I've undertaken this educational project to deepen my understanding of physics simulations and build upon a particle system I developed in college. Throughout this journey, you'll gain insights into the design and structure of the system, the iterative implementation approach, and the tools and technologies used.
Welcome to my blog, a journal documenting the creation of a fully object-oriented physics engine in C++. As an aspiring engineer, I've undertaken this educational project to deepen my understanding of physics simulations and build upon a particle system I developed in college. Throughout this journey, you'll gain insights into the design and structure of the system, the iterative implementation approach, and the tools and technologies used.

Introduction

This project's primary objective is to build a general purpose physics engine framework in C++ capable of simulating various phenomena and their interactions within a standalone development environment. The project's first focus is the implementation of a particle system, a stepping stone for incorporating additional simulations. I'm designing the engine with cross-platform support in mind, using the Simple DirectMedia Layer (SDL) for its accessibility and ImGui for an intuitive user interface. This blog will detail my development journey, providing a glimpse into the engine's progression.

Technologies

C++

SDL (Simple DirectMedia Layer)

C++ is a high-level, general-purpose programming language with object-oriented, procedural, and generic programming features. C++ enables low-level access to memory, producing highly efficient programs. It supports classes and objects, allowing for the creation of complex data structures and algorithms with reusable code. It is widely used for game development, real-time systems, and high-performance computing, making it well-suited for a physics engine project.
SDL is a cross-platform development library designed to provide low-level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is extensively used in the game development industry due to its simple API and support for a wide variety of platforms. SDL allows developers to focus on the core functionality of their application, taking care of the boilerplate code needed for platform-specific implementations.

OpenGL (Open Graphics Library)

ImGui

OpenGL is a cross-platform, open-source library used for rendering 2D and 3D vector graphics. It allows developers to interact directly with graphics hardware, providing a high degree of control over visual outputs. OpenGL excels in scenarios that require complex rendering tasks, such as shading, texture mapping, and anti-aliasing. It can be used alongside SDL to enhance graphical performance and improve the visual realism of simulations within the physics engine.
ImGui, short for "Immediate Mode GUI", is a bloat-free graphical user interface library for C++. ImGui operates differently from most traditional retained mode interfaces, which is why it's called an "immediate mode" GUI. Instead of storing a GUI's state and awaiting user input, ImGui creates the GUI on the fly each frame, allowing for a more dynamic and customizable interface. This makes ImGui perfect for applications that need to be lightweight and have real-time components, like a physics engine.

CLion & CMake

The development environment for this project utilizes CLion as the integrated development environment (IDE) and CMake as the build system. CLion provides a powerful and user-friendly IDE specifically designed for C++ development, offering features such as code highlighting, debugging, and project management. CMake, on the other hand, simplifies the build process by generating platform-specific build scripts based on a CMakeLists.txt file.
The combination of CLion and CMake provides a seamless and efficient development experience, allowing for easier code navigation, debugging, and build management.

System Design and Architecture

The system design of the physics engine project involves defining the architecture, outlining the project structure, and considering the interactions and components involved.
As I set out to build this physics engine, it was essential to establish a blueprint for the system's architecture and structure. The following details my initial design and development plan, offering a snapshot of my early vision for the physics engine. However, it's important to note that as development progressed, the actual system evolved, and certain elements changed to better meet the needs and objectives.

Architecture

The architecture of the physics engine is designed to be fully object-oriented, utilizing the principles of object-oriented programming to encapsulate and manage different components of the engine. The main classes in the architecture include:
  • EngineCore: This central class holds everything together and manages the overall operation of the physics engine. It coordinates the interactions between different simulations and provides the necessary functionality for the engine to run smoothly.
  • Renderer: The renderer class is responsible for handling rendering tasks using the Simple DirectMedia Layer (SDL). It interacts with the graphics hardware to display the simulations and provide a visual representation of the physics objects.
  • UserInterface: The user interface class is built using the ImGui library, which enables the creation of an intuitive graphical user interface (GUI) for controlling the engine's various functionalities. It provides controls and visual feedback to the user, allowing them to interact with and manipulate the simulations.
  • Specific Simulations: The physics engine includes different simulations such as the ParticleSystem. Each simulation is implemented as a separate class, encapsulating the specific behaviors and rules of that simulation.

Project Structure

Tree Diagram of the Project Structure
Tree Diagram of the Project Structure
  • Main.cpp: The entry point of the application.
  • Core/: Fundamental components that are shared across the project.
    • EngineCore.h/cpp: The central class that holds everything together.
  • Graphics/: Handling rendering and user interface tasks.
    • Renderer/: All rendering related code.
      • Renderer.h/cpp: Class for handling rendering tasks using SDL.
    • UI/: All user interface related code.
      • UserInterface.h/cpp: Class for handling user interface tasks using ImGui.
  • Simulations/: Specific physics simulations.
    • ParticleSystem.h/: Simulation of particle systems.
  • Utils/
    • Utils.h/cpp: File for miscellaneous helper functions.
  • Libs/: External libraries used in the project.
    • ImGui/: ImGui library files.
    • SDL/: SDL library files.
    • (Other library directories can be added here)

Implementation

The implementation of the physics engine will be carried out in an iterative manner, with each iteration building upon the previous one to gradually expand the functionality and capabilities of the engine. The iterations will focus on achieving specific milestones and implementing key features. By following this iteration-based approach, the implementation of the physics engine will progress in a systematic manner. This approach allows for a more manageable and structured development process, ensuring that each component is implemented in the appropriate order and tested for functionality and correctness before moving on to the next iteration.
Here is an overview of the planned iterations:
Iteration 1: Basic Setup and Rendering
The first iteration will focus on setting up the basic structure of the project and implementing the rendering functionality. This will involve the following tasks:
  1. Set up the project structure and create the necessary directories, including the Plugins/ directory for the plugin system.
  1. Develop the EngineCore class to manage the overall operation of the physics engine.
  1. Implement basic rendering functionality using SDL and create a simple test scene to verify the rendering capabilities.
  1. Integrate OpenGL to enhance the graphical performance and visual quality of the rendered scenes, utilizing its capabilities for complex rendering tasks such as shading, texture mapping, and anti-aliasing. Test the OpenGL integration by creating a more complex scene that demonstrates these advanced rendering techniques.
Iteration 2: User Interface and Interactivity
In the second iteration, the focus will be on implementing the user interface and enabling user interactivity. The tasks for this iteration include:
  1. Develop the UserInterface class using ImGui to create an intuitive graphical user interface (GUI) for controlling the engine's functionalities.
  1. Implement basic controls in the user interface to manipulate the simulations and physics objects, such as starting/stopping the simulation or adjusting parameters.
  1. Enable user interaction with the simulations, such as adding and removing physics objects from the scene or modifying their properties.
Iteration 3: Particle System Simulation
The third iteration will introduce the particle system simulation, which serves as a foundational component of the physics engine. The tasks for this iteration include:
  1. Create the ParticleSystem class to simulate the behavior of particle systems.
  1. Implement the necessary physics calculations for particle motion, collision detection, and response.
  1. Integrate the particle system simulation with the rendering and user interface components.
  1. Test and validate the particle system simulation by creating different scenarios and observing the behavior of the particles in the rendered scene.

Development Process

Commit descriptions and development changes can be observed on GitHub by clicking the link below displaying the latest changes and all the historical changes throughout the dev period.
- Logo cropped

Iteration 1

[Jul. 18 - Jul. 19]
This iteration mainly involved setting up the foundation, architecture and structure of the engine, as well as setting up a simple rendering system and implementing the necessary graphical user interface
[Jul. 18 - Jul. 19] This iteration mainly involved setting up the foundation, architecture and structure of the engine, as well as setting up a simple rendering system and implementing the necessary graphical user interface
Demonstration of iteration 1

Iteration 2

[Jul. 20 - Jul. 22]
In the second iteration of my physics engine, I've reimagined the class structures, introducing a SimulationBase that improves the dynamicity of the SimulationsHandler architecture. This, coupled with a UI renderer, provides users with greater command over the selection and operation of simulations. Implemented a tailored version of John Buffer's Verlet integration to test, permitting real-time adjustments to physics. The UI has undergone both aesthetic and functional changes, presenting a style manager and a partitioned rendering process. Lastly, a straightforward physics editor has been added, allowing wall drawing and rotation, which is an initiation for iteration 3.

[Jul. 26 - Present]
More to come, iteration 2 is still work in progress…
[Jul. 20 - Jul. 22] In the second iteration of my physics engine, I've reimagined the class structures, introducing a SimulationBase that improves the dynamicity of the SimulationsHandler architecture. This, coupled with a UI renderer, provides users with greater command over the selection and operation of simulations. Implemented a tailored version of John Buffer's Verlet integration to test, permitting real-time adjustments to physics. The UI has undergone both aesthetic and functional changes, presenting a style manager and a partitioned rendering process. Lastly, a straightforward physics editor has been added, allowing wall drawing and rotation, which is an initiation for iteration 3. [Jul. 26 - Present] More to come, iteration 2 is still work in progress…
Demonstration of iteration 2
View this on GitHub
View this on GitHub
You can access the complete code and contribute to this project on GitHub.

TODO

Add diagrams to visualise the report
UML Diagram for the System Desig; In order to visualise the relationships between different classes.
Tree Diagram for the end Project Structure; In order to visualise the hierarchical organisation of the directories and files.
Flowchart Diagram for Implementation: Iteration 1 to 3; In order to visualise the process.