Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Aug 05, 2012 5:49 pm 
Offline

Joined: Sun Aug 05, 2012 5:05 pm
Posts: 3
I am developing an electromechanical simulation application using C# and BulletSharp.
I have a class "MySimClass" which has, amongst other things, a RigidBody property and a CollisionShape property like this:
MySimObject.RigidBody (this is a BulletSharp RigidBody)
MySimObject.CollisionShape (this is a Bulletsharp CollisionShape)

After a DynamicsWorld.StepSimulation() I will iterate through the contact manifolds to get the ManifoldPoints, and from the ManifoldPoints I get things like AppliedImpulse, LocalPoint..., PositionWorldOn... etc. These values will then be used by the MySimObjects to which the colliding RigidBodies belong. From what I understand, the only way I can get a reference from a RigidBody to the MySimObject to which the RigidBody belongs is by putting a referens to the MySimClass into the UserObject of the RigidBody, like this:
MySimObject.RigidBody.UserObject = MySimObject;

and to get the reference from the RigidBody I do a cast like this:
mySimObject = (MySimClass)RigidBody.UserObject;

If this is the way to do it, I would think the casting affects the performance in a negative way. Is this performance loss not significant enough to be bothered about? If it is, is there a better way to get a reference from a RigidBody to the "owning" MySimObject?

If this is the way and the performance gets noticeably affected, I would like to suggest "typed" versions of the classes in BulletSharp containing UserObject members, so there would be for example a RigidBody<T> class and a CollisionObject<T> class.



Bullet and BulletSharp are indeed impressive projects, and I'm very glad to see the steady development.

Regards
///JmD


Top
 Profile  
 
PostPosted: Mon Aug 06, 2012 11:23 pm 
Offline

Joined: Wed Feb 24, 2010 9:49 pm
Posts: 26
All the cast really does is that it checks that UserObject is of type MySimClass and then copies the reference, so I doubt that this will be a bottleneck.

A performance hit might occur if the types on both sides were not the same and type conversion had to be done. For example, if MySimClass had a base class MySimBase and we tried to cast the same object like this:
MySimBase mySimObject = (MySimBase)RigidBody.UserObject;
then it would have to climb the inheritance tree to check that the cast was valid.

Generics would get rid of the type check, but it's a small gain and would be confusing to those that don't use the UserObject.

Storing the reference in UserObject should be fine. Another way I can think of would be to use a Dictionary of <RigidBody, MySimClass> pairs.

I'd recommend running a profiler such as SlimTune (http://code.google.com/p/slimtune/) to see where most of the time is spent.


Top
 Profile  
 
PostPosted: Tue Aug 07, 2012 10:03 am 
Offline

Joined: Sun Aug 05, 2012 5:05 pm
Posts: 3
Thank you for the thorough answer. Profiling will definitely be one of the things where time will be spent on this project, so thank you also for suggesting SlimTune.

///JmD


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group