diff --git a/panda/src/gobj/lens.I b/panda/src/gobj/lens.I index 47ee2f4e1d..cf1c2e4d09 100644 --- a/panda/src/gobj/lens.I +++ b/panda/src/gobj/lens.I @@ -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 diff --git a/panda/src/gobj/lens.cxx b/panda/src/gobj/lens.cxx index 3f903a68c0..f338ea8258 100644 --- a/panda/src/gobj/lens.cxx +++ b/panda/src/gobj/lens.cxx @@ -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; diff --git a/panda/src/gobj/lens.h b/panda/src/gobj/lens.h index ec21a91d1b..5064656898 100644 --- a/panda/src/gobj/lens.h +++ b/panda/src/gobj/lens.h @@ -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;