diff --git a/interface/src/models/ModelTreeRenderer.cpp b/interface/src/models/ModelTreeRenderer.cpp index 777459d642..5f6ac5f21f 100644 --- a/interface/src/models/ModelTreeRenderer.cpp +++ b/interface/src/models/ModelTreeRenderer.cpp @@ -268,92 +268,6 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) glutWireCube(1.0); glPopMatrix(); - - - glPushMatrix(); - { - Extents extents = model->getUnscaledMeshExtents(); - -qDebug() << "original..."; - -qDebug() << " extents.minimum=" << extents.minimum.x << "," << extents.minimum.y << "," << extents.minimum.z; -qDebug() << " extents.maximum=" << extents.maximum.x << "," << extents.maximum.y << "," << extents.maximum.z; - - float maxDimension = glm::distance(extents.maximum, extents.minimum); - float scale = modelItem.getSize() / maxDimension; - -qDebug() << " maxDimension=" << maxDimension; -qDebug() << " modelItem.getSize()=" << modelItem.getSize(); -qDebug() << " modelItem.getSize() [meters]=" << modelItem.getSize() * (float)TREE_SCALE; -qDebug() << " scale=" << scale; - - glm::vec3 halfDimensions = (extents.maximum - extents.minimum) * 0.5f; - glm::vec3 offset = -extents.minimum - halfDimensions; - - extents.minimum += offset; - extents.maximum += offset; - -qDebug() << "after offset..."; - -qDebug() << " extents.minimum=" << extents.minimum.x << "," << extents.minimum.y << "," << extents.minimum.z; -qDebug() << " extents.maximum=" << extents.maximum.x << "," << extents.maximum.y << "," << extents.maximum.z; - - extents.minimum *= (scale * (float)TREE_SCALE); - extents.maximum *= (scale * (float)TREE_SCALE); - -qDebug() << "after scale..."; - -qDebug() << " extents.minimum=" << extents.minimum.x << "," << extents.minimum.y << "," << extents.minimum.z; -qDebug() << " extents.maximum=" << extents.maximum.x << "," << extents.maximum.y << "," << extents.maximum.z; - - // using transform matrix draw spheres at corners - glm::mat4 rotation = glm::mat4_cast(modelItem.getModelRotation()); - glm::vec3 modelPosition = modelItem.getPosition() * (float)TREE_SCALE; - glm::mat4 translation = glm::translate(modelPosition); - glm::mat4 modelToWorldMatrix = translation * rotation; - glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix); - - - glm::vec3 modelOrigin(0); - glm::vec3 modelOriginInWorld = glm::vec3(modelToWorldMatrix * glm::vec4(modelOrigin, 1.0f)); - - glm::vec3 bottomLeftNear = extents.minimum; - glm::vec3 topRightFar = extents.maximum; - - glm::vec3 blnInWorld = glm::vec3(modelToWorldMatrix * glm::vec4(bottomLeftNear, 1.0f)); - glm::vec3 trfInWorld = glm::vec3(modelToWorldMatrix * glm::vec4(topRightFar, 1.0f)); - -//qDebug() << "modelPosition =" << modelPosition.x << "," << modelPosition.y << "," << modelPosition.z; -//qDebug() << "modelOrigin =" << modelOrigin.x << "," << modelOrigin.y << "," << modelOrigin.z; -//qDebug() << "modelOriginInWorld =" << modelOriginInWorld.x << "," << modelOriginInWorld.y << "," << modelOriginInWorld.z; - -qDebug() << " modelPosition =" << modelPosition.x << "," << modelPosition.y << "," << modelPosition.z; -qDebug() << " bottomLeftNear =" << bottomLeftNear.x << "," << bottomLeftNear.y << "," << bottomLeftNear.z; -qDebug() << " blnInWorld =" << blnInWorld.x << "," << blnInWorld.y << "," << blnInWorld.z; - - glPushMatrix(); - glTranslatef(modelOriginInWorld.x, modelOriginInWorld.y, modelOriginInWorld.z); - // draw the orignal bounding cube - glColor3f(0.0f, 1.0f, 0.0f); - glutSolidCube(0.02f); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(blnInWorld.x, blnInWorld.y, blnInWorld.z); - // draw the orignal bounding cube - glColor3f(0.0f, 0.0f, 1.0f); - glutSolidCube(0.02f); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(trfInWorld.x, trfInWorld.y, trfInWorld.z); - // draw the orignal bounding cube - glColor3f(1.0f, 0.0f, 1.0f); - glutSolidCube(0.02f); - glPopMatrix(); - - } - glPopMatrix(); } diff --git a/libraries/models/src/ModelTreeElement.cpp b/libraries/models/src/ModelTreeElement.cpp index 12d427aee5..31f786c15c 100644 --- a/libraries/models/src/ModelTreeElement.cpp +++ b/libraries/models/src/ModelTreeElement.cpp @@ -192,51 +192,27 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) { // if it's in our AABOX for our rotated extents, then check to see if it's in our non-AABox - + + // extents is the model relative, scaled, centered extents of the model + glm::mat4 rotation = glm::mat4_cast(model.getModelRotation()); glm::mat4 translation = glm::translate(model.getPosition()); - glm::mat4 modelToWorldMatrix = rotation; // * translation; - glm::mat4 worldToModelMatrix = modelToWorldMatrix; // glm::inverse(modelToWorldMatrix); + glm::mat4 modelToWorldMatrix = translation * rotation; + glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix); - // Note: reference, to get the point after rotation, take the rotation * the original point - //glm::vec3 rotatedPoint = rotation * originalPoint; - AABox nonAABox(extents.minimum, (extents.maximum - extents.minimum)); - glm::vec3 endPoint = origin + direction; - + glm::vec3 originInModelFrame = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f)); + glm::vec3 directionInModelFrame = glm::vec3(worldToModelMatrix * glm::vec4(direction, 1.0f)); - glm::vec3 originInModelFrame = glm::vec3(worldToModelMatrix * glm::vec4(origin, 0.0f)); - glm::vec3 endPointInModelFrame = glm::vec3(worldToModelMatrix * glm::vec4(endPoint, 0.0f)); - glm::vec3 directionInModelFrame = endPointInModelFrame - originInModelFrame; - glm::vec3 altDirectionInModelFrame = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f)); - - -qDebug() << "origin =" << origin.x << "," << origin.y << "," << origin.z; -qDebug() << "originInModelFrame =" << originInModelFrame.x << "," << originInModelFrame.y << "," << originInModelFrame.z; - -qDebug() << "endPoint =" << endPoint.x << "," << endPoint.y << "," << endPoint.z; -qDebug() << "endPointInModelFrame =" << endPointInModelFrame.x << "," << endPointInModelFrame.y << "," << endPointInModelFrame.z; - -qDebug() << "direction =" << direction.x << "," << direction.y << "," << direction.z; -qDebug() << "directionInModelFrame =" << directionInModelFrame.x << "," << directionInModelFrame.y << "," << directionInModelFrame.z; -qDebug() << "altDirectionInModelFrame=" << altDirectionInModelFrame.x << "," << altDirectionInModelFrame.y << "," << altDirectionInModelFrame.z; - - float xDistance; - BoxFace xFace; - - if (nonAABox.findRayIntersection(originInModelFrame, directionInModelFrame, xDistance, xFace)) { - qDebug() << "woot! got it! (originInModelFrame, directionInModelFrame) intersects nonAABox!"; - } else { - qDebug() << "NOPE! doesn't (originInModelFrame, directionInModelFrame) intersect nonAABox!"; + if (nonAABox.findRayIntersection(originInModelFrame, directionInModelFrame, localDistance, localFace)) { + if (localDistance < distance) { + distance = localDistance; + face = localFace; + *intersectedObject = (void*)(&model); + somethingIntersected = true; + } } - - if (localDistance < distance) { - distance = localDistance; - face = localFace; - *intersectedObject = (void*)(&model); - somethingIntersected = true; - } } } else if (localDistance < distance) { distance = localDistance;