KJB
|
#include <gr_camera.h>
Public Member Functions | |
Base_gl_interface (double inear=10, double ifar=10000) | |
Base_gl_interface (const Base_gl_interface &) | |
bgl the Base_gl_interface to copy into this one More... | |
virtual Base_gl_interface & | operator= (const Base_gl_interface &src) |
bgl the Base_gl_interface to assign to this one More... | |
virtual | ~Base_gl_interface () |
virtual void | swap (Self &other) |
virtual void | set_gl_modelview () const |
Sets the gl modelview matrix based on the current camera parameters. More... | |
virtual void | set_gl_projection () const |
Sets the gl projection matrix based on the current camera parameters. More... | |
virtual void | mult_gl_projection () const |
Multiplies the current gl projection matrix with this camera's matrix. More... | |
void | prepare_for_rendering (bool clean_buffers) const |
Prepares the opengl for rendering by setting the gl modelview and projection matrix based on the current camera parameters It also clears the depth and the color buffers, and sets the background color to black. More... | |
void | set_near_clipping_plane (double inear) |
sets the near clipping plane distance from the camera More... | |
void | set_far_clipping_plane (double ifar) |
sets the far clipping plane distance from the camera More... | |
void | set_clipping_planes (double inear, double ifar) |
sets the near and far clipping plane distances from the camera More... | |
double | get_near () const |
gets the near clipping plane distance from the camera More... | |
double | get_far () const |
gets the far clipping plane distance from the camera More... | |
const Matrix & | get_modelview_matrix () const |
returns the gl modelview matrix More... | |
const Matrix & | get_projection_matrix () const |
returns the projection matrix; note: this needs to be preceeded by a glOrtho call with the window dimensions before sending this to opengl. More... | |
Matrix | get_gl_projection_matrix () const |
returns the exact matrix that opengl uses for its projection matrix. this is effectively glOrtho(-vp_width/2, vp_width/2, -vp_height/2, vp_height/2, znear, zfar), followed by glMultMatrix(get_projection_matrix(). Note that if the viewport size changes, you'll likely need to re-call this, or understand that the pixels sizes will change. More... | |
void | project_point (double &x, double &y, double &z, const kjb::Vector &point3D, double img_height) const |
virtual bool | Polygon_visibility_test (const kjb::Polygon &p, double epsilon=0) const |
checks whether a given polygon is visible under the given camera parameters More... | |
void | set_modelview_entry (unsigned int row, unsigned int col, double value) |
sets an entry of the modelview matrix More... | |
void | set_projection_entry (unsigned int row, unsigned int col, double value) |
sets an entry of the projection matrix More... | |
double & | get_modelview_entry (unsigned int row, unsigned int col) |
returns an entry of the modelview matrix More... | |
double | get_modelview_entry (unsigned int row, unsigned int col) const |
returns an entry of the modelview matrix More... | |
double & | get_projection_entry (unsigned int row, unsigned int col) |
returns an entry of the projection matrix More... | |
double | get_projection_entry (unsigned int row, unsigned int col) const |
returns an entry of the projection matrix More... | |
Static Public Member Functions | |
static double | get_gl_viewport_aspect () |
returns the ratio between the gl viewport width and the gl viewport height More... | |
static double | get_gl_viewport_width () |
returns the gl viewport width More... | |
static double | get_gl_viewport_height () |
returns the gl viewport height More... | |
static void | get_gl_viewport_size (double *w, double *h) |
gets the gl viewport width and height More... | |
static void | get_gl_viewport (double *x, double *y, double *w, double *h) |
gets all the g; viewport parameters (x,y,width,height) More... | |
static void | set_gl_viewport_size (double, double) |
sets the gl viewport size More... | |
static void | set_gl_viewport (double x, double y, double w, double h) |
sets all the gl viewport parameters (x,y,width,length) More... | |
static void | capture_gl_view (kjb_c::KJB_image **img_out) |
captures the gl view and stores it into a KJB_image More... | |
static void | capture_gl_view (const char *fname) |
captures the gl view and saves into a file More... | |
static void | capture_gl_view (const char *fname_fmt, uint32_t N) |
captures the gl view and saves into a file, by appending N to the filename More... | |
static void | capture_gl_view (kjb::Int_matrix &matrix) |
captures the gl view and stores it into a Int_matrix. The four bytes used by GL to represent the four channels (R,G,B,A) are packaged into a single integer. More... | |
static void | capture_gl_view (Image &img_out) |
captures the gl view and stores it into a c++ image More... | |
static void | set_gl_view (const kjb::Image &img_in) |
static void | construct_image_from_int_matrix (kjb::Image &im, kjb::Int_matrix &m) |
Protected Member Functions | |
Base_gl_interface (const Matrix &, const Matrix &, double near, double far) | |
constructs a Base_gl_interface from a modelview and a projection matrix More... | |
void | set_modelview_matrix (const Matrix &mv) |
sets the modelview matrix More... | |
void | set_projection_matrix (const Matrix &pm) |
sets the projection matrix More... | |
void | scale_modelview (double xscale, double yscale, double zscale) |
scales the modelview matrix using glScale More... | |
the base interface between opengl and a camera parametrized in terms of modelview matrix, projection matrix, and near and far clipping planes. This class manipulates the modelview and the projection matrices by accessing them directly without calling glFrustum od gluPerspective. Please use it only if you know what you are doing. The clipping planes are handled by setting projection_matrix(2,2) = near + far; projection_matrix(2,3) = near*far; projection_matrix(3,2) = -1 and then by using applying the glOrtho transformation with parameters (-viewport_width/2, viewport_width/2, -viewport_height/2, viewport_height/2, near, far) This will clip stuff outside the viewing frustum and normalize the frustum itself to the normalized device coordinates opengl expects.
If you want to see the math, please go to http://sightations.wordpress.com/2010/08/03/simulating-calibrated-cameras-in-opengl
Base_gl_interface::Base_gl_interface | ( | double | inear = 10 , |
double | ifar = 10000 |
||
) |
inear | Distance of the near clipping plane from the camera |
ifar | Distance of the far clipping plane from the camera |
Base_gl_interface::Base_gl_interface | ( | const Base_gl_interface & | bgl | ) |
bgl the Base_gl_interface to copy into this one
|
inlinevirtual |
|
protected |
constructs a Base_gl_interface from a modelview and a projection matrix
mv | input modelview matrix |
pj | input projection matrix |
inear | Distance of the near clipping plane from the camera |
ifar | Distance of the far clipping plane from the camera |
|
static |
captures the gl view and stores it into a KJB_image
img_out | Result parameter. If *img_out is 0, an image is allocated; otherwise its space is re-used. |
kjb::IO_error |
|
static |
captures the gl view and saves into a file
fname | File name to write the captured view image to. |
kjb::IO_error |
|
static |
captures the gl view and saves into a file, by appending N to the filename
An example for fname_fmt is
fname_fmt | Format for the file name with one printf style integer conversion for the file number. |
N | Number of the captured image. |
kjb::IO_error |
|
static |
captures the gl view and stores it into a Int_matrix. The four bytes used by GL to represent the four channels (R,G,B,A) are packaged into a single integer.
matrix | Result parameter. The gl view will be stored into this int matrix. The four bytes used by GL to represent the four channels (R,G,B,A) are packaged into a single integer. |
kjb::IO_error |
|
static |
captures the gl view and stores it into a c++ image
Captures the gl view and stores it into a c++ image
img_out | Result parameter. The content of the GL frame buffer will be copied into this image, freeing the previous memory area pointed by this image |
kjb::IO_error |
|
static |
Constructs an image from an int matrix. Each integer consists of four bytes, and each of them is interpreted as one of the GL channels (RGBA, or ABGR if the architecture is little endian). This is MOSTLY (if not only) used for DEBUGGING
Constructs an image from an int matrix. Each integer consists of four bytes, and each of them is interpreted as one of the GL channels (RGBA, or ABGR if the architecture is little endian). This is MOSTLY (if not only) used for DEBUGGING
im | the image to be initialized from the matrix |
m | the matrix to create the image from |
|
inline |
gets the far clipping plane distance from the camera
kjb::Matrix Base_gl_interface::get_gl_projection_matrix | ( | ) | const |
returns the exact matrix that opengl uses for its projection matrix. this is effectively glOrtho(-vp_width/2, vp_width/2, -vp_height/2, vp_height/2, znear, zfar), followed by glMultMatrix(get_projection_matrix(). Note that if the viewport size changes, you'll likely need to re-call this, or understand that the pixels sizes will change.
|
static |
gets all the g; viewport parameters (x,y,width,height)
x | it will contain the x parameter of the gl viewport |
y | it will contain the y parameter of the gl viewport |
w | it will contain the width of the gl viewport |
h | it will contain the height of the gl viewport |
|
static |
returns the ratio between the gl viewport width and the gl viewport height
|
static |
returns the gl viewport height
|
static |
gets the gl viewport width and height
|
static |
returns the gl viewport width
|
inline |
returns an entry of the modelview matrix
|
inline |
returns an entry of the modelview matrix
|
inline |
returns the gl modelview matrix
|
inline |
gets the near clipping plane distance from the camera
|
inline |
returns an entry of the projection matrix
|
inline |
returns an entry of the projection matrix
|
inline |
returns the projection matrix; note: this needs to be preceeded by a glOrtho call with the window dimensions before sending this to opengl.
|
virtual |
Multiplies the current gl projection matrix with this camera's matrix.
|
virtual |
bgl the Base_gl_interface to assign to this one
|
virtual |
checks whether a given polygon is visible under the given camera parameters
Checks whether a polygon is visible under the current camera by checking that the dot product between the polygon normal and the normalized vector between the camera and the polygon center is bigger than epsilon (whose default value is zero)
p | the polygon to test |
epsilon | the constant to compare the dot product with (default = 0) |
Reimplemented in kjb::Parametric_camera_gl_interface.
void Base_gl_interface::prepare_for_rendering | ( | bool | clean_buffers | ) | const |
Prepares the opengl for rendering by setting the gl modelview and projection matrix based on the current camera parameters It also clears the depth and the color buffers, and sets the background color to black.
Prepares the opengl for rendering by setting the gl modelview and projection matrix based on the current camera parameters It also clears the depth and the color buffers, and sets the background color to black
clean_buffers | if true, the color and the depth buffer will be cleared |
void Base_gl_interface::project_point | ( | double & | x, |
double & | y, | ||
double & | z, | ||
const kjb::Vector & | point3D, | ||
double | img_height | ||
) | const |
|
protected |
scales the modelview matrix using glScale
Scales the gl modelview matrix using glScaled.
xscale | the scale along the x axis |
yscale | the scale along the y axis |
zscale | the scale along the z axis |
void Base_gl_interface::set_clipping_planes | ( | double | inear, |
double | ifar | ||
) |
sets the near and far clipping plane distances from the camera
inear | Distance of the near clipping plane from the camera |
far | Distance of the far clipping plane from the camera |
void Base_gl_interface::set_far_clipping_plane | ( | double | ifar | ) |
sets the far clipping plane distance from the camera
ifar | Distance of the far clipping plane from the camera |
|
virtual |
Sets the gl modelview matrix based on the current camera parameters.
Sets the gl modelview matrix using the current camera parameters.
|
virtual |
Sets the gl projection matrix based on the current camera parameters.
Sets the gl projection matrix using the current camera parameters. For the details on math, please see the class description
|
static |
Puts the content of the input image in the GL frame buffer
Put the content of the input image in the GL frame buffer
img_in | The input image |
|
static |
sets all the gl viewport parameters (x,y,width,length)
x | the new x parameter for the gl viewport |
y | the new y parameter for the gl viewport |
w | the new gl viewport size |
h | the new gl viewport height |
|
static |
sets the gl viewport size
w | the new gl viewport size |
h | the new gl viewport height |
|
inline |
sets an entry of the modelview matrix
|
protected |
sets the modelview matrix
void Base_gl_interface::set_near_clipping_plane | ( | double | inear | ) |
sets the near clipping plane distance from the camera
inear | Distance of the near clipping plane from the camera |
|
inline |
sets an entry of the projection matrix
|
protected |
sets the projection matrix
|
inlinevirtual |
Swap contents with another Perspective_camera. This is implemented to run much more quickly than: Perspective_camera tmp = b; b = a; a = tmp;
Reimplemented in kjb::Parametric_camera_gl_interface.