Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Simple Fast SFML Physics  (Read 8491 times)

0 Members and 1 Guest are viewing this topic.

profk

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Simple Fast SFML Physics
« 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.
« Last Edit: April 26, 2022, 07:19:47 pm by profk »

profk

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Simple Fast SFML Physics
« Reply #1 on: April 29, 2022, 09:50:38 pm »
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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11042
    • View Profile
    • development blog
    • Email
Re: Simple Fast SFML Physics
« Reply #2 on: April 30, 2022, 11:06:14 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

profk

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Simple Fast SFML Physics
« Reply #3 on: May 02, 2022, 02:34:54 am »
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.

profk

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Simple Fast SFML Physics
« Reply #4 on: May 03, 2022, 01:10:17 am »
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.

nogoodname

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Simple Fast SFML Physics
« Reply #5 on: June 30, 2022, 07:19:18 pm »
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.

Code: [Select]

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.

BreadMonika

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Simple Fast SFML Physics
« Reply #6 on: July 01, 2023, 09:44:50 pm »
Hi, I wanted to know, what's the license for this library, is it zlib?

 

anything