mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 03:53:52 +02:00
remove more cruft from VoxelSystem, move getElementEnclosingPoint() to Octree class where it belongs
This commit is contained in:
parent
855e351f39
commit
f245aa6ac5
5 changed files with 95 additions and 70 deletions
|
@ -1774,38 +1774,6 @@ void VoxelSystem::forceRedrawEntireTree() {
|
|||
setupNewVoxelsForDrawing();
|
||||
}
|
||||
|
||||
class VoxelAndPoint {
|
||||
public:
|
||||
VoxelTreeElement* voxel;
|
||||
glm::vec3 point;
|
||||
};
|
||||
|
||||
// Find the smallest colored voxel enclosing a point (if there is one)
|
||||
bool VoxelSystem::getVoxelEnclosingOperation(OctreeElement* element, void* extraData) {
|
||||
VoxelTreeElement* voxel = (VoxelTreeElement*)element;
|
||||
VoxelAndPoint* args = (VoxelAndPoint*) extraData;
|
||||
AABox voxelBox = voxel->getAABox();
|
||||
if (voxelBox.contains(args->point)) {
|
||||
if (voxel->isColored() && voxel->isLeaf()) {
|
||||
// we've reached a solid leaf containing the point, return the node.
|
||||
args->voxel = voxel;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The point is not inside this voxel, so stop recursing.
|
||||
return false;
|
||||
}
|
||||
return true; // keep looking
|
||||
}
|
||||
|
||||
VoxelTreeElement* VoxelSystem::getVoxelEnclosing(const glm::vec3& point) {
|
||||
VoxelAndPoint voxelAndPoint;
|
||||
voxelAndPoint.point = point;
|
||||
voxelAndPoint.voxel = NULL;
|
||||
_tree->recurseTreeWithOperation(getVoxelEnclosingOperation, (void*) &voxelAndPoint);
|
||||
return voxelAndPoint.voxel;
|
||||
}
|
||||
|
||||
bool VoxelSystem::isViewChanging() {
|
||||
bool result = false; // assume the best
|
||||
|
||||
|
|
|
@ -84,8 +84,6 @@ public:
|
|||
virtual void elementDeleted(OctreeElement* element);
|
||||
virtual void elementUpdated(OctreeElement* element);
|
||||
|
||||
VoxelTreeElement* getVoxelEnclosing(const glm::vec3& point);
|
||||
|
||||
public slots:
|
||||
void nodeAdded(SharedNodePointer node);
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
|
|
|
@ -87,23 +87,25 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
|||
|
||||
// Voxel Drumming with fingertips if enabled
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) {
|
||||
VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing(
|
||||
OctreeElement* fingerElement = Application::getInstance()->getVoxelTree()->getElementEnclosingPoint(
|
||||
glm::vec3(fingerTipPosition / (float)TREE_SCALE));
|
||||
if (fingerNode) {
|
||||
VoxelTreeElement* fingerVoxel = static_cast<VoxelTreeElement*>(fingerElement);
|
||||
if (fingerVoxel) {
|
||||
if (!palm.getIsCollidingWithVoxel()) {
|
||||
// Collision has just started
|
||||
palm.setIsCollidingWithVoxel(true);
|
||||
handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime);
|
||||
handleVoxelCollision(&palm, fingerTipPosition, fingerVoxel, deltaTime);
|
||||
|
||||
// Set highlight voxel
|
||||
VoxelDetail voxel;
|
||||
glm::vec3 pos = fingerNode->getCorner();
|
||||
glm::vec3 pos = fingerVoxel->getCorner();
|
||||
voxel.x = pos.x;
|
||||
voxel.y = pos.y;
|
||||
voxel.z = pos.z;
|
||||
voxel.s = fingerNode->getScale();
|
||||
voxel.red = fingerNode->getColor()[0];
|
||||
voxel.green = fingerNode->getColor()[1];
|
||||
voxel.blue = fingerNode->getColor()[2];
|
||||
voxel.s = fingerVoxel->getScale();
|
||||
voxel.red = fingerVoxel->getColor()[0];
|
||||
voxel.green = fingerVoxel->getColor()[1];
|
||||
voxel.blue = fingerVoxel->getColor()[2];
|
||||
Application::getInstance()->setHighlightVoxel(voxel);
|
||||
Application::getInstance()->setIsHighlightVoxel(true);
|
||||
}
|
||||
|
|
|
@ -588,9 +588,16 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) {
|
|||
}
|
||||
|
||||
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
OctreeElement*& node, float& distance, BoxFace& face) {
|
||||
OctreeElement*& node, float& distance, BoxFace& face, bool tryLock) {
|
||||
RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face };
|
||||
recurseTreeWithOperation(findRayIntersectionOp, &args);
|
||||
|
||||
if (!tryLock) {
|
||||
lockForRead();
|
||||
}
|
||||
if (tryLock && tryLockForRead()) {
|
||||
recurseTreeWithOperation(findRayIntersectionOp, &args);
|
||||
unlock();
|
||||
}
|
||||
return args.found;
|
||||
}
|
||||
|
||||
|
@ -626,25 +633,27 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
|||
}
|
||||
|
||||
bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
||||
void** penetratedObject) {
|
||||
void** penetratedObject, bool tryLock) {
|
||||
|
||||
bool result = false; // assume no penetration
|
||||
if (tryLockForRead()) {
|
||||
SphereArgs args = {
|
||||
center / (float)(TREE_SCALE),
|
||||
radius / (float)(TREE_SCALE),
|
||||
penetration,
|
||||
false,
|
||||
NULL };
|
||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
SphereArgs args = {
|
||||
center / (float)(TREE_SCALE),
|
||||
radius / (float)(TREE_SCALE),
|
||||
penetration,
|
||||
false,
|
||||
NULL };
|
||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if (!tryLock) {
|
||||
lockForRead();
|
||||
}
|
||||
if (tryLock && tryLockForRead()) {
|
||||
recurseTreeWithOperation(findSpherePenetrationOp, &args);
|
||||
if (penetratedObject) {
|
||||
*penetratedObject = args.penetratedObject;
|
||||
}
|
||||
unlock();
|
||||
result = args.found;
|
||||
}
|
||||
return result;
|
||||
return args.found;
|
||||
}
|
||||
|
||||
class CapsuleArgs {
|
||||
|
@ -677,22 +686,67 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
|
||||
bool result = false; // assume no penetration
|
||||
if (tryLockForRead()) {
|
||||
CapsuleArgs args = {
|
||||
start / (float)(TREE_SCALE),
|
||||
end / (float)(TREE_SCALE),
|
||||
radius / (float)(TREE_SCALE),
|
||||
penetration };
|
||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||
glm::vec3& penetration, bool tryLock) {
|
||||
|
||||
CapsuleArgs args = {
|
||||
start / (float)(TREE_SCALE),
|
||||
end / (float)(TREE_SCALE),
|
||||
radius / (float)(TREE_SCALE),
|
||||
penetration,
|
||||
false };
|
||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if (!tryLock) {
|
||||
lockForRead();
|
||||
}
|
||||
if (tryLock && tryLockForRead()) {
|
||||
recurseTreeWithOperation(findCapsulePenetrationOp, &args);
|
||||
result = args.found;
|
||||
unlock();
|
||||
}
|
||||
return result;
|
||||
return args.found;
|
||||
}
|
||||
|
||||
class GetElementEnclosingArgs {
|
||||
public:
|
||||
OctreeElement* element;
|
||||
glm::vec3 point;
|
||||
};
|
||||
|
||||
// Find the smallest colored voxel enclosing a point (if there is one)
|
||||
bool getElementEnclosingOperation(OctreeElement* element, void* extraData) {
|
||||
GetElementEnclosingArgs* args = static_cast<GetElementEnclosingArgs*>(extraData);
|
||||
AABox elementBox = element->getAABox();
|
||||
if (elementBox.contains(args->point)) {
|
||||
if (element->hasContent() && element->isLeaf()) {
|
||||
// we've reached a solid leaf containing the point, return the node.
|
||||
args->element = element;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The point is not inside this voxel, so stop recursing.
|
||||
return false;
|
||||
}
|
||||
return true; // keep looking
|
||||
}
|
||||
|
||||
OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, bool tryLock) {
|
||||
GetElementEnclosingArgs args;
|
||||
args.point = point;
|
||||
args.element = NULL;
|
||||
|
||||
if (!tryLock) {
|
||||
lockForRead();
|
||||
}
|
||||
if (tryLock && tryLockForRead()) {
|
||||
recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args);
|
||||
unlock();
|
||||
}
|
||||
return args.element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Octree::encodeTreeBitstream(OctreeElement* node,
|
||||
OctreePacketData* packetData, OctreeElementBag& bag,
|
||||
EncodeBitstreamParams& params) {
|
||||
|
|
|
@ -222,12 +222,15 @@ public:
|
|||
void setDirtyBit() { _isDirty = true; }
|
||||
|
||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
OctreeElement*& node, float& distance, BoxFace& face);
|
||||
OctreeElement*& node, float& distance, BoxFace& face, bool tryLock = true);
|
||||
|
||||
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
||||
void** penetratedObject = NULL);
|
||||
void** penetratedObject = NULL, bool tryLock = true);
|
||||
|
||||
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration);
|
||||
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||
glm::vec3& penetration, bool tryLock = true);
|
||||
|
||||
OctreeElement* getElementEnclosingPoint(const glm::vec3& point, bool tryLock = true);
|
||||
|
||||
// Note: this assumes the fileFormat is the HIO individual voxels code files
|
||||
void loadOctreeFile(const char* fileName, bool wantColorRandomizer);
|
||||
|
|
Loading…
Reference in a new issue