Move AABox from octree lib to shared lib

Stubbed out Shape vs Octree collisions
This commit is contained in:
Andrew Meadows 2014-04-21 10:27:20 -07:00
parent 57a221f343
commit 241df7a767
10 changed files with 79 additions and 9 deletions

View file

@ -20,18 +20,20 @@
#include <QDebug> #include <QDebug>
#include "CoverageMap.h"
#include <GeometryUtil.h> #include <GeometryUtil.h>
#include "OctalCode.h" #include <OctalCode.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <Shape.h>
#include <ShapeCollider.h>
//#include "Tags.h" //#include "Tags.h"
#include "ViewFrustum.h" #include "CoverageMap.h"
#include "OctreeConstants.h" #include "OctreeConstants.h"
#include "OctreeElementBag.h" #include "OctreeElementBag.h"
#include "Octree.h" #include "Octree.h"
#include "ViewFrustum.h"
float boundaryDistanceForRenderLevel(unsigned int renderLevel, float voxelSizeScale) { float boundaryDistanceForRenderLevel(unsigned int renderLevel, float voxelSizeScale) {
return voxelSizeScale / powf(2, renderLevel); return voxelSizeScale / powf(2, renderLevel);
@ -676,6 +678,13 @@ public:
bool found; bool found;
}; };
class ShapeArgs {
public:
const Shape* shape;
CollisionList& collisions;
bool found;
};
bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) { bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData); CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
@ -697,6 +706,24 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
return false; 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, bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
glm::vec3& penetration, Octree::lockType lockType) { glm::vec3& penetration, Octree::lockType lockType) {
@ -727,6 +754,31 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end
return args.found; 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 { class GetElementEnclosingArgs {
public: public:
OctreeElement* element; OctreeElement* element;

View file

@ -21,6 +21,7 @@ class Octree;
class OctreeElement; class OctreeElement;
class OctreeElementBag; class OctreeElementBag;
class OctreePacketData; class OctreePacketData;
class Shape;
#include "JurisdictionMap.h" #include "JurisdictionMap.h"
@ -30,6 +31,8 @@ class OctreePacketData;
#include "OctreePacketData.h" #include "OctreePacketData.h"
#include "OctreeSceneStats.h" #include "OctreeSceneStats.h"
#include <CollisionInfo.h>
#include <QObject> #include <QObject>
#include <QReadWriteLock> #include <QReadWriteLock>
@ -246,6 +249,8 @@ public:
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
glm::vec3& penetration, Octree::lockType lockType = Octree::TryLock); 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); OctreeElement* getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType = Octree::TryLock);
// Note: this assumes the fileFormat is the HIO individual voxels code files // Note: this assumes the fileFormat is the HIO individual voxels code files

View file

@ -15,11 +15,11 @@
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <AABox.h>
#include <NodeList.h> #include <NodeList.h>
#include <PerfStat.h> #include <PerfStat.h>
#include <assert.h> #include <assert.h>
#include "AABox.h"
#include "OctalCode.h" #include "OctalCode.h"
#include "SharedUtil.h" #include "SharedUtil.h"
#include "OctreeConstants.h" #include "OctreeConstants.h"

View file

@ -18,8 +18,9 @@
#include <QReadWriteLock> #include <QReadWriteLock>
#include <AABox.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include "AABox.h"
#include "ViewFrustum.h" #include "ViewFrustum.h"
#include "OctreeConstants.h" #include "OctreeConstants.h"
//#include "Octree.h" //#include "Octree.h"

View file

@ -17,7 +17,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include "AABox.h" #include <AABox.h>
#include "Plane.h" #include "Plane.h"
#include "OctreeConstants.h" #include "OctreeConstants.h"

View file

@ -1,6 +1,6 @@
// //
// AABox.cpp // AABox.cpp
// libraries/octree/src // libraries/shared/src
// //
// Created by Brad Hefta-Gaub on 04/11/13. // Created by Brad Hefta-Gaub on 04/11/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.

View file

@ -1,6 +1,6 @@
// //
// AABox.h // AABox.h
// libraries/octree/src // libraries/shared/src
// //
// Created by Brad Hefta-Gaub on 04/11/13. // Created by Brad Hefta-Gaub on 04/11/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.

View file

@ -92,6 +92,11 @@ bool collideShapesCoarse(const QVector<const Shape*>& shapesA, const QVector<con
return false; 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) { bool sphereSphere(const SphereShape* sphereA, const SphereShape* sphereB, CollisionList& collisions) {
glm::vec3 BA = sphereB->getPosition() - sphereA->getPosition(); glm::vec3 BA = sphereB->getPosition() - sphereA->getPosition();
float distanceSquared = glm::dot(BA, BA); float distanceSquared = glm::dot(BA, BA);

View file

@ -12,6 +12,7 @@
#ifndef hifi_ShapeCollider_h #ifndef hifi_ShapeCollider_h
#define hifi_ShapeCollider_h #define hifi_ShapeCollider_h
#include "AABox.h"
#include "CapsuleShape.h" #include "CapsuleShape.h"
#include "CollisionInfo.h" #include "CollisionInfo.h"
#include "ListShape.h" #include "ListShape.h"
@ -33,6 +34,12 @@ namespace ShapeCollider {
/// \return true if any shapes collide /// \return true if any shapes collide
bool collideShapesCoarse(const QVector<const Shape*>& shapesA, const QVector<const Shape*>& shapesB, CollisionInfo& collision); 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 sphereA pointer to first shape
/// \param sphereB pointer to second shape /// \param sphereB pointer to second shape
/// \param[out] collisions where to append collision details /// \param[out] collisions where to append collision details

View file

@ -18,10 +18,10 @@
#include <QReadWriteLock> #include <QReadWriteLock>
#include <AABox.h>
#include <OctreeElement.h> #include <OctreeElement.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include "AABox.h"
#include "ViewFrustum.h" #include "ViewFrustum.h"
#include "VoxelConstants.h" #include "VoxelConstants.h"