#include "Shapes.h" using namespace PolyVox; void createSphereInVolume(Volume& volData, float fRadius, PolyVox::uint8_t uValue) { //This vector hold the position of the center of the volume Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); //This three-level for loop iterates over every voxel in the volume for (int z = 0; z < volData.getWidth(); z++) { for (int y = 0; y < volData.getHeight(); y++) { for (int x = 0; x < volData.getDepth(); x++) { //Store our current position as a vector... Vector3DFloat v3dCurrentPos(x,y,z); //And compute how far the current position is from the center of the volume float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); //If the current voxel is less than 'radius' units from the center //then we make it solid, otherwise we make it empty space. if(fDistToCenter <= fRadius) { volData.setVoxelAt(x,y,z, uValue); } } } } } void createCubeInVolume(Volume& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, PolyVox::uint8_t uValue) { //This three-level for loop iterates over every voxel between the specified corners for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) { for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++) { for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++) { volData.setVoxelAt(x,y,z, uValue); } } } }