SFML community forums
General => SFML projects => Topic started by: profk on April 26, 2022, 07:17:33 pm
-
I have written a VERY simple physics library that is designed to be used with SFML. At its highest level it has pre-integrated physics shape classes. The API is designed to be easy and mimics the SFML pointerless API approach.
Right now it ONLY handles AABBs and circular bounds and that is all I expect to add to it myself. It has "PhysicsShape" classes right now for RectangleShape and CircleShape. I do intend to add similar wrappers for the other SFML shape classes soon.
There is NO documentation yet, sorry, I'll get to it when the examples and features are done. There is however a working breakout example.
The library is available on github as https://github.com/profK/SFPhysics and as a nuget package at https://www.nuget.org/packages/SFPhysics/
The breakout example is also in github at https://github.com/profK/Breakout2
The actual code for collision detection and response is heavily borrowed from:
https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331
I should note that, although individual collision resolutions are very fast, it over-all scales at O(n^2). Optimizations are on the dev list.
-
Usable version now up at:
https://github.com/profK/SFPhysics/blob/master/README.md
Sample pointer-less game written using it and SFML at
https://github.com/profK/Breakout2
-
Sounds quite interesting! :)
Since it's a library, I think a simple code usage example in the ReadMe would help quite a bit to get a grasp of how the library works, without delving into the examples.
-
Good idea. Ill add that as a part of the documentation pass.
Its at version 1.1.5 and the existing API should now be stable. I didn't like the way the highest level was architected so I refactored. It means a tiny bit more complexity exposed at the SFML Physics shapes level as they are now wrappers of an SFML drawable and a PhysicsBody, but the result is MUCH cleaner code-wise.
-
Okay first release is ready I believe.
I implemented the movement based collision pruner. It works in my examples, but though if it causes you probmes you can disable it with world.setIgnoreMovement(true).
I have added a "Hello Physics" example of a circle bouncing off the floor as per suggestion (thank you). I have also started the documentation wiki with a page explaining the design of the library.
-
There's one thing you should never do when making a C++ library, and that is putting "using namespace std;" globally in a public header.
The reason is that a you're forcing "using namespace std;" to anyone who uses your library, and lot of people don't like having "using namespace std;" in their code.
So be considerate to your users and don't force that on them.
Fortunately there's a quick and dirty way to alleviate this issue, and that is to simply put the using directives inside your namespace.
namespace sfp {
//This is now inside your namespace sfp
using namespace std;
using namespace sf;
This isn't ideal (personally I wouldn't put using directives in headers files) but it is a minimum standard that is really quick to achieve.
-
Hi, I wanted to know, what's the license for this library, is it zlib?