Page 1 of 1
Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 2:48 pm
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:
The box's CentrePosition returns (0, 0, 0)?!
What is going on here?
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 3:55 pm
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

Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 7:30 pm
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.
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 7:33 pm
by Norbo
The Internal-prefixed equivalents like InternalCenterPosition do not buffer reads or writes.
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 7:58 pm
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:
as all the entities claim to have their CenterPositions at (0,0,0)?!
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 8:34 pm
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.
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 8:48 pm
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.
Re: Why is box position resetting to (0, 0, 0) on space update?
Posted: Tue Dec 14, 2010 9:40 pm
by Spankenstein
Thank you for taking the time explain that. All working as it should now
