Why is box position resetting to (0, 0, 0) on space update?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Why is box position resetting to (0, 0, 0) on space update?

Post by Spankenstein »

I create a box

Code: Select all

            Box box = new Box(new Vector3(0, 10, 0), 1, 1, 1, 1);
            space.Add(box);
and its CentrePosition returns (0, 10, 0).

Now if I update the physics space:

Code: Select all

space.Update(gameTime);
The box's CentrePosition returns (0, 0, 0)?!

What is going on here?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Norbo »

CenterPosition is a buffered property if it's in the space, but equivalent to an Internal-prefixed property if it does not belong to a space. However, after the space.Update, the CenterPosition should show the correct result since the read buffers have been updated. Is the object forced asleep somehow before that can happen?

I'll be glad to see this sort of issue disappear when v0.15.0 comes out and 'hides' the buffered stuff :)
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Spankenstein »

What property should I use to avoid this from happening? The object is not being forced to sleep, all the code is as posted.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Norbo »

The Internal-prefixed equivalents like InternalCenterPosition do not buffer reads or writes.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Spankenstein »

The problem is that if I use one of the methods for finding entities within a certain bounding sphere:

Code: Select all

            sphereOfInfluence.Center = entity.InternalCenterPosition;
            List<Entity> entities = Resources.GetEntityList();
            space.BroadPhase.GetEntities(sphereOfInfluence, entities);
the GetEntities method appears to use the buffered CenterPosition for each object and therefore returns incorrect results after:

Code: Select all

space.Update(gameTime)
as all the entities claim to have their CenterPositions at (0,0,0)?!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Norbo »

The BroadPhase and GetEntities are based on the bounding boxes of entities, which are in turn based on the internal values, not buffered values.

Buffered properties should represent the most recent internal values after a space update. If they do not match what you expect of the internal values, then shenanigans are afoot. In that case, I'd recommend watching carefully the InternalCenterPosition and CenterPosition at various points in the code (before move, after move, before update, after update) to see exactly what happens when.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Norbo »

By the way, if you don't care about the interpolated/buffered values, you can just ignore the buffered properties like CenterPosition completely. In v0.15.0, the Entity will not expose the buffered properties directly, in favor of accessing them through a "BufferedStates" property to clarify their purpose. The remaining state properties will be the equivalent of the current Internal-prefixed properties, but with simple names like "Position" and such.

Buffered properties only really come in handy when updating the engine asynchronously, and interpolated values are just there to help smooth out graphics.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Why is box position resetting to (0, 0, 0) on space update?

Post by Spankenstein »

Thank you for taking the time explain that. All working as it should now :)
Post Reply