I'm using LWJGL and JOML to create a 3D view of hexagons whose positions lie on a torus.
I have a number (NxM) hexagons, whose centres and normals I have calculated to be placed on the torus to completely cover the torus surface, but in the "game" engine I'm using I need to convert each item being rendered to a position and 3 rotation angles. I'm struggling to go from the 3 normals of the item to the 3 angles.
EDIT: Subsequent to posting this I have got some way in creating a matrix with the angles and converting to Euler angles, everything is now turned according to those angles, but they aren't facing directions I expect.
The background
I'm trying to create a visualisation of a Conway Game of Life using hexagons but instead of a simple plane, mapping each hexagon onto a Torus.
I've done the maths to calculate the centres of every hexagon, and the 3 direction unit vectors that they need to point to, when in their places around the torus.
For illustrative purposes, here's a view of the torus and 2 hexagons that would lie on it (not real, this is just me mocking it up in Blender)
What I'm struggling to understand is how to rotate the single mesh for a hexagon to its calculated normals at the position I want to place it.
i.e. How do I rotate some "unit" hexagon mesh (loaded from an OBJ file exported from Blender) to point in the direction of the 3 normals I've calculated they should be for each hexagon around the torus.
I have read a similar question here, but I'm struggling to get from the idea of the 4d rotation matrix to how I convert that to a Vector3f for rotations. I have the 3 vector normals, could create the 4d matrix, but I need a Vector3f (the rotations about x/y/z) to the mesh is drawn correctly.
My code is here. I'm following this guide for using LWJGL to create GameItems (my hexagons) and position/rotate them from a loaded obj file mesh, but as I say, I'm struggling to calculate the rotation Vector3f needed to point in the same direction I've calculated.
Here's the code section relevant to the problem at hand:
val mesh = loadMesh("/conwayhex/models/simple-hexagon.obj")
hexGrid.hexAxes().forEach { (location, axis) ->
// axis is a Matrix3f with my 3 normals at the centre of the hexagon, e.g
// cX cY cZ
// 0 -1 0
// 0 0 -1
// 1 0 0
val gameItem = GameItem(mesh)
gameItem.position = location
gameItem.scale = 0.2f // TODO: calculate this according to the torus size
// what rotation do I give this?
// How do I calculate it from the given axis for the current item?
gameItem.rotation = Vector3f(30f, 30f, 30f)
gameItems += gameItem
}
The output of the application given the above static 30 degree rotation is:
Can anyone help me unserstand how I apply the rotation to my items so they align to what I've calculated they should be?