Hi folks! I’ve been working on the Rubik’s cube game in Elm using WebGL. The goal of the project was to experiment with complex user interactions and learn how to do ray tracing.
The result can be found here: https://github.com/w0rm/elm-cubik
Some of the interesting ideas in the project are:
- Using the same function to handle a particular message and also to conditionally subscribe to the corresponding subscription. You can find some similarities between update and subscription functions in the Main.elm.
- Modelling rotations as quaternions and using elm-animation library for transitions between rotations (for start game/end game transitions).
- Rendering text in 3D by defining a mesh as a layer of cubes, but then selectively discarding some of them in the vertex shader using the texture lookup.
- If you want to implement ray tracing I recommend this post: https://medium.com/@voorkanter/clicking-a-3d-mesh-in-elm-webgl-faadfdf703a0
- for quaternions in Elm I basically used some parts of this library https://github.com/kfish/quaternion
- to create animations that just need the time from AnimationFrame subscription, I highly encourage to check https://github.com/mgold/elm-animation