PDA

View Full Version : Physics engine v.s Scene graph



chronozphere
28-10-2010, 08:17 PM
Hey everybody,

I have a question about how to combine a scenegraph with a physics engine.

A scene-graph usually consist of a hierarchy of entities. Child-entities inherit their transformation from their parents. So typically each entity has a world-transform and a local-transform which is relative to it's parent.

The physics engine will do the physics computations for a number of scene entities (if not all). It's output consist of matrices for all simulated entities (and additional parameters such as speed, torque etc)..

Making the two cooperate gives me the following problem:

The physics simulation runs in world-space and thus gives me world-matrices for my entities. However, I would prefer local matrices instead, because I normally compute my world matrix from my local matrix and not the other way around.
Making both the world- and the local transform "settable", will be cumbersome because I don't know which information is up-to-date.
After setting one of them, I could update the other one, but that will become very expensive.

This made me realize that the physics engine does not know about the parent-child relations between entities in my scene graph. I honestly don't know how to combine the two without alot of overhead or messy code.

I would like to keep the two separated. However, I still have to deal with the transformations and the local/world space problem.

Can anybody show me some good ways to tackle this issue?

Thanks!

P.S: Also asked this on gamedev.net: here (http://www.gamedev.net/community/forums/topic.asp?topic_id=586221)

Mirage
29-10-2010, 04:40 PM
In my engine physics affects bodies regardless of scene graph hierarchy. There is no much sense to use physics for a child body which is hardly attached to its parent. And there always are joints for that kind of things.

About local transforms vs world transforms -- using physics you can forget about local transformations. Not a big problem I think.

But you still can use scene hierarchy to organise entities. To do that your scene graph should support entities without transforms at all and/or disregard transform hierarchy for items which physics applies to.

chronozphere
29-10-2010, 04:45 PM
Thanks for your reply. :)

The thread at gamedev.net is getting quite interesting. Someone mentioned this article (http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Scene%20Graphs%20-%20just%20say%20no]]) about why you shouldn't use scene-graphs. That really convinced me. I will redesign my engine and split it up into different modules each having a kind of entity (f.e PhysicsEntity, RenderEntity, AnimationEntity etc).