smcameron / space-nerds-in-space

Multi-player spaceship bridge simulator game. Captain your starship through adventures with your friends. See https://smcameron.github.io/space-nerds-in-space
GNU General Public License v2.0
724 stars 73 forks source link

Representing angular velocity via a quaternion could be problematic #307

Open smcameron opened 2 years ago

smcameron commented 2 years ago

But quaternions is what we use for angular velocity throughout SNIS. Not that I've noticed any problems with it in SNIS, however.

But... it can only represent angular velocities less than 360 degrees per time step. Also, it only works with a fixed timestep.

The "correct" and "conventional" way to represent angular velocities is via a vec3 pointing along the axis of rotation (similar to how a quaternion is constructed), with magnitude equal to the magnitude of the angular velocity (in whatever units... degrees per second, or whatever.) This accomodates a variable timestep and allows for arbitrarily large angular velocities.

This stackoverflow question goes into it in some depth: https://stackoverflow.com/questions/24197182/efficient-quaternion-angular-velocity

We would also save a float's worth of bandwidth for each angular velocity transmitted over the network.

All that being said... given that the "physics", such as it is in SNIS, is so lackadaisical, the only problem one might "see" in SNIS is that the timesteps are not necessarily precisely equal from one frame to the next, and this is not taken into account by the current way of using quaternions for angular velocity. So, maybe if you very carefully measured rotating asteroids, you might see them very very slightly speed up or slow down in their rotations. So this is more of a theoretical problem than an actual problem in the game as it stands today.

Also, if something were rotating very very fast, it might exceed the rotation representable by a quaternion for the selected timestep (unlikely).

So... this bug report is kind of like a... "D'oh! I did it wrong! (but my way still works well enough that I haven't noticed any problem since 2013.)"

And I didn't find out about this by spotting a problem, I suggested to someone else that they should use a quaternion to represent angular velocity, and someone else pointed out that this wasn't a very good idea for several reasons.

So, fixing this would be quite a lot of work, for next to no perceivable benefit. But... it's kind of bothering me, so maybe if I get really bored...