QVariantMap Camera::getViewFrustum() { ViewFrustum frustum; loadViewFrustum(frustum); QVariantMap result; result["position"].setValue(frustum.getPosition()); result["orientation"].setValue(frustum.getOrientation()); result["projection"].setValue(frustum.getProjection()); result["centerRadius"].setValue(frustum.getCenterRadius()); result["fieldOfView"].setValue(frustum.getFieldOfView()); result["aspectRatio"].setValue(frustum.getAspectRatio()); return result; }
void ConicalViewFrustum::set(const ViewFrustum& viewFrustum) { // The ConicalViewFrustum has two parts: a central sphere (same as ViewFrustum) and a circular cone that bounds the frustum part. // Why? Because approximate intersection tests are much faster to compute for a cone than for a frustum. _position = viewFrustum.getPosition(); _radius = viewFrustum.getCenterRadius(); _farClip = viewFrustum.getFarClip(); auto topLeft = viewFrustum.getNearTopLeft() - _position; auto topRight = viewFrustum.getNearTopRight() - _position; auto bottomLeft = viewFrustum.getNearBottomLeft() - _position; auto bottomRight = viewFrustum.getNearBottomRight() - _position; auto centerAxis = 0.25f * (topLeft + topRight + bottomLeft + bottomRight); // Take the average _direction = glm::normalize(centerAxis); _angle = std::max(std::max(angleBetween(_direction, topLeft), angleBetween(_direction, topRight)), std::max(angleBetween(_direction, bottomLeft), angleBetween(_direction, bottomRight))); }