History

initial LOD drop off when moving back

Stephen Birarda committed 13 years ago

Commit 31862541 parent 80170bd5 files · +45 −9Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+37−6
@@ -51,6 +51,10 @@ VoxelSystem::~VoxelSystem() { · 50 unmodified lines
51 pthread_mutex_destroy(&bufferWriteLock);51 pthread_mutex_destroy(&bufferWriteLock);
52}52}
53 53
54void VoxelSystem::setViewerHead(Head *newViewerHead) {
55 viewerHead = newViewerHead;
56}
57
54//////////////////////////////////////////////////////////////////////////////////////////58//////////////////////////////////////////////////////////////////////////////////////////
55// Method: VoxelSystem::loadVoxelsFile()59// Method: VoxelSystem::loadVoxelsFile()
56// Description: Loads HiFidelity encoded Voxels from a binary file. The current file60// Description: Loads HiFidelity encoded Voxels from a binary file. The current file
@@ -94,7 +98,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 37 unmodified lines
94 writeVerticesEndPointer = writeVerticesArray;98 writeVerticesEndPointer = writeVerticesArray;
95 // call recursive function to populate in memory arrays99 // call recursive function to populate in memory arrays
96 // it will return the number of voxels added100 // it will return the number of voxels added
97 voxelsRendered = treeToArrays(tree->rootNode);101 float treeRoot[3] = {0,0,0};
102 voxelsRendered = treeToArrays(tree->rootNode, treeRoot);
98 103
99 // copy the newly written data to the arrays designated for reading104 // copy the newly written data to the arrays designated for reading
100 copyWrittenDataToReadArrays();105 copyWrittenDataToReadArrays();
@@ -114,16 +119,42 @@ void VoxelSystem::copyWrittenDataToReadArrays() { · 13 unmodified lines
114 pthread_mutex_unlock(&bufferWriteLock);119 pthread_mutex_unlock(&bufferWriteLock);
115}120}
116 121
117int VoxelSystem::treeToArrays(VoxelNode *currentNode) {122int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
118 int voxelsAdded = 0;123 int voxelsAdded = 0;
119 124
120 for (int i = 0; i < 8; i++) {125 float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE);
121 // check if there is a child here126 glm::vec3 viewerPosition = viewerHead->getPos();
122 if (currentNode->children[i] != NULL) {127
123 voxelsAdded += treeToArrays(currentNode->children[i]);128 float distanceToVoxelCenter = sqrtf(powf(viewerPosition[0] - nodePosition[0] - halfUnitForVoxel, 2) +
129 powf(viewerPosition[1] - nodePosition[1] - halfUnitForVoxel, 2) +
130 powf(viewerPosition[2] - nodePosition[2] - halfUnitForVoxel, 2));
131
132 if (distanceToVoxelCenter < boundaryDistanceForRenderLevel(*currentNode->octalCode + 1)) {
133 for (int i = 0; i < 8; i++) {
134 // check if there is a child here
135 if (currentNode->children[i] != NULL) {
136
137 // calculate the child's position based on the parent position
138 float childNodePosition[3];
139
140 for (int j = 0; j < 3; j++) {
141 childNodePosition[j] = nodePosition[j];
142
143 if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,
144 currentNode->children[i]->octalCode),
145 (7 - j))) {
146 childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE);
147 }
148 }
149
150
151 voxelsAdded += treeToArrays(currentNode->children[i], childNodePosition);
152 }
124 }153 }
125 }154 }
126 155
156
157
127 // if we didn't get any voxels added then we're a leaf158 // if we didn't get any voxels added then we're a leaf
128 // add our vertex and color information to the interleaved array159 // add our vertex and color information to the interleaved array
129 if (voxelsAdded == 0 && currentNode->color[3] == 1) {160 if (voxelsAdded == 0 && currentNode->color[3] == 1) {