-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigating physics precision loss with increasing distance from world origin. #3034
base: master
Are you sure you want to change the base?
Conversation
Definitely not just a visual glitch, N/Bs become increasingly unstable the further away you are from world origin: EDIT: |
Indeed not just a visual glitch, my first test was with Gavril MV4 and it shaked itself apart. But the fact is, visuals make it look way worse than it actually is. I suspect ground collisions and other external forces (wings, fusedrag) to be the culprit, because when I put DAF semitruck in mid-air (notice the tests above are 777777 on all axes) the N/B seems perfectly stable, only visually distorted. To sum up what I learned so far:
@paroj Can you please read the above and check if it makes any sense at all? This is the first time I'm digging this deep into 3D. Some of our jargon to make sense of it:
@CuriousMike56 Hopefully it's not all just babble to you, I'm not entirely sure what I'm doing myself :D |
// Nodes are drawn directly using RelPosition, so that the debugview is accurate even in great distances. // To do that, we construct a custom modelview matrix.
I took advantage of the fact the mesh is regenerated every frame. Instead of choosing an arbitrary mesh origin and generating the mesh from node absolute positions, I place the mesh origin at physics origin and generate the mesh from node relative positions. This creates an illusion of smooth movement within world space while the mesh is actualy not moving, only vertices within the mesh are moving. The same fix can be applied to flextires, flexbodies and flex airfoil, but this commit only fixes the cab mesh as proof of concept.
7561923
to
e202a7c
Compare
It was recently brought up on Discord#development that physics accuracy degrades very quickly with distance from the world origin: https://discord.com/channels/136544456244461568/189904947649708032/1093130839350583306. I was very surprised because I know that internally the node positions are stored and updated relative to local physics origin which is always kept close to the vehicle.
Test on master branch
I did a test: load 'simple2' terrain, load 'DAF semitruck', press J to pause physics, align camera on the side, do
goto 777777 777777 777777
in the console, press Shift+C for free cam and Alt+C for fixed-freecam, set slow motion ratio to 0.045 (top menubar / settings / slow motion), press K to activate skeletonview and finally J to unpause physics. On master branch, you'll see this:Corrected skeletonview on this branch
I realized the skeletonview shows node's absolute positions, not the relative positions the physics simulation uses. That's why, even though the motion of individual nodes is jerky, the overall motion is quite continuous. After a bit of reading on transformation matrices, I fixed the skeletonview to display the actual node positions. If you perform the same test with this branch, you'll get this result:
Now the skeletonview moves smoothly but everything else is jerky. This is because both props and cab meshes use absolute node positions. Same applies to flexbodies, flex airfoils and flextires. The camera position is also absolute and follows vehicle's absolute position, that's why it gets crazy jumpy in large distances (the gifs above use fixed-freecam).
Is it all just a visual glitch then? Well, node forces and velocities are always small and centered around their node, so no problem there. However, collisions are all calculated in world space as I saw. Same with airfoils (wings). And there are more minor calculations (fusedrag) which also uses absolute position. I need to do a lot more research.
Reading
Links that helped me make this real:
Links that gave me confidence for further fixing: