1#include "CameraHelper.h"
19 glm::dvec3 center = (boundingBox.min + boundingBox.max) * 0.5;
31 const glm::dvec3 center =
getCenter(boundingBox);
32 float distance_to_midpoint =
static_cast<float>(glm::length(position - center));
33 return distance_to_midpoint;
38 glm::quat horizontalRotation = glm::angleAxis(horizontalAngle, glm::vec3(0, 0, 1));
39 glm::quat verticalRotation = glm::angleAxis(verticalAngle, glm::vec3(1, 0, 0));
40 glm::quat rotation = horizontalRotation * verticalRotation;
47 const float radius =
getRadius(boundingBox);
49 const float orthoHeight = radius * 2;
56 const glm::dvec3 size = boundingBox.max - boundingBox.min;
57 const float radius =
static_cast<float>(glm::length(size) / 2.0);
63 const glm::vec3 direction = orientation * glm::vec3(0, 0, -1);
64 glm::normalize(direction);
65 const glm::dvec3 result = position + glm::dvec3(direction * focalDistance);
70 const glm::quat& orientation,
float fieldOfView, glm::vec2 viewport)
72 const float viewportWidth = viewport.x;
73 const float viewportHeight = viewport.y;
76 if ((viewportWidth > 0.0f) && (viewportHeight > 0.0f))
77 aspect = viewportWidth / viewportHeight;
81 const glm::vec3 cameraDirection = orientation * glm::vec3(0, 0, -1);
82 const glm::dvec3 center =
getCenter(boundingBox);
85 const float radius =
getRadius(boundingBox);
89 const float aspectRadius = radius / (aspect < 1.0f ? aspect : 1.0f);
93 glm::vec3 direction = -cameraDirection;
94 glm::normalize(direction);
101 const float movelength = aspectRadius / std::tan(fieldOfView / 2.0f);
102 const glm::dvec3 position = center + glm::dvec3(direction * movelength);
COGSCORE_DLL_API float getOrthoHeight(const Cogs::Geometry::DBoundingBox &boundingBox)
Calculate Orthographic camera orthoHeight Field to view boundingbox.
COGSCORE_DLL_API glm::dvec3 getViewAllPosition(const Cogs::Geometry::DBoundingBox &boundingBox, const glm::quat &orientation, float fieldOfView, glm::vec2 viewport)
COGSCORE_DLL_API glm::dvec3 getFocalPosition(const glm::dvec3 &position, const glm::quat &orientation, float focalDistance)
COGSCORE_DLL_API glm::dvec3 getCenter(const Cogs::Geometry::DBoundingBox &boundingBox)
Gets center of non-empty bounding box.
COGSCORE_DLL_API float getFocalDistance(const glm::dvec3 &position, const Cogs::Geometry::DBoundingBox &boundingBox)
Gets distance from given position (camera position) to center of bounding box.
COGSCORE_DLL_API float getFarDistance(const glm::dvec3 &position, const Cogs::Geometry::DBoundingBox &boundingBox)
Gets camera far distance given bounding box.
COGSCORE_DLL_API float getRadius(const Cogs::Geometry::DBoundingBox &boundingBox)
Gets the radius of the bounding sphere.
COGSCORE_DLL_API glm::quat getOrientation(float horizontalAngle, float verticalAngle)
Gets the camera orientation from the horizontal and vertical angle values.
Contains common utility members for camera setup Other camera utilities: Interpolation utilities can ...