NGL
6.5
The NCCA Graphics Library
|
simple camera class to allow movement in an opengl scene. a lot of this stuff is from the HILL book Computer Graphics with OpenGL 2nd Ed Prentice Hall a very good book fustrum culling modified from http://www.lighthouse3d.com/opengl/viewfrustum/index.php?defvf More...
#include <Camera.h>
Public Member Functions | |
Camera () noexcept | |
default constructor More... | |
Camera (const Vec3 &_eye, const Vec3 &_look, const Vec3 &_up) noexcept | |
constructor setting the camera using eye look and up More... | |
void | roll (Real _angle) noexcept |
roll the cameara around the Z axis More... | |
void | pitch (Real _angle) noexcept |
roll the cameara around the x axis More... | |
void | yaw (Real _angle) noexcept |
roll the cameara around the y axis More... | |
void | slide (Real _du, Real _dv, Real _dn) noexcept |
slide the camera around the U V and N axis More... | |
void | set (const Vec3 &_eye, const Vec3 &_look, const Vec3 &_up) noexcept |
set the Camera position using eye look and up vectors More... | |
void | setShape (Real _viewAngle, Real _aspect, Real _near, Real _far) noexcept |
set the shape of the Camera More... | |
void | setAspect (Real _asp) noexcept |
re-set the aspect ratio of the camera More... | |
void | setDefaultCamera () noexcept |
sets some nice default camera values More... | |
void | move (Real _dx, Real _dy, Real _dz) noexcept |
move the camera in world space (i.e. add a translation to each of the axis More... | |
void | moveBoth (Real _dx, Real _dy, Real _dz) noexcept |
move both the eye and the look at the same time More... | |
void | moveEye (Real _dx, Real _dy, Real _dz) noexcept |
move the eye position More... | |
void | moveLook (Real _dx, Real _dy, Real _dz) noexcept |
move the look position More... | |
void | setViewAngle (Real _angle) noexcept |
set the viewangle for the Camera More... | |
void | update () noexcept |
Use is called to make this the current camera and set the MODELVIEW and PROJECTION matrices in OpenGL. More... | |
void | normalisedYaw (Real _angle) noexcept |
used to do a Yaw based on Euler rotation with normalised values More... | |
void | normalisedPitch (Real _angle) noexcept |
used to do a Pitch based on Euler rotation with normalised values More... | |
void | normalisedRoll (Real _angle) noexcept |
used to do a Roll based on Euler rotation with normalised values More... | |
void | writeRib (RibExport &_rib) const noexcept |
write out the Camera so it may be used in Renderman, this writes a transform command in rib format so the OpenGL camera mirrors that of the renderman one More... | |
const Mat4 & | getViewMatrix () noexcept |
accesor to get the view matrix More... | |
const Mat4 & | getProjectionMatrix () noexcept |
accesor to get the projection matrix More... | |
Mat4 | getVPMatrix () const noexcept |
get the View * Projection matrix used as part of the MVP calculations More... | |
Vec4 | getEye () const noexcept |
get the eye position More... | |
void | setEye (Vec4 _e) noexcept |
set the eye position and re-calculate the matrices More... | |
void | setLook (Vec4 _e) noexcept |
set the look position and re-calculate the matrices More... | |
Vec4 | getLook () const noexcept |
get the look position More... | |
Vec4 | getUp () const noexcept |
get the up vector More... | |
Vec4 | getU () const noexcept |
get the u vector More... | |
Vec4 | getV () const noexcept |
get the v vector More... | |
Vec4 | getN () const noexcept |
get the n vector More... | |
Real | getFOV () const noexcept |
get the fov value More... | |
Real | getAspect () const noexcept |
get the aspect value More... | |
Real | getNear () const noexcept |
get the near clip value More... | |
Real | getFar () const noexcept |
get the far clip value More... | |
void | calculateFrustum () noexcept |
calculate the frustum for clipping etc More... | |
void | drawFrustum () noexcept |
draw the frustum for clipping etc More... | |
CameraIntercept | isPointInFrustum (const Vec3 &_p) const noexcept |
check to see if the point passed in is within the frustum More... | |
CameraIntercept | isSphereInFrustum (const Vec3 &_p, Real _radius) const noexcept |
check to see if the sphere passed in is within the frustum More... | |
CameraIntercept | boxInFrustum (const AABB &b) const noexcept |
check to see if the AABB passed in is within the frustum More... | |
Protected Types | |
enum | ProjPlane : char { ProjPlane::TOP = 0, ProjPlane::BOTTOM, ProjPlane::LEFT, ProjPlane::RIGHT, ProjPlane::NEARP, ProjPlane::FARP } |
index values for the planes array More... | |
Protected Member Functions | |
void | setPerspProjection () noexcept |
function used to set the perspective projection matrix values More... | |
void | rotAxes (Vec4 &io_a, Vec4 &io_b, const Real _angle) noexcept |
internal function to calculate the new rotation vectors for the camera after a roll, pitch or yaw More... | |
void | setViewMatrix () noexcept |
method to set the modelview matrix values for the current camera, this method load the matrix Modelview into OpenGL More... | |
void | setProjectionMatrix () noexcept |
set the projection matrix More... | |
Protected Attributes | |
Vec4 | m_u |
vector for the Camera local cord frame More... | |
Vec4 | m_v |
vector for the Camera local cord frame More... | |
Vec4 | m_n |
vector for the Camera local cord frame More... | |
Vec4 | m_eye |
the position of the Camera used to calculate the local cord frame More... | |
Vec4 | m_look |
where the camera is looking to, used with Eye to calculate the Vector m_n More... | |
Vec4 | m_up |
gives a general indication of which way up the camera is More... | |
Real | m_width |
the width of the display image used for some perspective projection calculations More... | |
Real | m_height |
the height of the display image used for some perspective projection calculations More... | |
Real | m_aspect |
used to store the current camera aspect ratio (can be derived from Width / Height More... | |
Real | m_zNear |
the near clipping plane of the camera view volume More... | |
Real | m_zFar |
the far clipping plane of the camera view volume More... | |
Real | m_fov |
the feild of view of the camera view volume, measured from the eye More... | |
Mat4 | m_viewMatrix |
a Matrix to hold the combined modelling and viewing matrix to load into OpenGL More... | |
Plane | m_planes [6] |
array of planes for fustrum More... | |
Vec3 | m_ntl |
points for the fustrum drawing More... | |
Vec3 | m_ntr |
Vec3 | m_nbl |
Vec3 | m_nbr |
Vec3 | m_ftl |
Vec3 | m_ftr |
Vec3 | m_fbl |
Vec3 | m_fbr |
Mat4 | m_projectionMatrix |
Projection a Matrix to hold the perspective transfomatio matrix for the camera. More... | |
simple camera class to allow movement in an opengl scene. a lot of this stuff is from the HILL book Computer Graphics with OpenGL 2nd Ed Prentice Hall a very good book fustrum culling modified from http://www.lighthouse3d.com/opengl/viewfrustum/index.php?defvf
|
strongprotected |
|
noexcept |
default constructor
Definition at line 39 of file Camera.cpp.
References m_aspect, m_eye, m_fov, m_height, m_width, m_zFar, m_zNear, and ngl::Vec4::set().
constructor setting the camera using eye look and up
[in] | _eye | the eye position of the Camera |
[in] | _look | where the camera is looking |
[in] | _up | the notion of upwardness for the camers (get re-calculated from the other vectors) |
Definition at line 86 of file Camera.cpp.
References setDefaultCamera().
|
noexcept |
check to see if the AABB passed in is within the frustum
[in] | AABB | to test |
Definition at line 479 of file Camera.cpp.
References ngl::Plane::getNormal(), ngl::INSIDE, ngl::INTERSECT, m_planes, and ngl::OUTSIDE.
|
noexcept |
calculate the frustum for clipping etc
Code modified from http://www.lighthouse3d.com/opengl/viewfrustum/index.php?intro
Definition at line 358 of file Camera.cpp.
References BOTTOM, FARP, LEFT, m_aspect, m_eye, m_fbl, m_fbr, m_fov, m_ftl, m_ftr, m_n, m_nbl, m_nbr, m_ntl, m_ntr, m_planes, m_u, m_v, m_zFar, m_zNear, NEARP, ngl::radians(), RIGHT, TOP, and ngl::Vec4::toVec3().
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
check to see if the point passed in is within the frustum
_p | the point to check |
Definition at line 441 of file Camera.cpp.
References ngl::INSIDE, m_planes, and ngl::OUTSIDE.
|
noexcept |
check to see if the sphere passed in is within the frustum
[in] | _p | the center of the sphere |
[in] | _radius | the radius of the sphere |
Definition at line 457 of file Camera.cpp.
References ngl::Plane::distance(), ngl::INSIDE, ngl::INTERSECT, m_planes, and ngl::OUTSIDE.
move the camera in world space (i.e. add a translation to each of the axis
[in] | _dx | the translation in the x |
[in] | _dy | the translation in the y |
[in] | _dz | the translation in the z |
Definition at line 181 of file Camera.cpp.
References m_eye, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, and setViewMatrix().
move both the eye and the look at the same time
[in] | _dx | ammount to move in the x |
[in] | _dy | ammount to move in the y |
[in] | _dz | ammount to move in the z |
Definition at line 190 of file Camera.cpp.
References ngl::Vec4::cross(), m_eye, m_look, m_n, m_u, m_up, m_v, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, ngl::Vec4::normalize(), ngl::Vec4::set(), and setViewMatrix().
move the eye position
[in] | _dx | ammount to move the eye in the x |
[in] | _dy | ammount to move the eye in the y |
[in] | _dz | ammount to move the eye in the z |
Definition at line 247 of file Camera.cpp.
References ngl::Vec4::cross(), m_eye, m_look, m_n, m_u, m_up, m_v, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, ngl::Vec4::normalize(), ngl::Vec4::set(), and setViewMatrix().
move the look position
[in] | _dx | ammount to move the look in the x |
[in] | _dy | ammount to move the look in the y |
[in] | _dz | ammount to move the look in the z |
Definition at line 264 of file Camera.cpp.
References ngl::Vec4::cross(), m_eye, m_look, m_n, m_u, m_up, m_v, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, ngl::Vec4::normalize(), ngl::Vec4::set(), and setViewMatrix().
used to do a Pitch based on Euler rotation with normalised values
[in] | _angle | the angle to rotate in degrees |
Definition at line 316 of file Camera.cpp.
References ngl::Mat4::identity(), m_n, m_u, m_v, ngl::Mat4::rotateX(), and setViewMatrix().
used to do a Roll based on Euler rotation with normalised values
[in] | _angle | the angle to rotate in degrees |
Definition at line 301 of file Camera.cpp.
References ngl::Mat4::identity(), m_n, m_u, m_v, ngl::Mat4::rotateZ(), and setViewMatrix().
used to do a Yaw based on Euler rotation with normalised values
[in] | _angle | the angle to rotate in degrees |
Definition at line 287 of file Camera.cpp.
References ngl::Mat4::identity(), m_n, m_u, m_v, ngl::Mat4::rotateY(), and setViewMatrix().
roll the cameara around the x axis
[in] | _angle | the angle to roll in degrees |
Definition at line 233 of file Camera.cpp.
References m_n, m_v, rotAxes(), and setViewMatrix().
roll the cameara around the Z axis
[in] | _angle | the angle to roll in degrees |
Definition at line 226 of file Camera.cpp.
References m_u, m_v, rotAxes(), and setViewMatrix().
internal function to calculate the new rotation vectors for the camera after a roll, pitch or yaw
[in,out] | io_a | the first vector to be rotated |
[in,out] | io_b | the second vector to be rotated |
[in] | _angle | the angle to rotate |
Definition at line 209 of file Camera.cpp.
References ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, and ngl::radians().
set the Camera position using eye look and up vectors
[in] | _eye | the new eye position |
[in] | _look | the new look position |
[in] | _up | the notional up direction of the Camera |
Definition at line 70 of file Camera.cpp.
References ngl::Vec4::cross(), m_eye, m_look, m_n, m_u, m_up, m_v, ngl::Vec4::normalize(), and setViewMatrix().
re-set the aspect ratio of the camera
[in] | _asp | the new aspect ratio |
Definition at line 156 of file Camera.cpp.
References m_aspect, m_fov, m_zFar, m_zNear, and setShape().
|
noexcept |
sets some nice default camera values
Definition at line 53 of file Camera.cpp.
References m_aspect, m_eye, m_fov, m_look, m_up, m_zFar, m_zNear, ngl::Vec4::set(), setShape(), and ngl::Vec4::up().
|
protectednoexcept |
function used to set the perspective projection matrix values
Definition at line 108 of file Camera.cpp.
References ngl::Mat4::identity(), m_aspect, m_fov, ngl::Mat4::m_m, m_projectionMatrix, m_zFar, m_zNear, and ngl::radians().
|
protectednoexcept |
set the projection matrix
Definition at line 126 of file Camera.cpp.
References m_projectionMatrix, ngl::Mat4::null(), and setPerspProjection().
set the shape of the Camera
[in] | _viewAngle | the view angle of the camera from the eye |
[in] | _aspect | the aspect ratio of the camera can be calculated from Width/height |
[in] | _near | the near clipping plane |
[in] | _far | the far clipping plane |
Definition at line 134 of file Camera.cpp.
References ngl::CAMERANEARLIMIT, m_aspect, m_fov, m_zFar, m_zNear, NGL_ASSERT, and setProjectionMatrix().
set the viewangle for the Camera
[in] | _angle | new angle |
Definition at line 163 of file Camera.cpp.
References m_aspect, m_fov, m_zFar, m_zNear, and setShape().
|
protectednoexcept |
method to set the modelview matrix values for the current camera, this method load the matrix Modelview into OpenGL
Definition at line 95 of file Camera.cpp.
References calculateFrustum(), ngl::Vec4::dot(), m_eye, ngl::Mat4::m_m, m_n, m_u, m_v, m_viewMatrix, ngl::Vec4::m_x, ngl::Vec4::m_y, and ngl::Vec4::m_z.
slide the camera around the U V and N axis
[in] | _du | ammount to slide in the U |
[in] | _dv | ammount to slide in the V |
[in] | _dn | ammount to slide in the N |
Definition at line 171 of file Camera.cpp.
References m_eye, m_n, m_u, m_v, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, and setViewMatrix().
|
noexcept |
Use is called to make this the current camera and set the MODELVIEW and PROJECTION matrices in OpenGL.
Definition at line 281 of file Camera.cpp.
References setViewMatrix().
write out the Camera so it may be used in Renderman, this writes a transform command in rib format so the OpenGL camera mirrors that of the renderman one
[in] | _rib | the pointer to the RibExport class currently being used |
Definition at line 333 of file Camera.cpp.
References ngl::Mat4::m_openGL, and m_viewMatrix.
roll the cameara around the y axis
[in] | _angle | the angle to roll in degrees |
Definition at line 240 of file Camera.cpp.
References m_n, m_u, rotAxes(), and setViewMatrix().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |