June 19, 2025
Couldn't do much today but still got some done mainly bug fixes. Update moment of inertia after editing mass of rigidbody. Correctly dampen drag springs. Edit collision resolution optimization code. Changed dragging check to be an enum and not bool to allow for 3 states Starting InProcess NotDragging instead of just dragging and not dragging. Added function to safely remove springs. Added function to get the current mouse world position. Added way to change input modes with keyboard. Added way to change spawned spring parameters. Here is me playing with the bug fixed springs. Still some errors but I'll get to fixing them.
Couldn't do very much work today was busy with a bunch of other stuff but I still managed to get some done. Added the ability to select rigid bodies and change their properties. I also added the ability to drag rigid bodies with springs and attach springs between rigid bodies. Gravity also now actually works as it should as I fixed some code that was made for stability reasons a long time ago which is now still stable when done correctly. Also gave the ability for certain polygons to be more affected by gravity as well as setting the strength of gravity in the config menu. Gonna add a couple more features and change the read me then ship again.
Worked on the GUI. Separated the GUI code from the rendering code to clean up and organize a bit. Made it so that input is ignored if you are hovering over a GUI element so that you can input data without having unwanted things occurring in the background. Added a menu selector so that you can choose what menu's you want to be shown and which you want to be hidden. Added a new menu for editing the properties of spawned bodies so that you can spawn whatever body you want. Next I will make it possible to edit existing polygons and create springs using in app input. After that I will be adding anchors, and ball and socket joints then updating the read me creating a build system. Creating a new release and shipping.
Managed to get egui working with wgpu. Put some simple widgets for camera controls and such just to test things out. It took a while to set things up because I couldn't find much documentation for how to use wgpu with egui and everything I could find was years old and didn't apply anymore. Eventually I found an example program added a couple lines of code and everything worked. I want you to be able to modify everything in app so no code is needed. Here is a video of me playing around with some settings.
Finally finished implementing the new graphics API (wgpu). In the 1M circle test case it turned out to be 22.5% faster but performs about the same as the old API in most real physics scenarios since the bottleneck is always the doing all the computations for the physics. More importantly a lot more libraries support wgpu so it will be easier to find graphics API's which can work in the physics engine. Additionally it has much more functionality for compute shaders and other GPU stuff so I could make some GPU accelerated physics :). Here is the explosion example with the new graphics API (looks the exact same (as it should)).
Been working on the rendering system swap. Managed to get the camera uniform working as well as drawing polygons. Will try to finish the swap by the end of today.
Added partitioning to the collision resolution code so that we only check if two rigid bodies are colliding if they are sufficiently close to one another. I also optimized the code for extracting the vertices and indices from the rigid bodies for rendering. Overall these two optimizations together increased the speed of the explosion example by ~~6x which is from the collision resolution optimization and a different test case for rendering bench marking was increased by ~~40%. Here is the video of the explosion example now with ~200fps (previously 30fps)
Started porting the rendering system from miniquad to wgpu since wgpu is a faster, more versatile, better supported, but harder to use platform than miniquad. Using wgpu will give me a lot more options in the future and I will likely wanna swap to it eventually so might as well do it now. It seems like the port shouldn't be all too difficult but we will see. Here is a screenshot from the test program I made to figure out how to use wgpu. Using wgpu also opens up the opportunity for a web based version of the physics engine.
Added some useful displays for fps, total kinetic energy, and whether the pointer is being used. Now if you hover over the UI then you will no longer spawn/delete polygons or move the camera as would happen if you did it off the UI.
Decided to add a new crate for a GUI I struggled to get it working for a bit /:, will probably just be working on the GUI for the next couple days. My goal is for you to be able to do basically anything using just the in app GUI basically removing the need to program to use the engine. I could even serialize/save the in game state and allow you to replay anything. This will also probably make development easier since I could create test cases more easily. I also worked on the roadmap for this project so now I know what I want to implement for my next release as well as what I want to do for future releases! I might update the read me to include the roadmap. Here video of GUI test and cool spring.
Cleaned up a ton of the code base so it is now much more navigable, did some optimizations in the rendering code as well as other sections, refactored and removed magic numbers, Changed the rigid body constructors to allow you to set mass, restitution and color on creation rather than afterwards cleaning up many parts of the code and making things easier for the future. Springs also now are attached to an index in the main rigid body array rather than having their own rigid bodies which allows for cleaner collision resolution code, more functionality for springs by allowing multiple springs to attach to one rigid body (as shown in the video), and also a performance improvement.
Fixed up some code to be more modular. Optimized said more modular code to fix performance regression. Springs now account for angular momentum, are affected by gravity, and can collide with other rigid bodies, I think I might change the springs to use a reference to a rigid body to allow multiple springs to attach to the same body which would also help with cleaning up the collision detection code which is pretty messy with separate rigid body and spring collision resolution.
Edited the newly added springs to use RK4 as the numerical integration method instead of the simple newton's which increased accuracy by many orders of magnitude allowing the simulation to simulate springs at a much lower frequency than what was previously required. Current goal is to get a working double pendulum going.
Added Windows compatibility since my OpenGL shaders were giving errors when compiling for windows and the method I used for scrolling on Linux and Windows didn't work the same and required scaling the scroll amount by 100x. Tinkered with the collision resolution code, and added support for simple springs. Next I will probably try and make springs collide with other objects and try to tinker with more complex spring layouts. Also added two new test scenes for stability when standing on an edge and spring oscillation
Added new line support to the terminal as well as scrolling the terminal upon reaching the bottom.
Spent a couple hours studying computer architecture to understand the code I was about to write. I decided to create a system for the Raspberry Pi 4b and run it using QEMU since I don't own a Raspberry Pi. I tried a couple different tutorials but the Raspberry Pi code wasn't working on QEMU and I didn't feel like swapping to a generic aarch64 processor so decided to switch to x86 since it is by far the most widely documented architecture. Wrote a similar program to the Raspberry Pi code from before and got Hello, Kernel World! printed to the terminal using VGA. Real time is longer than 4h stated above but hackatime wouldn't track me reading an operating system book.
Making an x86 32bit operating system.
Refactored the code base and added lib.rs and some examples. I also added extra configuration options so that you can create your own simulations without needing to edit the engine itself! In the video you can see the three examples I prepared. I will probably move onto a different project for now likely an operating system but I will come back to this project later and improve the collision detection and resolution as well as adding more things such as gravity using newton's formula, springs, magnets, electric motors, and more!
Reinstalled my entire system today and didn't have much time to work. I forgot to install Wakatime on my IDE so no time was tracked (oops). Worked on collisions and accuracy + clipping. Recreated the simulation where block collisions compute PI (3.14159...)
Functional angular and linear impulses for collision resolution. Still a couple bugs with the calculation of contact points. I will probably just switch to a different algorithm for that since this one seems to be hopeless.
Implemented code to find the collision point between two colliding polygons and tried to implement angular impulse but there seem to be some bugs that I will try and iron out tomorrow.
Didn't do much programming today just reading about physics. Mainly Inertia tensors and angular momentum, once I finished reading I implemented the function for calculating the inertia tensor of a polygon and went to add angular momentum to the collision response code but found out the calculation of angular impulse requires the collision point. Sadly SAT my current collision detection function doesn't give me this so tomorrow I will need to implement GJK + EPA instead.
Added impulse based collision resolution, wrote the ODE solver (RK4) used it to apply gravity to some cubes. Tomorrow I will probably refactor a little bit and try to add angular momentum.
Added broad phase collision detection. Where we do a very cheap check to see which shapes are close enough to collide and then do a more expensive check to see which ones are actually colliding between the ones who are. This is a 4x speed improvement vs checking all shapes.
Just wanted to get a little bit done today. Decided to implement collision resolution. I plan to implement the Ordinary differential equation (ODE) solver soon and actually simulate some physics. I have more time now since the semester is officially over so I'll start working on this project a lot more.
Not much programming today because I had an exam and have another one tomorrow. Fixed a memory leak and did some optimization.
Narrow phase collision detection optimisation. Now we do a simple circle collision check on every polygon and only do a more vigorous check using SAT if the sum of the radii is less than the distance between the centers improved performance ~25x
You can now have shapes of arbitrary side counts
Rotation!
Refactored the code base twice. Made it so polygons can be any color and you can now zoom in or out
Added Vec2 math functions, added collision detection using SAT, fixed a bug where I was creating new buffers without deleting old ones. Code base is becoming a bit of a mess so I will probably spend tomorrow cleaning it up a bit so its easier to make new features since right now I have to rewrite whole portions for new features.
Fixed camera movement to be smoother
Fixed square placement to work with camera movement
After hours of troubleshooting and going through non existent documentation I managed to refactor the code to allow for multiple polygons as well as adding polygons with the mouse button and moving the camera with the keyboard
Managed to render a triangle took a while but eventually figured it out using the demos of graphics library I am using (miniquad) as well as learnopengl.com
A hand rolled 2D real-time Physics engine written in Rust.
This was widely regarded as a great move by everyone.