Hacker News new | past | comments | ask | show | jobs | submit login
Geodesic Asteroids: Classic arcade game gets correct physics (nbodyphysics.com)
55 points by musgravepeter on March 17, 2015 | hide | past | favorite | 17 comments



I'm a strong proponent of thinking about interesting geometries and physicses like this in games, but I'm reluctant to describe this physics as more correct than the original.

The original had correct physics for the simplest possible torus, the mathematically abstract flat one. You've replaced it with correct physics for some arbitrary irregular torus that happens to embed into 3-space :)

(In fact, you can embed the original, flat torus in 4-space, as x² + y² = z² + w² = 1. If you put that into your geodesic solver, all the weird cross terms will go away and you'll get normal Asteroids physics.)

(And now with santaclaus' comment, I'm wondering what geometry I would advocate for a double torus. It can't be flat because of the Euler characteristic or something, but can it at least have constant curvature everywhere?)


My first expectation upon seeing the title, was that the author had done something to how irregular (3d) asteroids were affected by gravity (pulling each other and the ship) and explosions, rotations and orbits etc. [ed: not to mention fuel/weight/recoil for the ship and/or plasma boiling off asteroids from lasers etc...).]

To me this is more an example of "correct math", not "correct physics" -- although I suppose it depends on one's point of view :-)


Just want to clarify a little. Since x^2+y^2 = 1, the projection of the torus onto the xy-plane is a circle. The same is true for the zw-plane.

A position on the torus can be specified by specifying the position in the xy-plane, and the position in the zw-plane. Since the projections are both circles, those two positions can be represented by one angle each.

And this is exactly what you see on your screen. The right-left axis is the xy-angle, and the top-bottom axis is the zw-angle. The edges of your screen correspond to an angle of 180/-180 degrees.


I agree with your point about embedding.

The game solves the geodesic equation using the instrinsic geometry of the torus in 2D space without reference to any embedding. It is in this sense that one might call the physics "correct"

The motion is then mapped into either a 2D or 3D representation and I agree this has a strong effect on how things look.

I'll need to think about the four space example.

What is the metric for a mathematically abstract flat torus?


If your model for the torus is the unit square with edges identified together, then the metric is the usual Euclidean metric, dx² + dy². (Alternatively, the metric induced from the embedding into Euclidean 4-space, with a parameterization like φ=atan2(y,x), θ=atan2(z,w), should give you the same answer give or take some factors of 2π.)

(Also, Mathoverflow relevant to the double torus question: http://mathoverflow.net/questions/194451/canonical-immersion...)


This reminds me of a game I wrote for Ludum Dare a while back:

http://0fps.net/2011/09/13/ludum-dare-21-results/

The title of the game was "Help! I'm trapped in a compact riemannian manifold"

You can grab the source for it on GitHub, though the build process is pretty janky as I wrote it in 48 hours and wasn't very careful with the distribution:

https://github.com/mikolalysenko/ludum-dare-21


Very hypnotizing! I assume you have a heuristic for geodesic motion? I doubt I could write down the metrics for some of those surfaces in a Lundum Dare timeframe.


It uses numerical techniques instead of explicit formulas.


This is really cool! I could really use a longer gameplay video though to get a hang of how the screen mapping works.


Thanks! You can get a free version for iOS, Android and Blackberry... (Same as paid version, just no bonus ships)


Why stop at a torus? Go Genus-2!


(Nbodyphysics) Yeah - maybe if there's interest. The code gets a bit messier since I need multiple co-ordinate patches and there is a discontinuity...


wait im confused, why a torus and not a sphere?


Going around the "top" of a sphere ends up looking weird in a 2D projection (like your standard Mercator projection map) - you end up next to where you went in. If you want to come out on the bottom, you typically want a torus.


What if it was a sphere, but the camera moved along with the ship -- with a dead zone in the middle?


(nbodyphysics here) I initially had the same thought, but when you think of a Mercator map, the top edge is a point, the north pole. On a torus it's a line, the inner circle.


The other comment makes an excellent point about the mapping. That's also crucial.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: