Lens::set_custom_film_mat()

This commit is contained in:
David Rose 2013-04-09 01:38:22 +00:00
parent 830fbcde1f
commit d3a295623e
3 changed files with 63 additions and 0 deletions

View File

@ -681,6 +681,18 @@ get_keystone() const {
return cdata->_keystone;
}
////////////////////////////////////////////////////////////////////
// Function: Lens::get_custom_film_mat
// Access: Published
// Description: Returns the custom_film_mat specified for the
// lens.
////////////////////////////////////////////////////////////////////
INLINE const LMatrix4 &Lens::
get_custom_film_mat() const {
CDReader cdata(_cycler);
return cdata->_custom_film_mat;
}
////////////////////////////////////////////////////////////////////
// Function: Lens::get_projection_mat
// Access: Published

View File

@ -340,6 +340,46 @@ clear_keystone() {
do_throw_change_event(cdata);
}
////////////////////////////////////////////////////////////////////
// Function: Lens::set_custom_film_mat
// Access: Published
// Description: Specifies a custom matrix to transform the points on
// the film after they have been converted into nominal
// film space (-1 .. 1 in U and V). This can be used to
// introduce arbitrary scales, rotations, or other
// linear transforms to the media plane. This is
// normally a 2-d matrix, but a full 4x4 matrix may be
// specified. This is applied on top of any film size,
// lens shift, and/or keystone correction.
////////////////////////////////////////////////////////////////////
void Lens::
set_custom_film_mat(const LMatrix4 &custom_film_mat) {
nassertv(!custom_film_mat.is_nan());
CDWriter cdata(_cycler, true);
cdata->_custom_film_mat = custom_film_mat;
do_adjust_user_flags(cdata, 0, UF_custom_film_mat);
do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv |
CF_projection_mat_left_inv | CF_projection_mat_right_inv |
CF_film_mat | CF_film_mat_inv, 0);
do_throw_change_event(cdata);
}
////////////////////////////////////////////////////////////////////
// Function: Lens::clear_custom_film_mat
// Access: Published
// Description: Disables the lens custom_film_mat correction.
////////////////////////////////////////////////////////////////////
void Lens::
clear_custom_film_mat() {
CDWriter cdata(_cycler, true);
cdata->_custom_film_mat = LMatrix4::ident_mat();
do_adjust_user_flags(cdata, UF_custom_film_mat, 0);
do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv |
CF_projection_mat_left_inv | CF_projection_mat_right_inv |
CF_film_mat | CF_film_mat_inv, 0);
do_throw_change_event(cdata);
}
////////////////////////////////////////////////////////////////////
// Function: Lens::set_frustum_from_corners
// Access: Published
@ -1618,6 +1658,10 @@ do_compute_film_mat(CData *cdata) {
0.0f, 0.0f, 0.0f, 1.0f) * cdata->_film_mat;
}
if ((cdata->_user_flags & UF_custom_film_mat) != 0) {
cdata->_film_mat = cdata->_film_mat * cdata->_custom_film_mat;
}
do_adjust_comp_flags(cdata, CF_film_mat_inv, CF_film_mat);
}
@ -2155,6 +2199,7 @@ clear() {
_view_vector.set(0.0f, 1.0f, 0.0f);
_up_vector.set(0.0f, 0.0f, 1.0f);
_keystone.set(0.0f, 0.0f);
_custom_film_mat = LMatrix4::ident_mat();
_user_flags = 0;
_comp_flags = CF_fov;

View File

@ -130,6 +130,10 @@ PUBLISHED:
void set_keystone(const LVecBase2 &keystone);
INLINE const LVecBase2 &get_keystone() const;
void clear_keystone();
void set_custom_film_mat(const LMatrix4 &custom_film_mat);
INLINE const LMatrix4 &get_custom_film_mat() const;
void clear_custom_film_mat();
// These flags are passed in as the last parameter to control the
// behavior of set_frustum_from_corners(). See the documentation
@ -266,6 +270,7 @@ protected:
UF_view_mat = 0x0400,
UF_keystone = 0x0800,
UF_min_fov = 0x1000,
UF_custom_film_mat = 0x2000,
};
enum CompFlags {
@ -320,6 +325,7 @@ protected:
PN_stdfloat _interocular_distance;
PN_stdfloat _convergence_distance;
LVecBase2 _keystone;
LMatrix4 _custom_film_mat;
LMatrix4 _film_mat, _film_mat_inv;
LMatrix4 _lens_mat, _lens_mat_inv;