Using EntityItemIDs instead of QUuids

This commit is contained in:
ericrius1 2015-10-20 09:22:16 -07:00
parent dcb37ccd73
commit 0373a481f8
10 changed files with 30 additions and 14 deletions

View file

@ -482,7 +482,7 @@ void EntityTreeRenderer::deleteReleasedModels() {
} }
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
bool precisionPicking, const QVector<QUuid>& entityIdsToInclude) { bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude) {
RayToEntityIntersectionResult result; RayToEntityIntersectionResult result;
if (_tree) { if (_tree) {
EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree); EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree);

View file

@ -130,7 +130,7 @@ private:
QList<Model*> _releasedModels; QList<Model*> _releasedModels;
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
bool precisionPicking, const QVector<QUuid>& entityIdsToInclude = QVector<QUuid>()); bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude = QVector<EntityItemID>());
EntityItemID _currentHoverOverEntityID; EntityItemID _currentHoverOverEntityID;
EntityItemID _currentClickingOnEntityID; EntityItemID _currentClickingOnEntityID;

View file

@ -280,18 +280,18 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn
} }
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) { RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) {
QVector<QUuid> entities = qVectorQUuidFromScriptValue(entityIdsToInclude); QVector<EntityItemID> entities = qVectorEntityItemIDFromScriptValue(entityIdsToInclude);
return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking, entities); return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking, entities);
} }
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) { RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) {
const QVector<QUuid>& entities = qVectorQUuidFromScriptValue(entityIdsToInclude); const QVector<EntityItemID>& entities = qVectorEntityItemIDFromScriptValue(entityIdsToInclude);
return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entities); return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entities);
} }
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
Octree::lockType lockType, Octree::lockType lockType,
bool precisionPicking, const QVector<QUuid>& entityIdsToInclude) { bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude) {
RayToEntityIntersectionResult result; RayToEntityIntersectionResult result;

View file

@ -186,7 +186,7 @@ private:
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
bool precisionPicking, const QVector<QUuid>& entityIdsToInclude); bool precisionPicking, const QVector<EntityItemID>& entityIdsToInclude);
EntityTreePointer _entityTree; EntityTreePointer _entityTree;
EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr; EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr;

View file

@ -457,7 +457,7 @@ public:
float& distance; float& distance;
BoxFace& face; BoxFace& face;
glm::vec3& surfaceNormal; glm::vec3& surfaceNormal;
const QVector<QUuid>& entityIdsToInclude; const QVector<EntityItemID>& entityIdsToInclude;
void** intersectedObject; void** intersectedObject;
bool found; bool found;
bool precisionPicking; bool precisionPicking;
@ -478,7 +478,7 @@ bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) {
bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
OctreeElementPointer& element, float& distance, OctreeElementPointer& element, float& distance,
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, void** intersectedObject, BoxFace& face, glm::vec3& surfaceNormal, const QVector<EntityItemID>& entityIdsToInclude, void** intersectedObject,
Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { Octree::lockType lockType, bool* accurateResult, bool precisionPicking) {
RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking }; RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking };
distance = FLT_MAX; distance = FLT_MAX;

View file

@ -82,7 +82,7 @@ public:
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal,
const QVector<QUuid>& entityIdsToInclude = QVector<QUuid>(), const QVector<EntityItemID>& entityIdsToInclude = QVector<EntityItemID>(),
void** intersectedObject = NULL, void** intersectedObject = NULL,
Octree::lockType lockType = Octree::TryLock, Octree::lockType lockType = Octree::TryLock,
bool* accurateResult = NULL, bool* accurateResult = NULL,

View file

@ -495,7 +495,7 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3
bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElementPointer& element, float& distance, bool& keepSearching, OctreeElementPointer& element, float& distance,
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, BoxFace& face, glm::vec3& surfaceNormal, const QVector<EntityItemID>& entityIdsToInclude,
void** intersectedObject, bool precisionPicking) { void** intersectedObject, bool precisionPicking) {
keepSearching = true; // assume that we will continue searching after this. keepSearching = true; // assume that we will continue searching after this.
@ -536,7 +536,7 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching,
OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal,
const QVector<QUuid>& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { const QVector<EntityItemID>& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube) {
// only called if we do intersect our bounding cube, but find if we actually intersect with entities... // only called if we do intersect our bounding cube, but find if we actually intersect with entities...
int entityNumber = 0; int entityNumber = 0;

View file

@ -144,11 +144,11 @@ public:
virtual bool canRayIntersect() const { return hasEntities(); } virtual bool canRayIntersect() const { return hasEntities(); }
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElementPointer& node, float& distance, bool& keepSearching, OctreeElementPointer& node, float& distance,
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, BoxFace& face, glm::vec3& surfaceNormal, const QVector<EntityItemID>& entityIdsToInclude,
void** intersectedObject = NULL, bool precisionPicking = false); void** intersectedObject = NULL, bool precisionPicking = false);
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElementPointer& element, float& distance, bool& keepSearching, OctreeElementPointer& element, float& distance,
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, BoxFace& face, glm::vec3& surfaceNormal, const QVector<EntityItemID>& entityIdsToInclude,
void** intersectedObject, bool precisionPicking, float distanceToElementCube); void** intersectedObject, bool precisionPicking, float distanceToElementCube);
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;

View file

@ -13,7 +13,6 @@
#include <QUrl> #include <QUrl>
#include <QUuid> #include <QUuid>
#include <QRect> #include <QRect>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include "RegisteredMetaTypes.h" #include "RegisteredMetaTypes.h"
@ -119,6 +118,21 @@ QVector<QUuid> qVectorQUuidFromScriptValue(const QScriptValue& array) {
return newVector; return newVector;
} }
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& array) {
if (!array.isArray()) {
return QVector<EntityItemID>();
}
QVector<EntityItemID> newVector;
int length = array.property("length").toInteger();
newVector.reserve(length);
for (int i = 0; i < length; i++) {
QString uuidAsString = array.property(i).toString();
EntityItemID fromString(uuidAsString);
newVector << fromString;
}
return newVector;
}
QScriptValue qVectorFloatToScriptValue(QScriptEngine* engine, const QVector<float>& vector) { QScriptValue qVectorFloatToScriptValue(QScriptEngine* engine, const QVector<float>& vector) {
QScriptValue array = engine->newArray(); QScriptValue array = engine->newArray();
for (int i = 0; i < vector.size(); i++) { for (int i = 0; i < vector.size(); i++) {

View file

@ -14,6 +14,7 @@
#include <QtScript/QScriptEngine> #include <QtScript/QScriptEngine>
#include <QtCore/QUuid> #include <QtCore/QUuid>
#include "../../entities/src/EntityItemID.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
@ -66,6 +67,7 @@ void qVectorFloatFromScriptValue(const QScriptValue& array, QVector<float>& vect
QVector<float> qVectorFloatFromScriptValue(const QScriptValue& array); QVector<float> qVectorFloatFromScriptValue(const QScriptValue& array);
QVector<QUuid> qVectorQUuidFromScriptValue(const QScriptValue& array); QVector<QUuid> qVectorQUuidFromScriptValue(const QScriptValue& array);
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& array);
class PickRay { class PickRay {
public: public: