Godot Version
Godot_v4.3-stable_win64
Question
As you know, in GridMap, the orientation parameter is used for rotation (0-24). To convert angles to basis and then to orientation I use this code:
var angles = Vector3(deg_to_rad(v_x_1), deg_to_rad(v_x_2), deg_to_rad(v_x_3))
var basis = Basis.from_euler(angles)
var arr = [
int(basis.x.x), int(basis.x.y), int(basis.x.z),
int(basis.y.x), int(basis.y.y), int(basis.y.z),
int(basis.z.x), int(basis.z.y), int(basis.z.z)
]
We got a basis. next, we find this basis in the array of all basis associated with the parameter orientation.
var index_orientation = 0
index_orientation = basis_orientations.get(arr,0)
dictionary of basis for all 24 rotation variants:
var basis_orientations = {
[1, 0, 0, 0, 1, 0, 0, 0, 1]: 0,
[0, -1, 0, 1, 0, 0, 0, 0, 1]: 1,
[-1, 0, 0, 0, -1, 0, 0, 0, 1]: 2,
[0, 1, 0, -1, 0, 0, 0, 0, 1]: 3,
[1, 0, 0, 0, 0, -1, 0, 1, 0]: 4,
[0, 0, 1, 1, 0, 0, 0, 1, 0]: 5,
[-1, 0, 0, 0, 0, 1, 0, 1, 0]: 6,
[0, 0, -1, -1, 0, 0, 0, 1, 0]: 7,
[1, 0, 0, 0, -1, 0, 0, 0, -1]: 8,
[0, 1, 0, 1, 0, 0, 0, 0, -1]: 9,
[-1, 0, 0, 0, 1, 0, 0, 0, -1]: 10,
[0, -1, 0, -1, 0, 0, 0, 0, -1]: 11,
[1, 0, 0, 0, 0, 1, 0, -1, 0]: 12,
[0, 0, -1, 1, 0, 0, 0, -1, 0]: 13,
[-1, 0, 0, 0, 0, -1, 0, -1, 0]: 14,
[0, 0, 1, -1, 0, 0, 0, -1, 0]: 15,
[0, 0, 1, 0, 1, 0, -1, 0, 0]: 16,
[0, -1, 0, 0, 0, 1, -1, 0, 0]: 17,
[0, 0, -1, 0, -1, 0, -1, 0, 0]: 18,
[0, 1, 0, 0, 0, -1, -1, 0, 0]: 19,
[0, 0, 1, 0, -1, 0, 1, 0, 0]: 20,
[0, 1, 0, 0, 0, 1, 1, 0, 0]: 21,
[0, 0, -1, 0, 1, 0, 1, 0, 0]: 22,
[0, -1, 0, 0, 0, -1, 1, 0, 0]: 23,
}
But now I need to convert orientation to angles for rotation. I’ve heard of the get_euler() function, but it doesn’t seem to work.
at the moment with the help of this code I got basis:
var basis_array_keys = basis_orientations.keys()
var basis_array = basis_array_keys[orientation_index]
var basis = Basis(
Vector3(basis_array[0], basis_array[1], basis_array[2]),
Vector3(basis_array[3], basis_array[4], basis_array[5]),
Vector3(basis_array[6], basis_array[7], basis_array[8]),
)
But then how to convert the basis to angles?