SFML community forums

General => SFML projects => Topic started by: Lo-X on April 29, 2012, 11:24:54 pm

Title: Isaac - Very simple physics engine
Post by: Lo-X on April 29, 2012, 11:24:54 pm
Hi,

I'm actually developing a re-usable Game Engine for my platform game and I needed to handle some basic physics. I first decided to use Box2D but there was too many things for me and it was difficult to integrate it with my engine. So I bought a vey good book on making basics 3D Physics engines. Some things were complicated or useless in 2D so I used it as a base for doing my own engine, easy to integrate with my SFML Game engine.

I don't pretend to re-invent the wheel, tis is a veeerrrryyyyy basic engine that can handle the minimum :
- Implement Rigid Bodies with sf::Shape fixtures
- Generate forces on Bodies with the possibility for user to implement non-trivial Forces Generator : (Gravity and Draw forces generator already implemented)
- Integrate (linear) Forces, Velocity and Acceleration on bodies
- Handle collision between Bodies (if they have Convex Shapes) using Separating Axis Theorem
- Very (very very) simple rotations angular velocities/accelerations (the result isn't very convincing)


Example of code :

Code: [Select]
// A Register of global forces to apply. Will be included in a "Physic" or "World" general class :
isaac::ForceRegistry registry;
// A gravity generator :
isaac::GravityGenerator gravity(isaac::Vector2(0.f, 150.f));

// Add a body
isaac::Body cube;
cube.setPosition(300, 320);
cube.setMass(500);
    // Fixtures
        isaac::Fixture f1;
        f1.RelativePosition = isaac::Vector2(0,0);
        f1.Shape = &cubeShape; // Just a sf::RectangleShape
cube.addFixture("base",f1); // There is a key string, I think about removing it

// Applies forces
registry.add(&cube, &gravity);

// Main loop :
sf::Clock clock;
float timestep = 0.f;
while(1)
{
     // Events...
     registry.updateForces(timestep);
     cube.intergrate(timestep);

     // Draw, using the shape or a body method to get all fixtures
}



Here a short video :

http://www.dailymotion.com/video/xqh60v_isaac-simple-physics-engine_videogames



There are a few bugs, I haven't documented every functions, so ATM I can't provide anything.
Title: Re: Isaac - Very simple physics engine
Post by: mateandmetal on April 30, 2012, 12:48:12 am
Nice project! 8)
Title: Re: Isaac - Very simple physics engine
Post by: StormWingDelta on April 30, 2012, 05:21:41 pm
Looks like it could be helpful.  Can't see much though due to being at school at the moment.  Surprising no one has done a physics tutorial yet, for 2D at least.  :o
Title: Re: Isaac - Very simple physics engine
Post by: Lo-X on April 30, 2012, 06:54:18 pm
Looks like it could be helpful.  Can't see much though due to being at school at the moment.  Surprising no one has done a physics tutorial yet, for 2D at least.  :o

I've a blog (in french, sorry) where I'll discribe a little how I did. I perhaps will translate or re-write som tuts in english if asked
Title: Re: Isaac - Very simple physics engine
Post by: N1ghtly on May 02, 2012, 09:56:02 pm
This can become very useful!
I'll keep following this :)