Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -98,6 +98,88 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { · 97 unmodified lines | ||
| 98 | 98 | voxelsToRender = (voxelsRendered > 0); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | +////////////////////////////////////////////////////////////////////////////////////////// | |
| 102 | +// Method: VoxelSystem::createSphere() | |
| 103 | +// Description: Creates a sphere of voxels in the local system at a given location/radius | |
| 104 | +// To Do: Move this function someplace better? I put it here because we need a | |
| 105 | +// mechanism to tell the system to redraw it's arrays after voxels are done | |
| 106 | +// being added. This is a concept mostly only understood by VoxelSystem. | |
| 107 | +// Complaints: Brad :) | |
| 108 | +void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid) | |
| 109 | +{ | |
| 110 | + // Psuedocode for creating a sphere: | |
| 111 | + // | |
| 112 | + // for (theta from 0 to 2pi): | |
| 113 | + // for (phi from 0 to pi): | |
| 114 | + // x = xc+r*cos(theta)*sin(phi) | |
| 115 | + // y = yc+r*sin(theta)*sin(phi) | |
| 116 | + // z = zc+r*cos(phi) | |
| 117 | + | |
| 118 | + int t=0; // total points | |
| 119 | + | |
| 120 | + // We want to make sure that as we "sweep" through our angles | |
| 121 | + // we use a delta angle that's small enough to not skip any voxels | |
| 122 | + // we can calculate theta from our desired arc length | |
| 123 | + // | |
| 124 | + // lenArc = ndeg/360deg * 2pi*R | |
| 125 | + // lenArc = theta/2pi * 2pi*R | |
| 126 | + // lenArc = theta*R | |
| 127 | + // theta = lenArc/R | |
| 128 | + // theta = g/r | |
| 129 | + float angleDelta = (s/r); | |
| 130 | + | |
| 131 | + // assume solid for now | |
| 132 | + float ri = 0.0; | |
| 133 | + if (!solid) | |
| 134 | + { | |
| 135 | + ri=r; // just the outer surface | |
| 136 | + } | |
| 137 | + // If you also iterate form the interior of the sphere to the radius, makeing | |
| 138 | + // larger and larger sphere's you'd end up with a solid sphere. And lots of voxels! | |
| 139 | + for (; ri <= r; ri+=s) | |
| 140 | + { | |
| 141 | + for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) | |
| 142 | + { | |
| 143 | + for (float phi=0.0; phi <= M_PI; phi += angleDelta) | |
| 144 | + { | |
| 145 | + t++; // total voxels | |
| 146 | + float x = xc+r*cos(theta)*sin(phi); | |
| 147 | + float y = yc+r*sin(theta)*sin(phi); | |
| 148 | + float z = zc+r*cos(phi); | |
| 149 | + /* | |
| 150 | + std::cout << " r=" << r; | |
| 151 | + std::cout << " theta=" << theta; | |
| 152 | + std::cout << " phi=" << phi; | |
| 153 | + std::cout << " x=" << x; | |
| 154 | + std::cout << " y=" << y; | |
| 155 | + std::cout << " z=" << z; | |
| 156 | + std::cout << " t=" << t; | |
| 157 | + std::cout << std::endl; | |
| 158 | + */ | |
| 159 | + | |
| 160 | + // random color data | |
| 161 | + unsigned char red = randomColorValue(65); | |
| 162 | + unsigned char green = randomColorValue(65); | |
| 163 | + unsigned char blue = randomColorValue(65); | |
| 164 | + | |
| 165 | + unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); | |
| 166 | + tree->readCodeColorBufferToTree(voxelData); | |
| 167 | + delete voxelData; | |
| 168 | + | |
| 169 | + } | |
| 170 | + } | |
| 171 | + } | |
| 172 | + | |
| 173 | + // reset the verticesEndPointer so we're writing to the beginning of the array | |
| 174 | + verticesEndPointer = verticesArray; | |
| 175 | + // call recursive function to populate in memory arrays | |
| 176 | + // it will return the number of voxels added | |
| 177 | + voxelsRendered = treeToArrays(tree->rootNode); | |
| 178 | + // set the boolean if there are any voxels to be rendered so we re-fill the VBOs | |
| 179 | + voxelsToRender = (voxelsRendered > 0); | |
| 180 | +} | |
| 181 | + | |
| 182 | + | |
| 101 | 183 | void VoxelSystem::parseData(void *data, int size) { |
| 102 | 184 | // output the bits received from the voxel server |
| 103 | 185 | unsigned char *voxelData = (unsigned char *) data + 1; |
| @@ -243,3 +325,4 @@ void VoxelSystem::simulate(float deltaTime) { · 139 unmodified lines | ||
| 243 | 325 | |
| 244 | 326 | } |
| 245 | 327 | |
| 328 | + | |