Skip to content

Im-Rises/physical-engine-webgl

Repository files navigation

physical-engine-webgl

cppLogo openglLogo cmakeLogo webglLogo glfwLogo

Description

This is a simple physics engine written in C++ using Glad, GLFW, OpenGl3 and Dear ImGui.

This repository is a port of the PhysicalEngine project to WebGL2.

🚀🚀 You can test it online here 🚀🚀

Note
The project is made as an educational project to learn more about physics and game engine development.

Features

Physics features

  • Basic object types (Sphere, Cube, Cylinder, Plane)
  • Particle and Rigid Body Physics
  • Collision Detection
  • Forces (Gravity, Drag, Spring, Buoyancy)
  • Torque forces (Angular Drag, Angular Spring)
  • Different types of constraints

User Interface features

  • Camera Controls
  • GameObjects Inspector
  • Scene Hierarchy

Other features

  • Basic ECS (Entity Component System)
  • Component Oriented Programming
  • Fixed Framerate
  • GameObject's speed Graph visualization

Images

RigidBodyImage

screenshot2

Building

To build the project, you need to use a UNIX system, like Ubuntu or if you're on Windows you can use WSL. Then you have to install Emscripten. You can find instructions on how to install Emscripten here:
https://emscripten.org/docs/getting_started/downloads.html

You also need to have CMake and make installed. You can find instructions on how to install CMake here:
https://cmake.org/install/

Make can be installed by running this command in the terminal:

sudo apt install make

Once you have Emscripten and CMake installed run this command in the project root directory:

emcmake cmake .

Then run this command in the same directory:

emmake make

To test the website locally

To test the website locally, you need to have Python installed. You can find instructions on how to install Python here:

https://www.python.org/downloads/

Once you have Python installed, run this command in the project build directory:

python -m http.server

Then open your browser and go to this address:

http://localhost:8000/

Controls

Game controls

To modify the speed value, you can use the ImGui window named Speed handler.

Action Key
Add speed to the left
Add speed to the right
Add speed forwardly
Add speed rearward

User controls

Action Key
Toggle fullscreen F11
Camera zoom Mouse wheel
Translate camera to the left Right Mouse Button + Mouse ← movement
Translate camera to the right Right Mouse Button + Mouse → movement
Translate camera upwards Right Mouse Button + Mouse ↑ movement
Translate camera downwards Right Mouse Button + Mouse ↓ movement
Exit app ESC

Dependencies

  • C++ 14
  • CMake
  • Emscripten (2.0.29)
  • GLFW (3.3.8)
  • OpenGl (3.3)
  • Glad (0.1.36)
  • Dear ImGui (1.89.4)
  • glm (0.9.8)

Run tests

The project has unit tests to check come common classes. You can find them in the test folder.

GitHub Actions

This project uses GitHub Actions to build the project and deploy it to GitHub

CodeQL CMake flawfinder cpp-linter Emscripten-CMake Emscripten-Publish

The project is set with a set of different scripts:

  • CodeQL: This script is used to check the code for security issues.
  • CMake: This script is used to build the project.
  • Cpp Cmake Publish: This script is used to publish the project on GitHub.
  • Flawfinder: This script is used to check the code for security issues.
  • Microsoft C++ Code Analysis: This script is used to check the code for security issues.
  • Cpp Linter: This script is used to check the code for security issues.
  • Emscripten CMake: This script is used to test build of the project using Emscripten toolchain.
  • Emscripten-Publish: This script build to webgl and publish the project on GitHub Pages.

Documentations

OpenGL:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/

OpenGL loading library:
https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library

GLFW:
https://www.glfw.org/docs/latest/

Dear ImGui:
https://github.com/ocornut/imgui

GLAD:
https://glad.dav1d.de/

GLM:
https://glm.g-truc.net/0.9.8/index.html

STB:
https://github.com/nothings/stb

ImPlot:
https://github.com/epezent/implot

Learn OpenGL:
https://learnopengl.com/Getting-started/Hello-Triangle

Developpez Learn OpenGL (Translated in French):
https://opengl.developpez.com/tutoriels/apprendre-opengl/?page=creer-une-fenetre#L4-5
https://opengl.developpez.com/tutoriels/opengl-tutorial/

Sphere OpenGL:
http://www.songho.ca/opengl/gl_sphere.html

unrealistic.dev (Change CMake working directory):
https://unrealistic.dev/posts/setting-debug-parameters-with-cmake-tools-for-visual-studio

Contributors on the WebGL port

Quentin MOREL:

GitHub contributors

Contributors on the original project

Quentin MOREL:

Gabriel REBOUL:

Clémence CLAVEL:

GitHub contributors