I'm Coding an Entire Physics Engine from Scratch
TLDRIn this engaging video, the creator tackles the daunting task of building a 3D physics engine from scratch during lockdown as a mental escape. With no prior experience in 3D physics, they embark on a journey through coding with C# and OpenGL, learning and experimenting with various sphere mesh types. The video documents the process of implementing soft body physics, using principles from Hooke's law and the ideal gas law to create a bouncy ball simulation. Despite the challenges and imperfections, the creator shares their progress and invites viewers to check out the GitHub repository for 'Geep3D', promising to address issues and possibly explore fluid simulations in future videos.
Takeaways
- π The video is about a lockdown project where the creator decides to build a 3D physics engine as a distraction.
- π οΈ The creator has previous experience with building a graphics library but is new to 3D physics.
- π¨ The project aims to include various simulations such as soft body, fluid, cloth, and rigid body dynamics.
- π» The chosen programming languages and tools for the project are C# and OpenGL.
- π The creator had to learn C# and OpenGL from scratch, which was a challenging and time-consuming process.
- π The initial focus was on creating a sphere mesh, with the Ico sphere being chosen for its even vertex distribution and triangular faces.
- π€ Physics principles from high school textbooks, like Hooke's Law and Newton's laws, were used to create the soft body dynamics.
- π The video describes the process of implementing a spring-mass system and using the ideal gas law to inflate the ball.
- π¨βπ« The creator struggled with the explicit Euler method for physics simulations and eventually switched to the Runge-Kutta 4 method.
- π§ Collision detection was a painful process, with the creator sharing their experience and the resulting code.
- π The project, named 'geep3d' for Gonki's Epic Physics Engine, is available on GitHub for others to view and contribute to.
Q & A
What is the main challenge the speaker is undertaking during lockdown?
-The speaker is undertaking the challenge of creating a 3D physics engine as a means of distraction during lockdown.
What previous experience does the speaker have with coding libraries?
-The speaker has previously created a graphics library, which took months of work, and has received comments asking about the animations made with it.
Why did the speaker choose to use C# and OpenGL for the project?
-The speaker chose C# and OpenGL because they have never used C# before and have not done anything 3D in OpenGL, making it a new and challenging learning experience.
What type of simulations does the speaker plan to include in the physics engine?
-The speaker plans to include various simulations such as soft body, fluid, cloth, and rigid body simulations in the physics engine.
What are the issues with the UV sphere mesh according to the speaker?
-The UV sphere mesh has uneven distribution of points with many vertices on the top and bottom and fewer in the middle, and it contains quadrilaterals which are not preferred in computer graphics.
What is the advantage of the ico sphere over the UV sphere and subdivided cube?
-The ico sphere is advantageous because it is made entirely of triangles, has a completely symmetrical structure, and evenly distributes vertices, making it ideal for 3D modeling.
What physics concept does the speaker use to prevent the ball from exploding?
-The speaker uses Hooke's law in a spring mass system to maintain the original length of each edge and prevent the ball from exploding.
How does the speaker address the issue of inflating the ball in the physics engine?
-The speaker uses the ideal gas law to calculate the pressure inside the ball and apply a force proportional to the area of each triangle on the ball, pushing the points outward.
What numerical method does the speaker initially use for simulating motion in the physics engine?
-The speaker initially uses the explicit Euler method for simulating motion in the physics engine.
Why does the speaker switch from the explicit Euler method to Runge-Kutta 4?
-The speaker switches to Runge-Kutta 4 because the explicit Euler method is less accurate, especially for the spring mass system, and Runge-Kutta 4 provides a more sophisticated and accurate solution.
What difficulties does the speaker encounter with collision detection in the physics engine?
-The speaker encounters significant difficulties with collision detection, which is as painful as expected, and requires a lot of time and effort to implement correctly.
How does the speaker share their experience and code with the community?
-The speaker shares their experience and code through a GitHub repository called 'geep3d' for Gonki's Epic Physics Engine, which is linked in the video description.
Outlines
π Taking on a 3D Physics Engine Challenge
The speaker, in a lockdown with nothing to do, decides to tackle a complex coding challenge: creating a full 3D physics engine. Despite having no experience in 3D physics, they have previously developed a graphics library, which they now consider improving. They plan to include various simulations like soft body, fluid, cloth, and rigid body dynamics in their engine. The speaker opts to use C# and OpenGL, languages and libraries they've never worked with before, and humorously documents their steep learning curve. After two weeks, they have a basic rendering setup, albeit with poor performance and aesthetics, and begin exploring sphere mesh generation for soft body simulation, eventually choosing the ico sphere for its triangular symmetry and even vertex distribution.
π€ Implementing Physics for a Bouncy Ball
The speaker delves into the physics of their 3D engine, starting with the creation of a bouncy ball. They discuss the use of Hooke's law for spring forces to maintain the ball's shape and Newton's second law for applying mass to each point on the ball, affecting its movement. To give the ball its bouncy characteristic, they apply the ideal gas law to pressurize it, using the relationship between pressure, volume, and force to calculate the outward force on the ball's surface. The implementation is described as challenging, taking days to complete and resulting in a less-than-perfect code. The speaker also mentions the limitations of the explicit Euler method for simulating motion and the switch to the more accurate Runge-Kutta 4 method. The paragraph concludes with a brief mention of collision detection, which is acknowledged as a difficult task, and ends with a cliffhanger as the speaker's soft body simulation struggles to clear gaps, hinting at unresolved issues and future improvements.
Mindmap
Keywords
π‘Lockdown
π‘3D Physics Engine
π‘Graphics Library
π‘Soft Body Simulations
π‘Fluid Simulations
π‘C Sharp
π‘OpenGL
π‘Sphere Meshes
π‘Spring Mass System
π‘Ideal Gas Law
π‘Explicit Euler Method
π‘Runge-Kutta 4
π‘Collision Detection
Highlights
Lockdown boredom leads to taking on the challenge of creating a 3D physics engine.
Previous experience with building a graphics library inspires a new project.
The decision to build the engine with C# and OpenGL despite having no prior experience.
Two weeks of learning and initial results with C# and OpenGL, despite poor performance and aesthetics.
Introduction to different types of sphere meshes for 3D modeling.
The choice of the ico sphere for its even vertex distribution and triangular symmetry.
Understanding the algorithm to generate an ico sphere through GitHub code.
The physics of the 3D engine starts with a simple collision model of a bouncing ball on a floor.
Incorporating Hooke's Law for spring mass system to maintain the shape of the ball.
Assigning mass to each point on the ball to simulate movement based on weight.
Using the ideal gas law to pressurize the ball and give it a bouncy effect.
Days of implementation to achieve a bouncy ball effect in the physics engine.
The limitations and inaccuracies of the explicit Euler method for physics simulations.
Transitioning to Runga Kutta 4 for more accurate physics calculations.
The struggle and learning curve of implementing Runga Kutta 4 in the physics engine.
The project's scalability and the decision to move on to collision detection.
The painstaking process of developing collision detection for the physics engine.
A demonstration of the soft body physics engine with a ball navigating gaps.
The challenges faced in fine-tuning values for collision and maintaining the engine's stability.
Invitation to the audience to view and contribute to the project on GitHub.
A humorous conclusion with the creator's intention to fix issues in a future video.
Transcripts
5.0 / 5 (0 votes)
Thanks for rating: