Game Development Community

[CLOSED] - Farseer Phsyics Integration - Any pointers?

by Ron Barbosa · in Torque X 2D · 07/29/2010 (12:51 pm) · 234 replies

Hey all...I've just recently started looking at some demos and videos for Farseer Physics.

I was curious if anyone here had done or is considering a Farseer integration with TorqueX. If so, how's it going for you?

I am admittedly ignorant in the use of the physics engine, so I have no idea where to begin...but I'm just curious if folks are even trying this and whether or not it integrates fairly simply or if it will detract too much attention from my game build.

I don't want to take a 2-month detour from my game project just to integrate the physics. My game project is going to be a value proposition. I want to sell it cheap and see if I can push volume...so if it doesn't have a proper physics implementation, or uses only the TX physics...that's ok. But if I can spend a couple of weeks or a month on the Farseer integration...that might help push sales volume.

Thanks!
--RB
#121
08/27/2010 (10:57 pm)
@Pino/Ron:I downloaded the SVN updates and ran the Gravity value test, it works! Many thanks Pino!

Here is another "Bug" I have:
With the T2D physics I was able to change InverseMass to a negative value and the sceneObject would reverse its gravity, I could use it on triggers to simulate a magnetic field, and many other uses. However, with farseer when I change the body Mass to a negative value it just floats in place.

Example: A scene with a brick and balloon.
The brick body Mass = 30 and the balloon body Mass = -30
#122
08/28/2010 (12:10 am)
What version of Farseer are you using for the port?
#123
08/28/2010 (2:41 am)
@Jason Fox...the Farseer integration is based on 2.1.3 (the latest stable release).

@All...my replacement motherboard came in and fixed the problem. I just installed Win 7 Pro 64 bit, and I'm in the process of getting my build environments loaded up.

Next I'll have to get subversion restored both for my local repositories and the online Torque X repo.

Hopefully, I'll be contributing again by the beginning of next week.

Enjoy...
--RB
#124
08/28/2010 (3:36 am)
@Pino...I just got Flash Player installed on my new PC...awesome videos!
#125
08/28/2010 (4:10 am)
Ok...I'm going to go off topic for a minute here.

To the folks running Windows 7...is there a Visual Studio 2008 option with .Net FrmWrk 3.5 and XNA 3.1?

Or am I going to be forced into .Net 4, XNA 4, and VS2010? I'm not really interested in a development platform upgrade at the moment.

I tried to install the .Net 3.5 Framework, and it just flashes on my screen for a split second and aborts.

Any help would be appreciated...feel free to email me directly at the address in my profile.

Thanks
--RB
#126
08/28/2010 (4:22 am)
Ron, Windows 7 comes with 3.5 SP1 installed. All you need is VS 2008 SP1 and XNA 3.1.

Also, you might take note that Farseer just released version 3.0 last week, in case you wanted to update the library.

farseerphysics.codeplex.com/wikipage?title=Videos&referringTitle=Home
#127
08/28/2010 (4:24 am)
@Jason Fox...thanks for the info. I will try to update the library once I've got my build environment back up and running.

--RB
#128
08/28/2010 (5:51 am)
[RESOLVED - DISREGARD THIS POST]

Hmmmm...things are not looking so hot for VS2008. The installs repeatedly fail early on (both for VC++ and VC#). It indicates C++ Runtime prerequisites could not be downloaded.

So I installed VS2010 (both C++ and C#) thinking I'd be able to run those with XNA Game Studio 3.1, but this is not the case. XNA Game Studio 3.1 will only run on VS2008.

I've read in the forums that if you had VS2008 running on Vista and then upgraded to Windows 7 you'd be ok, but if you try to install them directly in windows 7, you get what I'm getting now.

Can anyone confirm that they were able to successfully run the INSTALLER in Windows 7?

At this point, I'm not sure what else to try.

Thanks
--RB
#129
08/28/2010 (10:14 am)
Quote:Here is another "Bug" I have:
With the T2D physics I was able to change InverseMass to a negative value and the sceneObject would reverse its gravity, I could use it on triggers to simulate a magnetic field, and many other uses. However, with farseer when I change the body Mass to a negative value it just floats in place.

Example: A scene with a brick and balloon.
The brick body Mass = 30 and the balloon body Mass = -30

Ehmm...actually that's a bug in Torque physics :) The inverse mass (by its definition) is computed as 1/mass so it cannot be negative because the mass can't be less than Epsilon.

That's for actual physics. In conceptual physics we allow the mass to be zero or even negative, but it's not real physics so I guess that Farseer's authors disregarded that principle also because in an actual physics simulator you can't just change the sign, you have to properly apply the conceptual world physics which is not that simple. In real physics simulation a magnetic field has to alter the gravitational field to have an altered force vector applied to it's target.

That said, I'll try to see what happens hacking Farseer's source to allow negative mass and if there are no unwanted effects I guess I'll get rid of that constraint to allow the "Torque X approach" to be mantained ;)
#130
08/28/2010 (10:41 am)
Well,

I tried to allow negative mass, but (as I expected) it breaks the simulation and before to break it it doesn't give the expected result. I guess that what you need is a more realistic approach to magnetic fields ;)
#131
08/28/2010 (10:52 am)
Update about magnetic fields.

I've being digging this a little and found that Farseer has a controller that can be used to simulate this, a gravity controller written for space games to allow the simulation of Planetary Gravity in an open space, allowing more than one gravity generetors (via the ComplexFactory's method CreateGravityController).

This functionality is not yet implemented in this integration and is not documented in any existent Farseer sample so ... stay tuned ;)
#132
08/28/2010 (5:44 pm)
Hey guys,

