Module rotationutil
Various functions for rotating nodes.
The internal mechanics of Minetest are as follows: It uses the facedir value to apply an rotation. It is value with the minimum of 0 (no rotation) to the maximum of 23 (1 0 1 1 1). It consists of two parts, the lower two bits are the amount of rotation applied:
Bits Value Description 0 0 0 No rotation 0 1 1 90 degrees (sign depending on axis, + for z+ x- y-) 1 0 2 180 degrees 1 1 3 -90 degrees (sign depending on axis, + for z- x+ y+) These values correspond to the ROT_* constants. The upper three bits are the axis that is used:
Bits Value Shifted Description 0 0 0 0 0 y+, no rotation 0 0 1 1 4 z+, 90 degrees clockwise around x 0 1 0 2 8 z-, 90 degrees counter-clockwise around x 0 1 1 3 12 x+, 90 degrees counter-clockwise around z 1 0 0 4 16 x-, 90 degrees clockwise around z 1 0 1 5 20 y-, 180 degrees counter-clockwise around x
These values correspond to the POS_* and NEG_* constants. The rotation is a two step process, first the rotation of the axis/upper three bits are applied, after that the rotation/lower two bits.
See the mapnode.cpp/transformNodeBox function for even more details.
Functions
decrement (rotation) | Returns the decremented rotation, so given rotation - 90 degrees. |
facedir (axis, rotation) | Creates the facedir value from the given axis and rotation. |
increment (rotation) | Returns the incremented rotation, so given rotation + 90 degrees. |
invert (axis_or_rotation) | Inverts the given axis or rotation. |
Fields
NEG_X | The negative X Axis. |
NEG_Z | The negative Z Axis. |
NEG_Y | The negative Y Axis. |
POS_X | The positive X Axis. |
POS_Y | The positive Y Axis. |
POS_Z | The positive Z Axis. |
ROT_0 | No rotation. |
ROT_90 | Rotation 90 degrees, sign depends on the axis. |
ROT_180 | Rotation 180 degrees. |
ROT_270 | Rotation 270/-90 degrees, sign depends on the axis. |
Functions
- decrement (rotation)
-
Returns the decremented rotation, so given rotation - 90 degrees.
Parameters:
- rotation The rotation to decrement.
Returns:
-
The decremented rotation, or the given value if it was not valid.
- facedir (axis, rotation)
-
Creates the facedir value from the given axis and rotation.
Parameters:
- axis The axis, one of the POS_* or NEG_* constants.
- rotation The rotation, one of the ROT_* constants.
Returns:
-
The facedir value.
- increment (rotation)
-
Returns the incremented rotation, so given rotation + 90 degrees.
Parameters:
- rotation The rotation to increment.
Returns:
-
The incremented rotation, or the given value if it was not valid.
- invert (axis_or_rotation)
-
Inverts the given axis or rotation.
Parameters:
- axis_or_rotation The axis or rotation, one of the POS_*, NEG_* or ROT_* constants.
Returns:
-
The inverted value, or the given value if it was not valid.
Fields
- NEG_X
-
The negative X Axis. Will rotate the node around the Z axis by
90 degrees clockwise before the additional rotation is applied.
Minetest internal it has the value 4, within facedir it is 16 (1 0 0 R R).
- NEG_Z
-
The negative Z Axis. Will rotate the node around the X axis by
90 degrees counter-clockwise before the additional rotation is applied.
Minetest internal it has the value 2, within facedir it is 8 (0 1 0 R R).
- NEG_Y
-
The negative Y Axis. Will rotate the node around the Z axis by
180 degrees counter-clockwise before the additional rotation is applied.
Minetest internal it has the value 5, within the bitmask of facedir it is 20 (1 0 1 R R).
- POS_X
-
The positive X Axis. Will rotate the node around the Z axis by
90 degrees counter-clockwise before the additional rotation is applied.
Minetest internal it has the value 3, within facedir it is 12 (0 1 1 R R).
- POS_Y
-
The positive Y Axis. Will not rotate the node before the additional
rotation is applied.
Minetest internal it has the value 0, within of facedir it is 0 (0 0 0 R R).
- POS_Z
-
The positive Z Axis. Will rotate the node around the X axis by
90 degrees clockwise before the additional rotation is applied.
Minetest internal it has the value 1, within facedir it is 4 (0 0 1 R R).
- ROT_0
- No rotation.
- ROT_90
- Rotation 90 degrees, sign depends on the axis.
- ROT_180
- Rotation 180 degrees.
- ROT_270
- Rotation 270/-90 degrees, sign depends on the axis.