mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 18:26:26 +02:00
first cut at shape collisions
This commit is contained in:
parent
9cc1fe35db
commit
eda168a6d9
5 changed files with 50 additions and 8 deletions
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
|
#include <AACubeShape.h>
|
||||||
|
#include <ShapeCollider.h>
|
||||||
|
|
||||||
#include <FBXReader.h>
|
#include <FBXReader.h>
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
|
|
||||||
|
@ -546,6 +549,33 @@ bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float rad
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EntityTreeElement::findShapeCollisions(const Shape* shape, CollisionList& collisions) const {
|
||||||
|
bool atLeastOneCollision = false;
|
||||||
|
//AACube cube = getAACube();
|
||||||
|
//return ShapeCollider::collideShapeWithAACubeLegacy(shape, cube.calcCenter(), cube.getScale(), collisions);
|
||||||
|
|
||||||
|
QList<EntityItem*>::iterator entityItr = _entityItems->begin();
|
||||||
|
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
||||||
|
while(entityItr != entityEnd) {
|
||||||
|
EntityItem* entity = (*entityItr);
|
||||||
|
glm::vec3 entityCenter = entity->getPosition();
|
||||||
|
float entityRadius = entity->getRadius();
|
||||||
|
|
||||||
|
// don't collide with yourself???
|
||||||
|
//if (entityCenter == center && entityRadius == radius) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
AACube entityAACube = entity->getMinimumAACube();
|
||||||
|
AACubeShape aaCube(entityAACube.getScale(), entityAACube.calcCenter());
|
||||||
|
|
||||||
|
if (ShapeCollider::collideShapes(shape, &aaCube, collisions)) {
|
||||||
|
atLeastOneCollision = true;
|
||||||
|
}
|
||||||
|
++entityItr;
|
||||||
|
}
|
||||||
|
return atLeastOneCollision;
|
||||||
|
}
|
||||||
|
|
||||||
void EntityTreeElement::updateEntityItemID(const EntityItemID& creatorTokenEntityID, const EntityItemID& knownIDEntityID) {
|
void EntityTreeElement::updateEntityItemID(const EntityItemID& creatorTokenEntityID, const EntityItemID& knownIDEntityID) {
|
||||||
uint16_t numberOfEntities = _entityItems->size();
|
uint16_t numberOfEntities = _entityItems->size();
|
||||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||||
|
|
|
@ -142,6 +142,8 @@ public:
|
||||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const;
|
glm::vec3& penetration, void** penetratedObject) const;
|
||||||
|
|
||||||
|
virtual bool findShapeCollisions(const Shape* shape, CollisionList& collisions) const;
|
||||||
|
|
||||||
const QList<EntityItem*>& getEntities() const { return *_entityItems; }
|
const QList<EntityItem*>& getEntities() const { return *_entityItems; }
|
||||||
QList<EntityItem*>& getEntities() { return *_entityItems; }
|
QList<EntityItem*>& getEntities() { return *_entityItems; }
|
||||||
bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; }
|
bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; }
|
||||||
|
|
|
@ -817,9 +817,6 @@ bool findCapsulePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
if (!box.expandedIntersectsSegment(args->start, args->end, args->radius)) {
|
if (!box.expandedIntersectsSegment(args->start, args->end, args->radius)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!element->isLeaf()) {
|
|
||||||
return true; // recurse on children
|
|
||||||
}
|
|
||||||
if (element->hasContent()) {
|
if (element->hasContent()) {
|
||||||
glm::vec3 nodePenetration;
|
glm::vec3 nodePenetration;
|
||||||
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
|
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
|
||||||
|
@ -827,6 +824,9 @@ bool findCapsulePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
args->found = true;
|
args->found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!element->isLeaf()) {
|
||||||
|
return true; // recurse on children
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,15 +839,15 @@ bool findShapeCollisionsOp(OctreeElement* element, void* extraData) {
|
||||||
if (!cube.expandedContains(args->shape->getTranslation(), args->shape->getBoundingRadius())) {
|
if (!cube.expandedContains(args->shape->getTranslation(), args->shape->getBoundingRadius())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!element->isLeaf()) {
|
|
||||||
return true; // recurse on children
|
|
||||||
}
|
|
||||||
if (element->hasContent()) {
|
if (element->hasContent()) {
|
||||||
if (ShapeCollider::collideShapeWithAACubeLegacy(args->shape, cube.calcCenter(), cube.getScale(), args->collisions)) {
|
if (element->findShapeCollisions(args->shape, args->collisions)) {
|
||||||
args->found = true;
|
args->found = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!element->isLeaf()) {
|
||||||
|
return true; // recurse on children
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -17,7 +18,8 @@
|
||||||
|
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
#include <assert.h>
|
#include <AACubeShape.h>
|
||||||
|
#include <ShapeCollider.h>
|
||||||
|
|
||||||
#include "AACube.h"
|
#include "AACube.h"
|
||||||
#include "OctalCode.h"
|
#include "OctalCode.h"
|
||||||
|
@ -1369,6 +1371,10 @@ bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
return _cube.findSpherePenetration(center, radius, penetration);
|
return _cube.findSpherePenetration(center, radius, penetration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OctreeElement::findShapeCollisions(const Shape* shape, CollisionList& collisions) const {
|
||||||
|
AACube cube = getAACube();
|
||||||
|
return ShapeCollider::collideShapeWithAACubeLegacy(shape, cube.calcCenter(), cube.getScale(), collisions);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: consider removing this, or switching to using getOrCreateChildElementContaining(const AACube& box)...
|
// TODO: consider removing this, or switching to using getOrCreateChildElementContaining(const AACube& box)...
|
||||||
OctreeElement* OctreeElement::getOrCreateChildElementAt(float x, float y, float z, float s) {
|
OctreeElement* OctreeElement::getOrCreateChildElementAt(float x, float y, float z, float s) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "ViewFrustum.h"
|
#include "ViewFrustum.h"
|
||||||
#include "OctreeConstants.h"
|
#include "OctreeConstants.h"
|
||||||
|
|
||||||
|
class CollisionList;
|
||||||
class EncodeBitstreamParams;
|
class EncodeBitstreamParams;
|
||||||
class Octree;
|
class Octree;
|
||||||
class OctreeElement;
|
class OctreeElement;
|
||||||
|
@ -32,6 +33,7 @@ class OctreeElementBag;
|
||||||
class OctreeElementDeleteHook;
|
class OctreeElementDeleteHook;
|
||||||
class OctreePacketData;
|
class OctreePacketData;
|
||||||
class ReadBitstreamToTreeParams;
|
class ReadBitstreamToTreeParams;
|
||||||
|
class Shape;
|
||||||
class VoxelSystem;
|
class VoxelSystem;
|
||||||
|
|
||||||
const float SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE = (1.0f / TREE_SCALE) / 10000.0f; // 1/10,000th of a meter
|
const float SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE = (1.0f / TREE_SCALE) / 10000.0f; // 1/10,000th of a meter
|
||||||
|
@ -128,6 +130,8 @@ public:
|
||||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const;
|
glm::vec3& penetration, void** penetratedObject) const;
|
||||||
|
|
||||||
|
virtual bool findShapeCollisions(const Shape* shape, CollisionList& collisions) const;
|
||||||
|
|
||||||
// Base class methods you don't need to implement
|
// Base class methods you don't need to implement
|
||||||
const unsigned char* getOctalCode() const { return (_octcodePointer) ? _octalCode.pointer : &_octalCode.buffer[0]; }
|
const unsigned char* getOctalCode() const { return (_octcodePointer) ? _octalCode.pointer : &_octalCode.buffer[0]; }
|
||||||
OctreeElement* getChildAtIndex(int childIndex) const;
|
OctreeElement* getChildAtIndex(int childIndex) const;
|
||||||
|
|
Loading…
Reference in a new issue