Sign in to follow this  
irreversible

PhysX - translating the entire scene

Recommended Posts

irreversible    2862

First off, for a while I was fairly sure this is a precision issue, but at this point I think it might just be my poor use of the API (to which I'm very new).

 

In short, I have an unbounded scene for which I keep a fairly local set of collision data, which needs to be updated as the player moves through the world. I run my updates regularly every N units, which for testing purposes is something small (eg 512). Now, collision is working just fine, but every time the player crosses the update boundary, there's a chance that the character controller (CCT) will clip through geometry. In case this is confusing, here's an example: I keep a 5x5 node section of the world in memory, which is always relative to the upper left corner of the current "player frustum". As the player moves, say vertically, through the world and crosses a node boundary, the 5 bottom nodes go out of scope while 5 new ones need to be loaded at the top. Also, geometry in the rest of the nodes needs to be transformed to a new coordinate system. So relatively everything stays the same, but as the CCT crosses a node boundary, all geometry along with the player will need to be transformed back towards the origin by the size of one node.

 

A few things worthwhile of a mention:

 

- I have decoupled my player's position from the usual single precision coordinate vector and keep a PxExtendedVec3 duplicate that functions as the only read/write proxy for PhysX. I downcast this vector to single precision for my drawing code, but never the other way around

- I currently only have box geometry, which is always unit-aligned (eg my world correlates 1 unit to 1 pixel and all geometry is pixel-aligned), but is stored as single precision

- I'm using PxRigidDynamic::setGlobalPose() to update my geometry and PxController::setPosition() to transform the CCT at update boundaries. The former is single precision while the latter is double precision. This might be the root of my problems, although I doubt it, since all geometry that is single precision is unit-aligned and the more volatile position of the player is stored as double precision.

 

- I haven't looked into PhysX's collision code, but one thing I did notice while testing is some nudging that happens when the CCT keeps walking into a wall: even when touching a wall head on, it moves forward by ~0.1 units 8 times and then bounces back by -0.8 units. It does this over and over again, which initially introduced jitter into my drawing code. I ended up snapping the player to the closest full unit after every CCT update. Initially I assumed this had to do with the minDist argument to PxController::move(), but apparently it doesn't. Still, once again, this small intrusion might well be the root of the problem when suddenly the entire scene gets transformed.

 

Clipping happens ~10% of the time, but that's more than enough to clip the player as they wallhug across an update boundary a few times.

 

Now, I've read up on setGlobalPose() and the caveats it imposes, but nowhere does it imply that it would be unsafe to transform an entire static scene like this. I've also tried moving the CCT back by a short distance at update crossings and frankly according to my debug output the CCT isn't even close enough to the geometry to be subject to precision issues. But it still keeps clipping into it. So either I'm missing something or PhysX doesn't quite like what I'm doing.

 

I'd post some code, but frankly it's a bit messy, so I'd rather post snippets as needed.

 

Has anyone had experience with something like this or can suggest what I might be missing?

Share this post


Link to post
Share on other sites
cgrant    1827

How are you translating the scene ? What version are of PhysX are you using ?  v 3.3.3 added support for larger simulation environment by allow the scene origin to be moved ( don't know if this is what you are currently using. ) If you are using setGlobalPose in conjunction with this, then there are going to be anomalies as the new position position should be reference to the scene origin.

Share this post


Link to post
Share on other sites
irreversible    2862


How are you translating the scene ?

 

As mentioned, I'm calling setGlobalPose() for every rigid body and setPosition() for the character controller.

 


What version are of PhysX are you using ?

 

3.3.3

 


 v 3.3.3 added support for larger simulation environment by allow the scene origin to be moved ( don't know if this is what you are currently using. )

 

Since I'm essentially streaming geometry and intend to maintain a fairly small region in memory at any given time, I need to move the world around the origin. I don't see how adjusting the origin would help me here, unless I'm misunderstanding its function.

 


If you are using setGlobalPose in conjunction with this, then there are going to be anomalies as the new position position should be reference to the scene origin.

 

Nope, not using in conjunction. The thing is that my scene is translated properly, but if the player is in the process of walking into a solid when the translation occurs, there's a good chance that they'll clip into the the geometry during that update.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this