From 1fec69698ec66db629413af7b1288737fb7715a6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 5 Dec 2014 23:23:21 -0800 Subject: [PATCH] get the triangle picking for submeshes working, remove some debug --- .../entities/RenderableModelEntityItem.cpp | 16 +- interface/src/renderer/Model.cpp | 200 ++++++++++-------- interface/src/renderer/Model.h | 1 + libraries/entities/src/EntityTreeElement.cpp | 44 ++-- libraries/octree/src/OctreeElement.cpp | 34 +-- libraries/shared/src/GeometryUtil.cpp | 8 +- 6 files changed, 169 insertions(+), 134 deletions(-) diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index e2fd50ceee..37efeb98ee 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -174,7 +174,9 @@ void RenderableModelEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("model->render"); bool dontRenderAsScene = true; // Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene); if (dontRenderAsScene) { - _model->render(alpha, modelRenderMode, args); + if (!_model->renderTriangleProxies()) { + _model->render(alpha, modelRenderMode, args); + } } else { _model->renderInScene(alpha, args); } @@ -261,12 +263,12 @@ bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& ori bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject) const { - qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection()...."; - qDebug() << " this.id:" << getEntityItemID(); - qDebug() << " this.modelURL:" << getModelURL(); - qDebug() << " origin:" << origin; + //qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection()...."; + //qDebug() << " this.id:" << getEntityItemID(); + //qDebug() << " this.modelURL:" << getModelURL(); + //qDebug() << " origin:" << origin; glm::vec3 originInMeters = origin * (float)TREE_SCALE; - qDebug() << " originInMeters:" << originInMeters; + //qDebug() << " originInMeters:" << originInMeters; QString extraInfo; float localDistance; @@ -276,7 +278,7 @@ bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& ori // NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return // results in tree scale. distance = localDistance / (float)TREE_SCALE; - qDebug() << " --hit this mode -- returning distance:" << distance; + //qDebug() << " --hit this mode -- returning distance:" << distance; } return intersectsModel; // we only got here if we intersected our non-aabox diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 3606a17cf8..8f684440da 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -516,6 +516,61 @@ void Model::setJointStates(QVector states) { _boundingRadius = radius; } +bool Model::renderTriangleProxies() { + if (!isActive()) { + return false; + } + if (_calculatedMeshTrianglesValid) { + int color = 0; + foreach (const QVector& meshTriangles, _calculatedMeshTriangles) { + switch(color) { + case 0: glColor3ub( 0, 0, 255); break; + case 1: glColor3ub( 0, 255, 0); break; + case 2: glColor3ub( 0, 255, 255); break; + case 3: glColor3ub(255, 0, 0); break; + case 4: glColor3ub(255, 0, 255); break; + case 5: glColor3ub(255, 255, 0); break; + case 6: glColor3ub( 0, 0, 128); break; + case 7: glColor3ub( 0, 128, 0); break; + case 8: glColor3ub( 0, 128, 128); break; + case 9: glColor3ub(128, 0, 0); break; + case 10: glColor3ub(128, 0, 128); break; + case 11: glColor3ub(128, 128, 0); break; + case 12: glColor3ub(128, 128, 255); break; + case 13: glColor3ub(128, 255, 128); break; + case 14: glColor3ub(128, 255, 255); break; + case 15: glColor3ub(255, 128, 128); break; + case 16: glColor3ub(255, 128, 255); break; + case 17: glColor3ub(255, 255, 128); break; + default: glColor3ub(255,255, 255); break; + } + + if (_calculatedMeshBoxes.size() > color) { + const AABox& box = _calculatedMeshBoxes[color]; + glm::vec3 center = box.calcCenter(); + glm::vec3 dimensions = box.getDimensions(); + glPushMatrix(); + glTranslatef(center.x, center.y, center.z); + glScalef(dimensions.x, dimensions.y, dimensions.z); + Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f); + glPopMatrix(); + } + + + glBegin(GL_TRIANGLES); + foreach (const Triangle& triangle, meshTriangles) { + //qDebug() << "triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2; + glVertex3f( triangle.v0.x, triangle.v0.y, triangle.v0.z); + glVertex3f( triangle.v1.x, triangle.v1.y, triangle.v1.z); + glVertex3f( triangle.v2.x, triangle.v2.y, triangle.v2.z); + } + glEnd(); + color++; + } + } + return _calculatedMeshTrianglesValid; +} + bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, QString& extraInfo) { @@ -528,9 +583,9 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g bool pickAgainstTriangles = Menu::getInstance()->isOptionChecked(MenuOption::PickAgainstModelTriangles); - qDebug() << "Model::findRayIntersectionAgainstSubMeshes()..."; - qDebug() << " origin:" << origin; - qDebug() << " direction:" << direction; + //qDebug() << "Model::findRayIntersectionAgainstSubMeshes()..."; + //qDebug() << " origin:" << origin; + //qDebug() << " direction:" << direction; // extents is the entity relative, scaled, centered extents of the entity glm::vec3 position = _translation; @@ -540,24 +595,24 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix); Extents modelExtents = getMeshExtents(); // NOTE: unrotated - qDebug() << " modelExtents:" << modelExtents; + //qDebug() << " modelExtents:" << modelExtents; glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum; glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference AABox modelFrameBox(corner, dimensions); - qDebug() << " modelFrameBox:" << modelFrameBox; + //qDebug() << " modelFrameBox:" << modelFrameBox; glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f)); glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f)); - qDebug() << " modelFrameOrigin:" << modelFrameOrigin; - qDebug() << " modelFrameDirection:" << modelFrameDirection; + //qDebug() << " modelFrameOrigin:" << modelFrameOrigin; + //qDebug() << " modelFrameDirection:" << modelFrameDirection; // we can use the AABox's ray intersection by mapping our origin and direction into the model frame // and testing intersection there. if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) { - qDebug() << " modelFrameBox.findRayIntersection() HITS!!!"; + //qDebug() << " modelFrameBox.findRayIntersection() HITS!!!"; float bestDistance = std::numeric_limits::max(); float bestTriangleDistance = std::numeric_limits::max(); @@ -569,22 +624,23 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g const FBXGeometry& geometry = _geometry->getFBXGeometry(); - qDebug() << " Checking mesh boxes...."; - + //qDebug() << " Checking mesh boxes...."; + // If we hit the models box, then consider the submeshes... foreach(const AABox& subMeshBox, _calculatedMeshBoxes) { - qDebug() << " subMeshBox[" << subMeshIndex <<"]:" << subMeshBox; + //qDebug() << " subMeshBox[" << subMeshIndex <<"]:" << subMeshBox; if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) { - qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() HITS!"; - qDebug() << " subMeshBox[" << subMeshIndex <<"].distanceToSubMesh:" << distanceToSubMesh; - qDebug() << " bestDistance:" << bestDistance; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() HITS!"; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].distanceToSubMesh:" << distanceToSubMesh; + //qDebug() << " bestDistance:" << bestDistance; if (distanceToSubMesh < bestDistance) { - qDebug() << " distanceToSubMesh < bestDistance !! looks like a good match!"; + //qDebug() << " distanceToSubMesh < bestDistance !! looks like a good match!"; if (pickAgainstTriangles) { - qDebug() << " subMeshBox[" << subMeshIndex <<"] --- check triangles!!"; + someTriangleHit = false; + //qDebug() << " subMeshBox[" << subMeshIndex <<"] --- check triangles!!"; if (!_calculatedMeshTrianglesValid) { recalcuateMeshBoxes(); } @@ -592,93 +648,59 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g const QVector& meshTriangles = _calculatedMeshTriangles[subMeshIndex]; int t = 0; foreach (const Triangle& triangle, meshTriangles) { - //qDebug() << "triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2; + //qDebug() << "checking triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2; t++; float thisTriangleDistance; if (findRayTrianlgeIntersection(origin, direction, triangle, thisTriangleDistance)) { - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- HITS!!"; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] thisTriangleDistance:" << thisTriangleDistance; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] bestTriangleDistance:" << bestTriangleDistance; - if (thisTriangleDistance < bestTriangleDistance) { + //qDebug() << "---- HIT triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2 << " -----"; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- HITS!!"; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] thisTriangleDistance:" << thisTriangleDistance; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] bestTriangleDistance:" << bestTriangleDistance; + if (thisTriangleDistance < bestDistance) { bestTriangleDistance = thisTriangleDistance; someTriangleHit = true; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- WOOT! BEST DISTANCE!"; + + bestDistance = thisTriangleDistance; + intersectedSomething = true; + face = subMeshFace; + extraInfo = geometry.getModelNameOfMesh(subMeshIndex); + + //qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- WOOT! BEST DISTANCE!"; } else { - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- not best distance???"; + //qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- not best distance???"; } } } + } else { + // this is the non-triangle picking case... + bestDistance = distanceToSubMesh; + intersectedSomething = true; + face = subMeshFace; + extraInfo = geometry.getModelNameOfMesh(subMeshIndex); } - - bestDistance = distanceToSubMesh; - intersectedSomething = true; - face = subMeshFace; - extraInfo = geometry.getModelNameOfMesh(subMeshIndex); } else { - qDebug() << " distanceToSubMesh >= bestDistance !! TOO FAR AWAY!"; + //qDebug() << " distanceToSubMesh >= bestDistance !! TOO FAR AWAY!"; } - } else { - // TODO: this needs to be deleted... there shouldn't be any reason to run this here... if the mesh's bounding box - // doesn't intersect, then how can any of it's triangles!!!! - - qDebug() << " subMeshBox[" << subMeshIndex <<"].findRayIntersection() MISSES???"; - if (pickAgainstTriangles) { - qDebug() << " subMeshBox[" << subMeshIndex <<"] --- check triangles anyway!!"; - if (!_calculatedMeshTrianglesValid) { - recalcuateMeshBoxes(); - } - // check our triangles here.... - const QVector& meshTriangles = _calculatedMeshTriangles[subMeshIndex]; - int t = 0; - foreach (const Triangle& triangle, meshTriangles) { - //qDebug() << "triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2; - t++; - - float thisTriangleDistance; - if (findRayTrianlgeIntersection(origin, direction, triangle, thisTriangleDistance)) { - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- HITS!!"; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] thisTriangleDistance:" << thisTriangleDistance; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] bestTriangleDistance:" << bestTriangleDistance; - if (thisTriangleDistance < bestTriangleDistance) { - bestTriangleDistance = thisTriangleDistance; - someTriangleHit = true; - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- WOOT! BEST DISTANCE!"; - } else { - qDebug() << " subMeshBox[" << subMeshIndex <<"].triangle[" << t <<"] --- not best distance???"; - } - } - } - } - } + } subMeshIndex++; } - // if we were asked to pick against triangles, and we didn't hit one, then we - // do not consider this model to be hit at all. - if (pickAgainstTriangles && !someTriangleHit) { - qDebug() << "pickAgainstTriangles && !someTriangleHit --- call it a NON-HIT!"; - intersectedSomething = false; - } - qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles; - qDebug() << "someTriangleHit:" << someTriangleHit; - qDebug() << "bestTriangleDistance:" << bestTriangleDistance; - qDebug() << "bestDistance:" << bestDistance; + //qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles; + //qDebug() << "someTriangleHit:" << someTriangleHit; + //qDebug() << "bestTriangleDistance:" << bestTriangleDistance; + //qDebug() << "bestDistance:" << bestDistance; + //qDebug() << "intersectedSomething:" << intersectedSomething; if (intersectedSomething) { - qDebug() << " --- we hit this model --- "; - - if (pickAgainstTriangles) { - distance = bestTriangleDistance; - } else { - distance = bestDistance; - } - qDebug() << "distance:" << distance; + //qDebug() << " --- we hit this model --- "; + distance = bestDistance; + //qDebug() << "distance:" << distance; } return intersectedSomething; } else { - qDebug() << "modelFrameBox.findRayIntersection()... DID NOT INTERSECT..."; + //qDebug() << "modelFrameBox.findRayIntersection()... DID NOT INTERSECT..."; } return intersectedSomething; @@ -689,12 +711,14 @@ void Model::recalcuateMeshBoxes() { bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid; if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) { - qDebug() << "Model::recalcuateMeshBoxes()"; + qDebug() << "************************************************************************************************"; + qDebug() << "Model::recalcuateMeshBoxes() -------------------------------------------------------------------"; PerformanceTimer perfTimer("calculatedMeshBoxes"); const FBXGeometry& geometry = _geometry->getFBXGeometry(); int numberOfMeshes = geometry.meshes.size(); _calculatedMeshBoxes.resize(numberOfMeshes); _calculatedMeshTriangles.clear(); + _calculatedMeshTriangles.resize(numberOfMeshes); for (int i = 0; i < numberOfMeshes; i++) { const FBXMesh& mesh = geometry.meshes.at(i); Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents); @@ -731,8 +755,14 @@ void Model::recalcuateMeshBoxes() { glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f))); glm::vec3 v3 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i3], 1.0f))); - Triangle tri1 = { v0, v1, v3 }; - Triangle tri2 = { v1, v2, v3 }; + // Sam's + //Triangle tri1 = { v0, v1, v3 }; + //Triangle tri2 = { v1, v2, v3 }; + + // triangle 0 1 2 + // triangle 2 3 0 + Triangle tri1 = { v0, v1, v2 }; + Triangle tri2 = { v2, v3, v0 }; //qDebug() << "quad["<< q <<"].t1 :" << v0 << ", "<< v1 << ", " << v3; //qDebug() << "quad["<< q <<"].t2 :" << v1 << ", "<< v2 << ", " << v3; @@ -764,7 +794,7 @@ void Model::recalcuateMeshBoxes() { } } - _calculatedMeshTriangles.push_back(thisMeshTriangles); + _calculatedMeshTriangles[i] = thisMeshTriangles; qDebug() << "------------------------------------------------------------------------------"; } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 406622e6a8..4145b7b3d9 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -89,6 +89,7 @@ public: enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE }; bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL); + bool renderTriangleProxies(); // Scene rendering support static void startScene(RenderArgs::RenderSide renderSide); diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index aea278adf6..ac65245f4b 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -479,10 +479,10 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con // only called if we do intersect our bounding cube, but find if we actually intersect with entities... - qDebug() << "EntityTreeElement::findDetailedRayIntersection()...."; - qDebug() << " origin:" << origin; - qDebug() << " distance:" << distance; - qDebug() << " number of entities:" << _entityItems->size(); + //qDebug() << "EntityTreeElement::findDetailedRayIntersection()...."; + //qDebug() << " origin:" << origin; + //qDebug() << " distance:" << distance; + //qDebug() << " number of entities:" << _entityItems->size(); int entityNumber = 0; QList::iterator entityItr = _entityItems->begin(); @@ -498,15 +498,15 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con float localDistance; BoxFace localFace; - qDebug() << "EntityTreeElement::findDetailedRayIntersection()...."; - qDebug() << " checking entity[" << entityNumber << "]:" << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); - qDebug() << " checking the AABox:" << entityBox; + //qDebug() << "EntityTreeElement::findDetailedRayIntersection()...."; + //qDebug() << " checking entity[" << entityNumber << "]:" << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); + //qDebug() << " checking the AABox:" << entityBox; // if the ray doesn't intersect with our cube, we can stop searching! if (entityBox.findRayIntersection(origin, direction, localDistance, localFace)) { - qDebug() << " AABox for entity intersects!"; - qDebug() << " localDistance:" << localDistance; + //qDebug() << " AABox for entity intersects!"; + //qDebug() << " localDistance:" << localDistance; // extents is the entity relative, scaled, centered extents of the entity glm::mat4 rotation = glm::mat4_cast(entity->getRotation()); @@ -525,51 +525,51 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con // we can use the AABox's ray intersection by mapping our origin and direction into the entity frame // and testing intersection there. - qDebug() << " checking the entityFrameBox:" << entityFrameBox; + //qDebug() << " checking the entityFrameBox:" << entityFrameBox; if (entityFrameBox.findRayIntersection(entityFrameOrigin, entityFrameDirection, localDistance, localFace)) { - qDebug() << " entityFrameBox intersects!"; - qDebug() << " localDistance:" << localDistance; + //qDebug() << " entityFrameBox intersects!"; + //qDebug() << " localDistance:" << localDistance; if (localDistance < distance) { - qDebug() << " localDistance < distance... continue..."; + //qDebug() << " localDistance < distance... continue..."; // now ask the entity if we actually intersect if (entity->supportsDetailedRayIntersection()) { - qDebug() << " entity->supportsDetailedRayIntersection()...."; + //qDebug() << " entity->supportsDetailedRayIntersection()...."; if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance, localFace, intersectedObject)) { - qDebug() << " localDistance (detailed):" << localDistance; + //qDebug() << " localDistance (detailed):" << localDistance; if (localDistance < distance) { - qDebug() << " localDistance < distance..."; - qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); + //qDebug() << " localDistance < distance..."; + //qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); distance = localDistance; face = localFace; *intersectedObject = (void*)entity; somethingIntersected = true; } else { - qDebug() << " localDistance >= distance... TOO FAR AWAY"; + //qDebug() << " localDistance >= distance... TOO FAR AWAY"; } } } else { // if the entity type doesn't support a detailed intersection, then just return the non-AABox results if (localDistance < distance) { - qDebug() << " localDistance < distance..."; - qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); + //qDebug() << " localDistance < distance..."; + //qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType())); distance = localDistance; face = localFace; *intersectedObject = (void*)entity; somethingIntersected = true; } else { - qDebug() << " localDistance >= distance... TOO FAR AWAY"; + //qDebug() << " localDistance >= distance... TOO FAR AWAY"; } } } @@ -580,7 +580,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con entityNumber++; } - qDebug() << " EntityTreeElement::findDetailedRayIntersection().... returning somethingIntersected:" << somethingIntersected << "keepSearching:" << keepSearching; + //qDebug() << " EntityTreeElement::findDetailedRayIntersection().... returning somethingIntersected:" << somethingIntersected << "keepSearching:" << keepSearching; return somethingIntersected; } diff --git a/libraries/octree/src/OctreeElement.cpp b/libraries/octree/src/OctreeElement.cpp index 9f6e0530a8..e3ff06b2d3 100644 --- a/libraries/octree/src/OctreeElement.cpp +++ b/libraries/octree/src/OctreeElement.cpp @@ -1346,23 +1346,23 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3 AACube debugCube = cube; debugCube.scale((float)TREE_SCALE); - qDebug() << "OctreeElement::findRayIntersection()...."; - qDebug() << " origin:" << origin; - qDebug() << " checking element:" << debugCube << "in meters"; - qDebug() << " distance:" << distance; + //qDebug() << "OctreeElement::findRayIntersection()...."; + //qDebug() << " origin:" << origin; + //qDebug() << " checking element:" << debugCube << "in meters"; + //qDebug() << " distance:" << distance; // if the ray doesn't intersect with our cube, we can stop searching! if (!cube.findRayIntersection(origin, direction, distanceToElementCube, localFace)) { - qDebug() << " didn't intersect cube... done searching..."; + //qDebug() << " didn't intersect cube... done searching..."; keepSearching = false; // no point in continuing to search return false; // we did not intersect } - qDebug() << " distanceToElementCube:" << distanceToElementCube; + //qDebug() << " distanceToElementCube:" << distanceToElementCube; // by default, we only allow intersections with leaves with content if (!canRayIntersect()) { - qDebug() << " NOT canRayIntersect() -- no point in calling detailed..."; + //qDebug() << " NOT canRayIntersect() -- no point in calling detailed..."; return false; // we don't intersect with non-leaves, and we keep searching } @@ -1373,28 +1373,28 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3 // for any details inside the cube to be closer so we don't need to consider them. if (cube.contains(origin) || distanceToElementCube < distance) { - qDebug() << " distanceToElementCube < distance:" << (distanceToElementCube < distance); - qDebug() << " cube.contains(origin):" << (cube.contains(origin)); - qDebug() << " continue.... call... findDetailedRayIntersection()..."; + //qDebug() << " distanceToElementCube < distance:" << (distanceToElementCube < distance); + //qDebug() << " cube.contains(origin):" << (cube.contains(origin)); + //qDebug() << " continue.... call... findDetailedRayIntersection()..."; //qDebug() << " distanceToElementCube < distance -- continue.... call... findDetailedRayIntersection()..."; if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails, face, intersectedObject, distanceToElementCube)) { - qDebug() << " findDetailedRayIntersection() -- intersected something"; + //qDebug() << " findDetailedRayIntersection() -- intersected something"; if (distanceToElementDetails < distance) { - qDebug() << " distanceToElementDetails < distance -- THIS ONE IS GOOD -------"; + //qDebug() << " distanceToElementDetails < distance -- THIS ONE IS GOOD -------"; distance = distanceToElementDetails; face = localFace; - qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------"; + //qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------"; return true; } else { - qDebug() << " distanceToElementDetails:" << distanceToElementDetails; - qDebug() << " distance:" << distance; - qDebug() << " distanceToElementDetails >= distance -- THIS ONE IS NOT SELECTED even though it INTERSECTED -------"; + //qDebug() << " distanceToElementDetails:" << distanceToElementDetails; + //qDebug() << " distance:" << distance; + //qDebug() << " distanceToElementDetails >= distance -- THIS ONE IS NOT SELECTED even though it INTERSECTED -------"; } } } @@ -1412,7 +1412,7 @@ bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const g if (intersectedObject) { *intersectedObject = this; } - qDebug() << " OctreeElement::findDetailedRayIntersection().... hasContent() -- done searching..."; + //qDebug() << " OctreeElement::findDetailedRayIntersection().... hasContent() -- done searching..."; keepSearching = false; return true; // we did intersect } diff --git a/libraries/shared/src/GeometryUtil.cpp b/libraries/shared/src/GeometryUtil.cpp index c064630f83..f44c954a3a 100644 --- a/libraries/shared/src/GeometryUtil.cpp +++ b/libraries/shared/src/GeometryUtil.cpp @@ -252,6 +252,7 @@ bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direct return true; } + bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direction, const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) { @@ -264,7 +265,8 @@ bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direc h = glm::cross(direction, e2); a = glm::dot(e1, h); - if (a > -0.00001 && a < 0.00001) { + if (a > EPSILON && a < EPSILON) { + qDebug() << "if (a > EPSILON && a < EPSILON)..."; return false; } @@ -287,17 +289,17 @@ bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direc t = f * glm::dot(e2,q); // ray intersection - if (t > 0.00001) { + if (t > EPSILON) { distance = t; return true; } else { // this means that there is a line intersection but not a ray intersection + qDebug() << "if (t <= EPSILON)..."; return false; } return false; } - // Do line segments (r1p1.x, r1p1.y)--(r1p2.x, r1p2.y) and (r2p1.x, r2p1.y)--(r2p2.x, r2p2.y) intersect? // from: http://ptspts.blogspot.com/2010/06/how-to-determine-if-two-line-segments.html bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2) {