as Ron is still building his new workstation I thought to add the Gravity Bodies right away to solve Aaron issue and give you some new thing to toy with :)

There is only one thing that has to be considered a major change: a constraint has been added to the FSPhysicsManagerComponent to have its SceneObject automatically named “FSManager” during its registration so to allow a deterministic way to find the FS manager in the scene during FS components’ registration, so if you named that scene object know that it will change its name at runtime.

The new component allowing Gravity Bodies is FSPointOfGravityComponent so just add it to a FS body and have fun with this :)

This short video documents this new piece of integration:

#133
08/28/2010 (7:55 pm)
@Pino...the gravity bodies are awesome...thanks for taking the time to do this. I am curious, did you use the Farseer Planetary Gravity controller for this? I've not used it before (or any controllers for that matter).

I'll sync my checkout and see what the implementation is like.

As for forcing the name of the FSPhysicsManagerComponent's body...this should not pose any problems, as only 1 scene object should have be registered with this component at any time.

As for me...I have all my build tools back online, so I should be able to reconvene my contributions here. I will take a moment to run a local upgrade to Farseer 3.0 and see if everything still works.

I do not know what changes are included in 3.0, but since this is a relatively new integration, it's probably best not to bind it to an older revision of the library.

So I'm about 95% of my way back to having a fully functional game development platform...my build environments are up, but I still need to install my artwork tools.

So close!
--RB
#134
08/28/2010 (8:18 pm)
Don't hold me to this yet...but near as I can tell...all of the "Springs" have been removed from Farseer Physics 3.0.

There are a few new joints...but there is no spring factory...and I haven't found any spring class yet.

I migration to 3.0 is going to require a revisit to the beginning...starting again with the simplest versions of the joints.

I'm not sure that there was much care given to an "upgrade path" when 3.0 was planned and written.

Still investigating...
--RB

[UPDATE] - We're not in Kansas anymore. Wow! The changes are pretty huge. There's no PhysicsSimulator class any more. I believe it's been changed to the "World" class.

I'm going to try to contact the writer of Farseer and see if there's any upgrade coaching he can offer. It looks like (without the PhysicsSimulator class and the Spring classes) a large chunk of everything that's been done will not have much value. An update to 3.0 will almost be a rewrite.
#135
08/28/2010 (8:53 pm)
@Pino: FSPointOfGravityComponent works great!

@Ron: Thats odd that they would remove springs, it might be a while before the 3.0 manual comes out.
#136
08/28/2010 (9:00 pm)
@Ron: Yes, I did use Gravity Controller for that. I didn't see version 3.0 released! I've just quickly read the manual: looks that springs are not there anymore, it has been simplified incorporating the spring behaviours in the joints as properties... quite a nice idea actually.

I agree that we should move to this new release as this integration is just born ;)
#137
08/28/2010 (11:40 pm)
Hey guys,

before to leave it back to Ron (who's back on his new ws!) I thought to commit my experiment with exposing Farseer OnCollision delegate in the Geometry object. This allows you to manage the collisions just like you are used to do it in Torque X.

One thing to be aware of: here we work on a double layer of components, so when you search for the geometry component it can be found but it can be not initialized yet, so you have to double check that. My quick solution has been like this:

private void setupCollision()
{
    _geom = _sceneObject.Components.FindComponent<FSGeomComponent>();
    if (_geom != null)
    {
        if (_geom.FSGeom != null)
        {
            _geom.OnCollision = _onCollision;
            _geom.CollisionEnabled = true;
        }
        else
            // Sanity! this means that the geometry is not fully initialized
            _geom = null;
    }
}

This is called in my ProcessTick if _geom== null. I don't really like this solution but it's really late so I'll think about a better stuff tomorrow. In the meantime enjoy this version which is quite functional ;)

#138
08/29/2010 (12:15 am)
@Pino, thanks for the collision update! This will help me out a bunch.
Question: I have started to develop a game with the SVN and the Farseer integration. Do you think I will run into problems other then the springs when updated to Farseer 3.0? Should I wait?
#139
08/29/2010 (1:56 am)
@Pino...thanks so much for the help with the integration. Those were some really valuable contributions over a short period of time.

A question regarding the collisions, does the collision delegate fire on each clock cycle until the separation occurs, or does it only fire once when the objects first make contact?

It might be good for everyone here, myself included, to know how that works.

@Aaron...Pino and I had a brief email exchange regarding the update to 3.0. I think the short answer is, don't wait.

The changes in 3.0 are significant. I posted some of them a couple posts back...and as you mentioned earlier, the docs will probably be a long time coming. Since we've got our collective community heads wrapped around Farseer as we know it today, it will probably be more effective for us to continue using what we're familiar with, then to try to glean through code surfing, what new gains there are to be had through the upgrade.

My suspicion is that most of the changes are logistic in terms of code management. Class repacking, functional refactoring, reorganization of functionality, etc. I haven't read about too much in the way of very new features.

I'm going to continue watching FS3, and playing with it on my own workstation. When I find that it's sufficiently stable, and I have my arms around how it's organized, I'll revisit the upgrade.

For now we have something very useful...and we shouldn't be afraid to put it to work.

Enjoy!
--RB
#140
08/29/2010 (11:03 am)
@Aaron: As Ron said... go ahead :) when we'll switch to 3.0 It'll be done allowing a backward compatibility. Anyhow the 3.0 is quite different, more compact but also... too young if you know what I mean :) Leave it out there to grow solid while we use the consolidated version :)

@Ron: The collision delegate returns a boolean which is used in Farseer to clear the collirion list. Obviously at the next tick the collision will be raised again, but all the collisions points related to that geometry in the current tick are cleared if we return True.