Offsets

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
kylawl
Posts: 11
Joined: Thu May 22, 2008 6:11 pm

Offsets

Post by kylawl »

So I'm trying to add some physics bodies trying to offset them. I've tried both the geometric center as well as COM offset. Neither of which seem to do anything. I've also tried adding a bunch of objects to a compound object fallowing the demo samples. All this stuff doesn't seem to work I'm not sure what exactly Is going on, is there a specific order things need to be done in? I'm using 0.6.1.

Any suggestions would be appreciated.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Offsets

Post by Norbo »

I'm not sure exactly what you're trying to do; are you just trying to modify the position of the center of mass relative to the geometric center? If so, the centerOfMassOffset should be doing what you want.

There does seem to be a problem right now with the offset which causes contact caching to behave poorly when the center of mass is offset, though. I'll probably be releasing v0.6.2 to address this since it is pretty serious.
kylawl
Posts: 11
Joined: Thu May 22, 2008 6:11 pm

Re: Offsets

Post by kylawl »

Yes that is what I'm trying to do but using that centerOfMassOffset does not seem to work. I also tried just setting the position of the object then adding it to a compound object but that does not seem to offset it either.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Offsets

Post by Norbo »

When you set centerOfMassOffset to something, nothing at all changes? The object itself won't move, but it will behave differently- is it still acting like a perfectly normal object?

Adding an object to a CompoundBody should cause all involved bodies to rotate around the common center of mass; what is happening in your case exactly? Or are you adding a single entity to a compound body? If there is only a single entity, the compound body will center itself on that entity's center (the compound's common center of mass) unless you modify the centerOfMassOffset.

Do you have some sample code showing the problem?
kylawl
Posts: 11
Joined: Thu May 22, 2008 6:11 pm

Re: Offsets

Post by kylawl »

LOL so i think found the problem tell me if this sounds correct. It I was getting the center position of the object, not the center of mass so applying the offset was not actually doing much. What I'm trying to do here is have a model and associate some physics with it, copy the position of the physics entity onto my model. I want the pivots to be aligned but the actual collision shape to be around the mesh. centerOfMassOffset seems to be the answer?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Offsets

Post by Norbo »

It sounds like the model you're using was built away from the origin. When the origin of the model is moved to the position of the entity, it is still offset. If this is your issue, translating the model so that is centered on the origin before moving it to the entity should fix the problem.

Modifying the center of mass simply changes the location around which an entity will rotate. Once your model and collision shape match, then the center of mass offset would become useful for tweaking the feel of the physics (different pivot and such).
kylawl
Posts: 11
Joined: Thu May 22, 2008 6:11 pm

Re: Offsets

Post by kylawl »

So the models pivot is at the origin.. Lets use the rocket ship i've got as an example I want to pivot to be centered on the horizontal axis' but at the minumum on the height. This way when i place the object on the ground its on the ground.. but I need the centerofmass and the collision object to not be at the pivot location.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Offsets

Post by Norbo »

The model can be aligned with the collision shape without any modification of the entity's center of mass, preserving its normal rotational behavior. To place an entity on the ground instead of halfway sunk into the ground, you just need to add half the object's height to the position.

For example, if the model's origin is placed at the base of the rocket ship rather than at somewhere like the center of mass, you would need to translate the model down before transforming it to the rocket ship's physical representation's position and orientation.

If the rocket's model was from (0,0,0) to (0,4,0) in height (with the apparent center position of the model being at (0,2,0)) and you wanted to align it with the entity, you would first create an initial transformation that translates the model down:

Code: Select all

baseWorldMatrix = Matrix.CreateTranslation(new Vector3(0,-2f, 0));
Then later, during the draw method, you would draw the model with a world matrix of:

Code: Select all

worldMatrixToUse = baseWorldMatrix * entity.orientationMatrix * Matrix.CreateTranslation(entity.centerPosition);
This would draw the model in alignment with the geometry of the entity.

I'm not sure if I'm actually addressing your problem though; if this isn't helpful, a picture or diagram might help me understand better.
kylawl
Posts: 11
Joined: Thu May 22, 2008 6:11 pm

Re: Offsets

Post by kylawl »

I see. thanks
kyle
Post Reply