Farseer.BMX - 2D Physics Engine Released

Community Forums/Showcase/Farseer.BMX - 2D Physics Engine Released

AlexO(Posted 2008) [#1]
**UPDATE** 11-4-08
Farseer Physics 2.0 Documentation
- the developers of Farseer Physics 2.0 has released some documentation on the engine, which is all still very applicable to Blitzmax for those wishing to know more about how the engine works and how to use it. Includes real-time silverlight demos!

**UPDATE** 10-14-08
- updated farseer code to include a fix that dealt with CollideWithGeometry() crashing.

***UPDATE****
- Added a farseer module to the download for those that wish to use Farseer Physics as a bmx module.


It's finally done! I've ported the whole Farseer Physics Engine from C# to Blitzmax.

Download: Farseer.BMX

Main demo video:Farseer Demos
Fluid Container Demo video: Farseer Fluid Container Demo

The zip file contains:
* A compiled version of the physics demo application with 4 new demos!
* Ready-to-compile source code for both the core physics engine and the demo application
* A ‘quickstart’ application that shows someone how to setup a basic physics scene with minimal code.
* a ‘quick start guide’ that pretty much is a walk through of the quick start application.
* a farseerModule.zip that allows you to use Farseer Physics as a bmx module. Just extract to your Blitzmax/mod/ folder!

Thanks to everyone in the previous thread for the feedback and data provided. It was useful in gauging the limits of the engine. As I work on my own game with it, the data will prove very useful in further optimizing the engine to be able to play on lower-spec machines.

While I haven't tested the engine on a Mac or Linux machine I don't see anything keeping it from being a cross-platform engine. I've kept to native Blitzmax commands, so any quirks on other OS's should be easily fixable I imagine.

I have more detailed info on the release of this engine on my blog for those interested.


Fluid Container demo.


Box stacking demo.

Enjoy.


EOF(Posted 2008) [#2]
Good work Alex. Good contribution. Is the fluid demo based on the Thames water (heehee)

BTW, Can you tell me what the music score is in the inital video here? .. http://www.youtube.com/watch?v=97S-PmEXLGw
It's a really nice piece


Wiebo(Posted 2008) [#3]
Really awesome. I saved it. Now I only need a game to use this in :)


Htbaa(Posted 2008) [#4]
I'll try to take a look at it soon. I can test it on Linux.

How does this engine compare the Chipmunk? Is it faster? It does look a bit easier to use than Chipmunk, but is it?

I haven't tried Chipmunk or Farseer but looking at the example code on your website and it looks pretty easy. The Chipmunk examples looked way more complex.


MrTAToad(Posted 2008) [#5]
Works fine on a Mac...

Very nice!


AlexO(Posted 2008) [#6]
Thanks all!

@Jim Brown
Haha, it could very well be based on it ;). The music is by Justin Durban and it's called 'Human Nature'.

@Wiebo
I'll be looking forward to that game :)

@Htbaa
That'd be great to know if it works on linux without a hitch. I haven't done any benchmarking on Farseer vs other Blitzmax 2D engines so I wouldn't really know. The only comparisons I did was the blitzmax version of Farseer vs the C# version. I can't say if it's faster than chipmunk but I do know it's 'fast enough' for most games.
The original author of Farseer intended for the engine to be very easy to use and I think he did a good job of accomplishing that. Most setup and usage can be done with just a few lines code, while more advanced things are still available they aren't required for you to get up and running.

@MrTAToad
Thanks for testing on a Mac, glad to see it working without any problems!


MrTAToad(Posted 2008) [#7]
I would try Linux now, but the purchasing of postal stamps awaits, so it will have to wait for an hour or two.

Can you use your own images, or is it limited to to the spheres, boxes and rectangles ?


BlitzSupport(Posted 2008) [#8]
Brilliant job, thanks very much, Alex.

MrTAToad, is yours a PowerPC Mac or Intel? If it's Intel then I'll dig out my PPC Mac (which currently hard to get at) and try it...


MrTAToad(Posted 2008) [#9]
Its Intel


pappavis(Posted 2008) [#10]
jaw-dropping, goodness!


MrTAToad(Posted 2008) [#11]
Its fine with Linux too.


Rck(Posted 2008) [#12]
gratz


Htbaa(Posted 2008) [#13]
Works fine under Linux here as well. Nice stuff, very impressive.

By the way, why isn't it a normal bmx module? I think that's more convenient, instead when you need to test or debug the module.


MrTAToad(Posted 2008) [#14]
So, is the physics system limited to just the internal shapes, or is it possible to use any image ?


AlexO(Posted 2008) [#15]
@MrTAToad
The physics system is in no way tied to a graphics system. The demo application just has a lot of support classes to help ease the visualization of the physics bodies by encapsulating the rendering and physics together. Also, when trying to render physics bodies with your own images keep in mind Farseer does all rotational calculations in radians. So a call to "GetRotation()" will return a radian value. There is a MathHelper class for easy transformation between the two (ToDegrees(), ToRadians(), etc) along with other useful functions.

@Htbaa
Glad to hear it works well on Linux and Mac. I'm pretty impressed with Blitzmax's ability to 'just work' on multiple platforms if you stay within the native set of commands :D. I'll have a bmx module out soon. Personally, I'm not using the physics engine as a module, as a lot of times I end up tweaking the innards of the engine to help make the 'game for fun' (ie platformer games rarely obey physics engines 100% if at all), so the physics engine ends up being modified for game-specific needs, which becomes inconvienent for development if it's a module. But that's just me. For those that wish to just keep the physics in 'vanilla' form, then I can see why they wish to have it as a module.


AlexO(Posted 2008) [#16]
@Htbaa

By the way, why isn't it a normal bmx module? I think that's more convenient, instead when you need to test or debug the module.



I just went back and moved things around to create a module version of Farseer.BMX for those that want it. You can get it here. It's the same download (has everything like before), just now includes a zip file that allows you to install a farseer physics module. Once installed you just do:
format_code('
SuperStrict
Import aco.farseerphysics
'Weeeee physics....!
')

...And you're ready to go. Let me know if the module acts up, as I've never created a module before but it seemed to compile and register fine on my end.

Enjoy.


xlsior(Posted 2008) [#17]
It does appear that the example files in the module version are not currently set up to actually import the module itself -- none of the the examples appear to run out of the box.


Digital Anime(Posted 2008) [#18]
This looks really great, gonna test it this week.. :-)

What I'm more interested in is what is the license when you want to sell a game with ths engine, any idea?


MrTAToad(Posted 2008) [#19]
Oh, and it does work on an Asus EEE PC - unfortunately, with some of the demos you'll get a FPS of around 1 or 2 :)


AlexO(Posted 2008) [#20]
@xslior

It does appear that the example files in the module version are not currently set up to actually import the module itself -- none of the the examples appear to run out of the box.



To compile the examples, from the read me file:
there is an example folder inside the farseerphysics.mod folder. Simply open the Main.bmx file in a blitzmax IDE and
compile it to get the demo application up and running.

The demo's will not run independently as there is a central app that compiles all of them, since several of them share assets and code.

@Digital Anime
I don't believe licensing will be an issue. I intend to use it for a commercial game also. The license is included in the download. The license is an Ms-Pl 1.1 license, which seems pretty sparse to begin with.

@MrTAToad
That's great to hear! Which demos did you get 1 to 2 fps? Was it the more 'stress-test' type demos like demo 4 and 8?


MrTAToad(Posted 2008) [#21]
Its the one with the stacks of cubes. Keep the physics limited and it'll run at a decent speed...


slenkar(Posted 2008) [#22]
thanks alex,

p.s. where are Tgeomfactory and Tbodyfactory?


AlexO(Posted 2008) [#23]
@Jeremy Paxman
Glad you like it.
The factories are in the same folders for their respective 'type' (ie whereever geom, body, controller, and joint type file is):
1. TGeomFactory is in src/Collision/GeomFactory.bmx
2. TBodyfactory is in src/Dynamics/BodyFactory.bmx


slenkar(Posted 2008) [#24]
thanks


Ziltch(Posted 2008) [#25]
Well Done !

A Great demo as well.

Thanks for sharing your work.


Armitage 1982(Posted 2008) [#26]
Great work really !
I have a small question though.

Does anybody knows if a full blitzmax coded physics engine like this one is ok to handle large amount (let say 1000) of bodies with a game logic and rendering system on top of it ?

I know that BlitzMax is natively slower than C#/C++ in this particular case.


MGE(Posted 2008) [#27]
Works...but........ oh ....so ......slow on my dev box. (2.9ghz Celeron)


AlexO(Posted 2008) [#28]
@Armitage1982

Does anybody knows if a full blitzmax coded physics engine like this one is ok to handle large amount (let say 1000) of bodies with a game logic and rendering system on top of it ?

I know that BlitzMax is natively slower than C#/C++ in this particular case.



1000 fully interactive physics bodies at a decent framerate is no small task no matter your langauge (C#/C++/Blitzmax). If you're talking about having 1000 objects at the same time (with no culling or space partitioning) then, I doubt farseer will be able to handle it. But with a lot of clever organization of how objects are partitioned then it may be possible.

@JGOware

Works...but........ oh ....so ......slow on my dev box. (2.9ghz Celeron)



Are all the demos are slow or just few particular ones? Also, if a demo is running slow it'd be helpful to see if it's the rendering or the actual physics that the demo is choking on. If you press 'F1' a performance panel will show up telling you how many milliseconds the physics is taking up. If it's around 16 milliseconds then the physics aren't running 'slow' per say. The demo strives to hit 100 fps using fixed-timestep logic. Doing the math this gives you about 10 milliseconds per frame to do physics and rendering. So if physics are over 10 milliseconds you'll see a framerate hit. In a more realistic setting where you'd target 30 or 60 fps you'd have a time slice of 32ms or 16ms respectively.

I suspect if it's running very slow on your box, that the fixed-timestep code is always trying to 'catch' up and as a result leaves you further and further behind and therefore really slow framerate. The fixed-timestep logic isn't 100% bullet-proof.


Armitage 1982(Posted 2008) [#29]
Hi Alexo

You were right.
In fact my platform engine in Box2D work fine with 1024 "objects" because 512 of them were static one !

Those statics objects represent my level collisions and boundaries.

I successfully reduce them to 150 which allow me to put extra "dynamics" objects in my level and now I see a normal performance drop after 512 objects.

To fit my needs : 200 Statics objects and 300 Dynamics objects are more precise values.

So maybe Farseer could handle that without particular optimization ?

The big problem in comparison with Box2d is the documentation !
I can't find the API documentation at http://www.codeplex.com/FarseerPhysics
This give me problem to compare both engine.
(Switching originally from chipmunk to box2d wasn't very easy bud at this progress from Box2d to farseer won't be a small task too ^^)

Also do you know if Farseer is tuned for MKS units and what's the best size of objects ? (In Box2d it's roughly 0.1 and 10 meters to reach the best performance).

Thanks


Sauer(Posted 2008) [#30]
If only for B+... it looks so cool!


AlexO(Posted 2008) [#31]
@Armitage1982

To fit my needs : 200 Statics objects and 300 Dynamics objects are more precise values.


I can probably knock up a quick test this weekend to see if it's possible to do those types of numbers in farseer.bmx without further optimization.
As for the API documentation, this is a work in progress at the moment. The demo application source code that's included currently serves as an example for just about every feature in Farseer though. I'm not sure if Farseer is tuned for MKS units, that'd be a question for Jeff (C# author). Since Farseer is based off of box2D, it may be a possibility.


Rck(Posted 2008) [#32]
any results yet on that stress test?


AlexO(Posted 2008) [#33]
Been really busy as of late so haven't had time to do that yet. It's still on my to-do list though.


Gooneybird(Posted 2008) [#34]
Absolutly awsome port Alex! Thanks for your efforts on this, I hope many people take the oppertunity to check out this great engine.

-Gooney


Armitage 1982(Posted 2008) [#35]
Hi AlexO
How's your progress with Farseer ?
Have you find some more pros and cons to this engine ?


IPete2(Posted 2008) [#36]
Alex()

sheer beauty dude - sheer beauty in action!

Fantastic wrk.

IPete2.


Raz(Posted 2008) [#37]
Hey, looks like a fun module :)

However I'm having problems, I've compiled it. Blide is aware of it to some extend but something's not quite right...

Global physics:TPhysicsSimulator
Global viewer:TPhysicsSimulatorView

It recognises TPhysicsSimulator but not TPhysicsSimulatorView, erm... what's with that? :o

Edit: Naturally, I've just had a closer looks and seen it's not part of the module itself ;)


AlexO(Posted 2008) [#38]
Thanks for the comments!

And yes, TPhysicsSimulatorView I kept out of the module as it was more like 'supporting' code used for debug purposes and the demo application. It's not the first time someone's come across that. I may consider updating the module to include it, for users to quickly see things on screen...


Raz(Posted 2008) [#39]
AlexO: I've not had a chance to look at the code, but I see you have a shape drawing demo too. Does that work as an array of x,y co-ordinates to create a polygon?


AlexO(Posted 2008) [#40]
Yes Raz, the arbitrary polygon collision demo uses some helper functions in TDrawingHelper. One of them is 'CreatePolygonTexture' which takes in an array (or TList, can't remember off the top of my head) of Vector2's (x,y, coordinates), and generates an image out of them.


Head(Posted 2008) [#41]
I try to make a little Pong game, but don't understand anything lol..

How to set/limit the speed of a ball? How to position the paddle at mouseposition?

I need just a small little demo....

Sorry for the "command tone".. my english writing is very bad :D


Sledge(Posted 2008) [#42]
This looks great and makes me want to drop everything and write a pool sim. No, pinball! No, pool! etc


Raz(Posted 2008) [#43]
Awesome, thanks for the info Alex, can't wait to start mucking around with this :D


Raz(Posted 2008) [#44]
Edit: Hmm, yeah ignore me, I was being an idiot ;)


AlexO(Posted 2008) [#45]

I try to make a little Pong game, but don't understand anything lol..
How to set/limit the speed of a ball? How to position the paddle at mouseposition?

I need just a small little demo....



You may want to try looking at the quick start guide that is included in the module and also on my website. It goes over the basic functionality of the physics bodies such as setting the position and such.

As for setting the speed of the ball. You may want to look at using the 'ApplyForce(vec:Vector2)' method for the TBody Type. This is the recommended way for moving objects in the physics engine.


Pineapple(Posted 2008) [#46]
Some code examples to look at that differ a bit from the demos would be good, because there's no different styles of code to compare, which is how I usually learn stuff like this.. look at several examples, spot their differences, and see what those differences cause. This would greatly speed up the learning process for people like me.


I love the physics engine, and I have an idea for a game with it, so hopefully I'll get it done.


BlitzSupport(Posted 2016) [#47]
For anyone who discovers it's no longer available online...

http://www.hi-toro.com/blitz/farseer10.zip

Anyone have a later version than 1.0? It looks like the updates went up to 4th November 2008, while this version is dated 31st May 2008. This version doesn't include the module, just the import version.


Hardcoal(Posted 2016) [#48]
which is better/faster

box2d or farseer?

All I know of box 2D is that it got on my nerves.. one time.