Cogs.Core
Functions
Cogs::Utility::CameraUtils Namespace Reference

Contains common operations for camera setup. More...

Functions

template<class TransformComponent , class OrbitingCameraController >
glm::quat getCameraOrientation (const TransformComponent transformComponent, const OrbitingCameraController orbitingCameraController)
 
template<class CameraComponent , class TransformComponent , class OrbitingCameraController , typename ProjectionMode >
glm::dvec3 viewAll (const CameraComponent cameraComponent, const TransformComponent transformComponent, const OrbitingCameraController orbitingCameraController, const ProjectionMode projectionMode, const Cogs::Geometry::DBoundingBox &boundingBox, glm::vec2 viewport=glm::vec2(0.0f, 0.0f))
 View all for given bounding box.
 
template<class CameraData >
bool getProjectedCoordinates (const glm::vec2 &coordinatesToProject, const CameraData &cameraData, const glm::vec3 &targetPlaneNormal, const glm::vec3 &targetPlanePosition, glm::vec3 &projectedCoordinates)
 Project a screen coordinate onto a plane in 3d space.
 

Detailed Description

Contains common operations for camera setup.

Uses: CameraHelper.h for calculation. Support both Cogs.Native API usage and direct Cogs classes: Using Cogs::Native: Cogs::Native::ProjectionMode projectionMode = camera->cameraComponent->projectionMode Cogs::Utility::CameraUtils::viewAll(camera->cameraComponent, camera->transformComponent, camera->getComponent<OrbitingCameraController>(), projectionMode, bbox, viewport); Using Cogs::Core: Cogs::Core::ProjectionMode projectionMode = cameraComponent->projectionMode; Cogs::Utility::CameraUtils::viewAll(camera->getComponent<CameraComponent>(), camera->getComponent<TransformComponent>(), camera->getComponent<OrbitingCameraController>(), projectionMode, bbox, viewport);

Function Documentation

◆ getCameraOrientation()

template<class TransformComponent , class OrbitingCameraController >
glm::quat Cogs::Utility::CameraUtils::getCameraOrientation ( const TransformComponent  transformComponent,
const OrbitingCameraController  orbitingCameraController 
)
inline

Get the Camera Orientation Quaternion.

Template Parameters
TransformComponentCogs.Native of Core::TransformComponent
OrbitingCameraControllerCogs.Native of Core::OrbitingCameraController
Parameters
transformComponentCamera transform if not using orbiting controller.
orbitingCameraControllerOptional orbiting controller. Use transformComponent if not present.
Returns
Camera orientation.

Definition at line 29 of file CameraUtils.h.

References Cogs::Utility::CameraHelper::getOrientation().

Referenced by viewAll().

◆ getProjectedCoordinates()

template<class CameraData >
bool Cogs::Utility::CameraUtils::getProjectedCoordinates ( const glm::vec2 &  coordinatesToProject,
const CameraData &  cameraData,
const glm::vec3 &  targetPlaneNormal,
const glm::vec3 &  targetPlanePosition,
glm::vec3 &  projectedCoordinates 
)
inline

Project a screen coordinate onto a plane in 3d space.

Parameters
coordinatesToProject- Screen coordinate to project.
cameraData- CameraData of the camera used for projection.
cameraPosition- Position of the camera used for projection.
targetPlaneNormal- Normal vector of the plane used for projecting onto. As a convenience, a normal of exactly [0,0,0] will be interpreted as a plane orthogonal to the camera view direction.
targetPlanePosition- Position of the plane used for projecting onto.
[out]projectedCoordinates- Resulting projected coordinate.
Returns
a boolean telling if the position was projected onto the plane and is in front of the camera.

Definition at line 103 of file CameraUtils.h.

◆ viewAll()

template<class CameraComponent , class TransformComponent , class OrbitingCameraController , typename ProjectionMode >
glm::dvec3 Cogs::Utility::CameraUtils::viewAll ( const CameraComponent  cameraComponent,
const TransformComponent  transformComponent,
const OrbitingCameraController  orbitingCameraController,
const ProjectionMode  projectionMode,
const Cogs::Geometry::DBoundingBox &  boundingBox,
glm::vec2  viewport = glm::vec2(0.0f, 0.0f) 
)
inline

View all for given bounding box.

Ensures a sphere enclosing the bounding box is visible. Update passed components. Either in CameraComponent/TransformComponent or OrbitingCameraController/CameraComponent. Updated cameraComponent->farDistance is extended if needed to include bounds (Near Distance not changed).

Parameters
cameraComponent- CameraComponent of the selected camera.
transformComponent- TransformComponent of the selected camera.
orbitingCameraController- Optional OrbitingCameraController component of the selected camera.
projectionMode- Perspective or Orthogonal projection
boundingBox- Bounding box to focus on. Must have Extents.
viewport- Optional viewport in pixels of window.
Returns
Calculated Position of the camera (may be passed to getFarDistance)

Definition at line 56 of file CameraUtils.h.

References getCameraOrientation(), Cogs::Utility::CameraHelper::getCenter(), Cogs::Utility::CameraHelper::getFarDistance(), Cogs::Utility::CameraHelper::getFocalDistance(), Cogs::Utility::CameraHelper::getOrthoHeight(), and Cogs::Utility::CameraHelper::getViewAllPosition().