Selection ViewpointCursor::getCursor(const SelectableList& selectables) {
        Selectable* closestObject = NULL;
        Selection closestIntersection;
        if (updatePending) {

            closestIntersection.distance = std::numeric_limits<float>::max();

            glm::vec3 p = getUserPosition();
            glm::vec3 d = getCursorDirection();


            // First up, see if we intersect one of the objects.
            for (SelectableList::const_iterator it = selectables.begin(); it < selectables.end(); ++it) {
                Selectable* s = *it;
                Selection i = s->intersect(p, d);

                if (i.distance > 0 && i.distance < closestIntersection.distance)
                {
                    closestObject = s;
                    closestIntersection = i;
                }
            }
            updatePending = false;

            // Return the closest object, if there was one.
            if (closestObject != NULL) {
                cursorPlaced = true;
                cursor3D = closestIntersection.pos;
                cursorNormal = closestIntersection.normal;
                closestIntersection.rotationMatrix = getCursorRotation();
                closestIntersection.object = closestObject;
            }

            // intersect with magic plane so at least the cursor appears...
            else {
                glm::vec3 userDirection = getViewDirection();
                Plane plane(p + userDirection*planeDistance, userDirection);
                Plane::Intersection ip = plane.intersect(p, d);
                if (ip.intersects) {
                    cursorPlaced = true;
                    cursor3D = ip.intersectionPoint;
                    cursorNormal = userDirection*-1.0f;
                    cursorPlaced = true;

                    closestIntersection.pos = cursor3D;
                    closestIntersection.normal = cursorNormal;
                    closestIntersection.rotationMatrix = getCursorRotation();
                    closestIntersection.object = NULL;
                }
            }
        }
        return closestIntersection;
    }
Example #2
0
void MeshEditorInstance::tickTools()
{
    EditorInstance::tickTools();

    if(m_selectedVolume)
    {
        m_selectedVolume->location = getCursorLocation();
        m_selectedVolume->rotation = getCursorRotation();
        m_selectedVolume->scale = getCursorScale();
    }
}