mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 17:03:11 +02:00
initial LOD drop off when moving back
This commit is contained in:
parent
80170bd4c4
commit
3186254a93
5 changed files with 45 additions and 9 deletions
|
@ -51,6 +51,10 @@ VoxelSystem::~VoxelSystem() {
|
|||
pthread_mutex_destroy(&bufferWriteLock);
|
||||
}
|
||||
|
||||
void VoxelSystem::setViewerHead(Head *newViewerHead) {
|
||||
viewerHead = newViewerHead;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Method: VoxelSystem::loadVoxelsFile()
|
||||
// Description: Loads HiFidelity encoded Voxels from a binary file. The current file
|
||||
|
@ -94,7 +98,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
|
|||
writeVerticesEndPointer = writeVerticesArray;
|
||||
// call recursive function to populate in memory arrays
|
||||
// it will return the number of voxels added
|
||||
voxelsRendered = treeToArrays(tree->rootNode);
|
||||
float treeRoot[3] = {0,0,0};
|
||||
voxelsRendered = treeToArrays(tree->rootNode, treeRoot);
|
||||
|
||||
// copy the newly written data to the arrays designated for reading
|
||||
copyWrittenDataToReadArrays();
|
||||
|
@ -114,16 +119,42 @@ void VoxelSystem::copyWrittenDataToReadArrays() {
|
|||
pthread_mutex_unlock(&bufferWriteLock);
|
||||
}
|
||||
|
||||
int VoxelSystem::treeToArrays(VoxelNode *currentNode) {
|
||||
int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
|
||||
int voxelsAdded = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// check if there is a child here
|
||||
if (currentNode->children[i] != NULL) {
|
||||
voxelsAdded += treeToArrays(currentNode->children[i]);
|
||||
float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE);
|
||||
glm::vec3 viewerPosition = viewerHead->getPos();
|
||||
|
||||
float distanceToVoxelCenter = sqrtf(powf(viewerPosition[0] - nodePosition[0] - halfUnitForVoxel, 2) +
|
||||
powf(viewerPosition[1] - nodePosition[1] - halfUnitForVoxel, 2) +
|
||||
powf(viewerPosition[2] - nodePosition[2] - halfUnitForVoxel, 2));
|
||||
|
||||
if (distanceToVoxelCenter < boundaryDistanceForRenderLevel(*currentNode->octalCode + 1)) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// check if there is a child here
|
||||
if (currentNode->children[i] != NULL) {
|
||||
|
||||
// calculate the child's position based on the parent position
|
||||
float childNodePosition[3];
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
childNodePosition[j] = nodePosition[j];
|
||||
|
||||
if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,
|
||||
currentNode->children[i]->octalCode),
|
||||
(7 - j))) {
|
||||
childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
voxelsAdded += treeToArrays(currentNode->children[i], childNodePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if we didn't get any voxels added then we're a leaf
|
||||
// add our vertex and color information to the interleaved array
|
||||
if (voxelsAdded == 0 && currentNode->color[3] == 1) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <UDPSocket.h>
|
||||
#include <AgentData.h>
|
||||
#include <VoxelTree.h>
|
||||
#include "Head.h"
|
||||
#include "Util.h"
|
||||
#include "world.h"
|
||||
|
||||
|
@ -33,10 +34,12 @@ public:
|
|||
void render();
|
||||
void setVoxelsRendered(int v) {voxelsRendered = v;};
|
||||
int getVoxelsRendered() {return voxelsRendered;};
|
||||
void setViewerHead(Head *newViewerHead);
|
||||
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer);
|
||||
private:
|
||||
int voxelsRendered;
|
||||
Head *viewerHead;
|
||||
VoxelTree *tree;
|
||||
GLfloat *readVerticesArray;
|
||||
GLubyte *readColorsArray;
|
||||
|
@ -49,7 +52,7 @@ private:
|
|||
GLuint vboIndicesID;
|
||||
pthread_mutex_t bufferWriteLock;
|
||||
|
||||
int treeToArrays(VoxelNode *currentNode);
|
||||
int treeToArrays(VoxelNode *currentNode, float nodePosition[3]);
|
||||
void setupNewVoxelsForDrawing();
|
||||
void copyWrittenDataToReadArrays();
|
||||
};
|
||||
|
|
|
@ -294,6 +294,7 @@ void initDisplay(void)
|
|||
void init(void)
|
||||
{
|
||||
voxels.init();
|
||||
voxels.setViewerHead(&myHead);
|
||||
myHead.setRenderYaw(start_yaw);
|
||||
|
||||
head_mouse_x = WIDTH/2;
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
#include <iostream> // to load voxels from file
|
||||
#include <fstream> // to load voxels from file
|
||||
|
||||
const int TREE_SCALE = 10;
|
||||
|
||||
int boundaryDistanceForRenderLevel(unsigned int renderLevel) {
|
||||
switch (renderLevel) {
|
||||
case 1:
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
const int MAX_VOXEL_PACKET_SIZE = 1492;
|
||||
const int MAX_TREE_SLICE_BYTES = 26;
|
||||
const int TREE_SCALE = 10;
|
||||
|
||||
class VoxelTree {
|
||||
VoxelNode * nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * needleCode);
|
||||
|
@ -42,4 +43,6 @@ public:
|
|||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer);
|
||||
};
|
||||
|
||||
int boundaryDistanceForRenderLevel(unsigned int renderLevel);
|
||||
|
||||
#endif /* defined(__hifi__VoxelTree__) */
|
||||
|
|
Loading…
Reference in a new issue