First, we divide the x, y, and z coordinates into unit cubes. In other words, find [x,y,z] % 1.0
to find the coordinate's location within the cube.
What that means is you perform the value % 1.0
operation for each member of the [x,y,z]
vector (the position):
[x', y', z'] = [x % 1.0, y % 1.0, z % 1.0]
x'
, y'
, and z'
are the remainders of dividing each floating-point coordinate by 1.0.
In other words, they are the amount you "chop off" of each coordinate when you round towards zero.
[x', y', z']
represents the position inside a unit cube, from 0.0 to 1.0 on each axis.
But you can also imagine that unit cube is actually positioned in 3D space at the rounded (towards zero) coordinates of [(int)x, (int)y, (int)z]
.
Another way to visualize what [x', y', z']
means is to imagine a 1x1x1 grid superimposed over your game world. Each cell in the grid is a unit cube. If you have a point anywhere in that game world, it must be inside of of those cubes. [x', y', z']
is telling you where the point is inside that cube.
The original position can be recovered by adding the position of the unit cube and the position inside the unit cube:
[x, y, z] = [(int)x, (int)y, (int)z] + [x % 1.0, y % 1.0, z % 1.0]