Expand description
Β§Monkey Map
Parses any arbitrary cube map calculating the transitions between faces dynamically using 3D vectors.
We build the transitions with a BFS over the connected cube map. The first face we find is labelled A in the diagram below. For each face we define 3 vectors:
i
Horizontal from left to right in the plane of the face.j
Vertical from top to bottom in the plane of the face.k
Perpendicular to the face pointing into the body of the cube.
k (0, 0, 1)
^
/
/
-------------+
/ /|
/ B / |
/ / |
+------------+---->i (1, 0, 0)
| | C |
| A | /
| | /
| |/
+------------+
|
|
v
j (0, 1, 0)
Then for each neighbouring face we can find its i
, j
and k
vectors depending on which
edge it shares in common. For example if we move from face A to face B along the top edge
then the new vectors are:
i
(1, 0, 0) Remains unchangedj
(0, 0, -1) Minus previousk
k
(0, 1, 0) Previousj
If face B and C are connected then the vectors for face C are:
i
(0, 1, 0)j
(0, 0, -1)k
(-1, 0, 0)
However if A and C were connected then the vectors for face C are:
i
(0, 0, 1)j
(0, 1, 0)k
(-1, 0, 0)
The really neat part is that when we leave the edge of a cube face the next
3D vector is always k
no matter which edge. We can find the new direction by comparing
the previous k
against the new i
and j
vectors.
For example say we transition from face A
to face B
. Our k
is (0, 1, 0) which is
equal to minus the new j
, so we know that weβre travelling upwards from the bottom edge.
Then we can use this information to figure out the two dimensional offsets into the new face.
Structs§
- Face π2D coordinates of the top left corner plus 3D vectors for the cube face.
- Vector πMinimal 3D vector implementation
Enums§
Functions§
- parse_
grid π - parse_
moves π - password πCommon code shared between part one and two. The
handle_none
closure defines how to transition when we leave an edge.