### Author Topic: Isaac - Very simple physics engine  (Read 8177 times)

0 Members and 1 Guest are viewing this topic.

#### Lo-X

• Hero Member
• Posts: 618
##### Isaac - Very simple physics engine
« 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::RectangleShapecube.addFixture("base",f1); // There is a key string, I think about removing it// Applies forcesregistry.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.
« Last Edit: April 29, 2012, 11:28:23 pm by Lo-X »

#### mateandmetal

• Full Member
• Posts: 171
• The bird is the word
##### Re: Isaac - Very simple physics engine
« Reply #1 on: April 30, 2012, 12:48:12 am »
Nice project!
- My first (and free) game: BichingISH!

#### StormWingDelta

• Sr. Member
• Posts: 365
##### Re: Isaac - Very simple physics engine
« Reply #2 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.
I have many ideas but need the help of others to find way to make use of them.

#### Lo-X

• Hero Member
• Posts: 618
##### Re: Isaac - Very simple physics engine
« Reply #3 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.

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

#### N1ghtly

• Jr. Member
• Posts: 96
##### Re: Isaac - Very simple physics engine
« Reply #4 on: May 02, 2012, 09:56:02 pm »
This can become very useful!
I'll keep following this