vm6502q / OpenRelativity

An open source framework to add the effects of traveling at relativistic speeds to visualizations or games
17 stars 2 forks source link

WIP: Fixing "viw == 0" shader case #11

Closed WrathfulSpatula closed 5 years ago

WrathfulSpatula commented 5 years ago

Per #3, we're going to clean up everything, from style standards to debugging the relativistic physics itself. When our code isn't "spaghettified," it's much easier to detect the problems with the physics.

The "cheap" RelativisticObjects I implemented, with BoxColliders that "live" in "optical coordinates" don't seem to have this problem, but the full shader implementation is wrong for the "viw == Vector3.zero" case. It's fairly easily apparent, in the demo level. This WIP will ultimately fix that, for the full RO w/ shader implementation.

WrathfulSpatula commented 5 years ago

Upon reviewing the existing code, it turns out that round-trip on WorldToOptical and OpticalToWorld fails at viw magnitude close to or exactly 0. To get around this, the velocity setter doesn't bother to update anything if the difference vector between old and new viw values has a square magnitude smaller than a very small epsilon. (This is a good idea in any case, from a performance standpoint.) Hopefully, this is just a numerical limitation and not indicative of a fundamental problem. I will be on the lookout. The mechanics finally look reasonably observer-independent, to a limited test.