mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-10 21:47:22 +02:00
Move AABox from octree lib to shared lib
Stubbed out Shape vs Octree collisions
This commit is contained in:
parent
57a221f343
commit
241df7a767
10 changed files with 79 additions and 9 deletions
|
@ -20,18 +20,20 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#include "CoverageMap.h"
|
||||
#include <GeometryUtil.h>
|
||||
#include "OctalCode.h"
|
||||
#include <OctalCode.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <Shape.h>
|
||||
#include <ShapeCollider.h>
|
||||
|
||||
//#include "Tags.h"
|
||||
|
||||
#include "ViewFrustum.h"
|
||||
#include "CoverageMap.h"
|
||||
#include "OctreeConstants.h"
|
||||
#include "OctreeElementBag.h"
|
||||
#include "Octree.h"
|
||||
#include "ViewFrustum.h"
|
||||
|
||||
float boundaryDistanceForRenderLevel(unsigned int renderLevel, float voxelSizeScale) {
|
||||
return voxelSizeScale / powf(2, renderLevel);
|
||||
|
@ -676,6 +678,13 @@ public:
|
|||
bool found;
|
||||
};
|
||||
|
||||
class ShapeArgs {
|
||||
public:
|
||||
const Shape* shape;
|
||||
CollisionList& collisions;
|
||||
bool found;
|
||||
};
|
||||
|
||||
bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
|
||||
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
|
||||
|
||||
|
@ -697,6 +706,24 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool findShapeCollisionsOp(OctreeElement* node, void* extraData) {
|
||||
const ShapeArgs* args = static_cast<ShapeArgs*>(extraData);
|
||||
|
||||
// coarse check against bounds
|
||||
AABox box = node->getAABox();
|
||||
box.scale(TREE_SCALE);
|
||||
if (!box.expandedContains(args->shape->getPosition(), args->shape->getBoundingRadius())) {
|
||||
return false;
|
||||
}
|
||||
if (!node->isLeaf()) {
|
||||
return true; // recurse on children
|
||||
}
|
||||
if (node->hasContent()) {
|
||||
return ShapeCollider::collideShapeWithBox(args->shape, box, args->collisions);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||
glm::vec3& penetration, Octree::lockType lockType) {
|
||||
|
||||
|
@ -727,6 +754,31 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end
|
|||
return args.found;
|
||||
}
|
||||
|
||||
bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions, Octree::lockType lockType) {
|
||||
|
||||
ShapeArgs args = { shape,
|
||||
collisions,
|
||||
false };
|
||||
|
||||
bool gotLock = false;
|
||||
if (lockType == Octree::Lock) {
|
||||
lockForRead();
|
||||
gotLock = true;
|
||||
} else if (lockType == Octree::TryLock) {
|
||||
gotLock = tryLockForRead();
|
||||
if (!gotLock) {
|
||||
return args.found; // if we wanted to tryLock, and we couldn't then just bail...
|
||||
}
|
||||
}
|
||||
|
||||
recurseTreeWithOperation(findShapeCollisionsOp, &args);
|
||||
|
||||
if (gotLock) {
|
||||
unlock();
|
||||
}
|
||||
return args.found;
|
||||
}
|
||||
|
||||
class GetElementEnclosingArgs {
|
||||
public:
|
||||
OctreeElement* element;
|
||||
|
|
|
@ -21,6 +21,7 @@ class Octree;
|
|||
class OctreeElement;
|
||||
class OctreeElementBag;
|
||||
class OctreePacketData;
|
||||
class Shape;
|
||||
|
||||
|
||||
#include "JurisdictionMap.h"
|
||||
|
@ -30,6 +31,8 @@ class OctreePacketData;
|
|||
#include "OctreePacketData.h"
|
||||
#include "OctreeSceneStats.h"
|
||||
|
||||
#include <CollisionInfo.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
|
||||
|
@ -246,6 +249,8 @@ public:
|
|||
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||
glm::vec3& penetration, Octree::lockType lockType = Octree::TryLock);
|
||||
|
||||
bool findShapeCollisions(const Shape* shape, CollisionList& collisions, Octree::lockType = Octree::TryLock);
|
||||
|
||||
OctreeElement* getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType = Octree::TryLock);
|
||||
|
||||
// Note: this assumes the fileFormat is the HIO individual voxels code files
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <NodeList.h>
|
||||
#include <PerfStat.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "AABox.h"
|
||||
#include "OctalCode.h"
|
||||
#include "SharedUtil.h"
|
||||
#include "OctreeConstants.h"
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
#include <QReadWriteLock>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <SharedUtil.h>
|
||||
#include "AABox.h"
|
||||
|
||||
#include "ViewFrustum.h"
|
||||
#include "OctreeConstants.h"
|
||||
//#include "Octree.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include "AABox.h"
|
||||
#include <AABox.h>
|
||||
#include "Plane.h"
|
||||
|
||||
#include "OctreeConstants.h"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// AABox.cpp
|
||||
// libraries/octree/src
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 04/11/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// AABox.h
|
||||
// libraries/octree/src
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 04/11/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
|
@ -92,6 +92,11 @@ bool collideShapesCoarse(const QVector<const Shape*>& shapesA, const QVector<con
|
|||
return false;
|
||||
}
|
||||
|
||||
bool collideShapeWithBox(const Shape* shapeA, const AABox& boxB, CollisionList& collisions) {
|
||||
// TODO: Andrew to implement this
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sphereSphere(const SphereShape* sphereA, const SphereShape* sphereB, CollisionList& collisions) {
|
||||
glm::vec3 BA = sphereB->getPosition() - sphereA->getPosition();
|
||||
float distanceSquared = glm::dot(BA, BA);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#ifndef hifi_ShapeCollider_h
|
||||
#define hifi_ShapeCollider_h
|
||||
|
||||
#include "AABox.h"
|
||||
#include "CapsuleShape.h"
|
||||
#include "CollisionInfo.h"
|
||||
#include "ListShape.h"
|
||||
|
@ -33,6 +34,12 @@ namespace ShapeCollider {
|
|||
/// \return true if any shapes collide
|
||||
bool collideShapesCoarse(const QVector<const Shape*>& shapesA, const QVector<const Shape*>& shapesB, CollisionInfo& collision);
|
||||
|
||||
/// \param shapeA a pointer to a shape
|
||||
/// \param boxB an axis aligned box
|
||||
/// \param collisions[out] average collision details
|
||||
/// \return true if shapeA collides with boxB
|
||||
bool collideShapeWithBox(const Shape* shapeA, const AABox& boxB, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to first shape
|
||||
/// \param sphereB pointer to second shape
|
||||
/// \param[out] collisions where to append collision details
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
#include <QReadWriteLock>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <OctreeElement.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "AABox.h"
|
||||
#include "ViewFrustum.h"
|
||||
#include "VoxelConstants.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue