I have been playing around with voxeljs, I'm new to 3D programming, and it says in the doc that this code generates the "sphere world":
generate: function(x,y,z) {
return x*x+y*y+z*z <= 20*20 ? 1 : 0 // sphere world
},
How is this actually generating a sphere? From my simple understanding, I think that it's basically "looping" through each "chunk" in the 3D world? Any further explanation or a point to a good tutorial on this would be a huge help!
Your function says:
If the voxel at
(x, y, z)is part of the sphere, return1, else0.
The author applies the sphere equation. Your sphere is formed by the following set of voxels:

That basically means a voxel is part of the sphere, if the distance to the center (0, 0, 0) is less than the radius. The distance is calculated using the Pythagorean Theorem. By squaring the radius (in your case 20) you can compare it to the squared distance without calculating a square root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With