Example #1
0
 bool rayPassesNearOrThrough(const V3d& rayOrigin, const V3d& rayDir) const
 {
     const double diagRadius = 1.2*bbox.size().length()/2; // Sphere diameter is length of box diagonal
     const V3d o2c = bbox.center() - rayOrigin; // vector from rayOrigin to box center
     const double l = o2c.length();
     if(l < diagRadius)
         return true; // rayOrigin lies within bounding sphere
     // rayOrigin lies outside of bounding sphere
     const double cosA = o2c.dot(rayDir)/l;  // cosine of angle between rayDir and vector from origin to center
     if(cosA < DBL_MIN)
         return false; // rayDir points to side or behind with respect to direction from origin to center of box
     const double sinA = sqrt(1 - cosA*cosA); // sine of angle between rayDir and vector from origin to center
     return sinA/cosA < diagRadius/l;
 }
Example #2
0
void View3D::snapToPoint(const Imath::V3d & pos)
{

    double snapScale = 0.025;
    QString pointInfo;
    V3d newPos(0.0,0.0,0.0); //init newPos to origin
    if (snapToGeometry(pos, snapScale,
                &newPos, &pointInfo))
    {
        V3d posDiff = newPos - m_prevCursorSnap;
        g_logger.info("Selected Point Attributes:\n"
                "%s"
                "diff with previous = %.3f\n"
                "vector diff = %.3f",
                pointInfo, posDiff.length(), posDiff);
        // Snap cursor /and/ camera to new position
        // TODO: Decouple these, but in a sensible way
        m_cursorPos = newPos;
        m_camera.setCenter(newPos);
        m_prevCursorSnap = newPos;
    }
}