Hi folks, I’ve been working on something really exciting — a 3d physics engine in Elm, and have something to show!
Conversion was somewhat painful, because of little mistakes that I did here and there that were not caught by the type system, e.g.
vec1 |> Vec3.sub vec2 is not equivalent to
I went by manually stepping through the compiled code in Chrome Dev Tools and comparing intermediate values to the same scene running in Cannon.js, I did this to discover some anomalies in the coefficients and then traced them up to find the bugs in code.
I learned that the current linear-algebra package in Elm doesn’t support things that I needed, so I had to implement things like Mat3 and Quaternion. Perhaps supporting typed arrays in Elm would make it possible to roll out Elm implementation of linear-algebra without native code.
In order to port mutable object oriented code to Elm, I had to clearly separate reads and writes, because in some places the values were mutated on read (perhaps for performance reasons). In the end, it really streamlined the algorithms, and made them easier to understand.
There are also a lot of features that I didn’t implement, because I was mostly focused on just enough API to make the dice game.