Panda3D
 All Classes Functions Variables Enumerations
matrixLens.I
00001 // Filename: matrixLens.I
00002 // Created by:  drose (12Dec01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 ////////////////////////////////////////////////////////////////////
00016 //     Function: MatrixLens::Constructor
00017 //       Access: Public
00018 //  Description:
00019 ////////////////////////////////////////////////////////////////////
00020 INLINE MatrixLens::
00021 MatrixLens() :
00022   _user_mat(LMatrix4::ident_mat()),
00023   _ml_flags(0)
00024 {
00025   // The default film size for a MatrixLens is 2, which makes the
00026   // default range for both X and Y be [-1, 1].  This also,
00027   // incidentally, makes the film_mat be identity.
00028   set_film_size(2.0);
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: MatrixLens::Copy Constructor
00033 //       Access: Public
00034 //  Description:
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE MatrixLens::
00037 MatrixLens(const MatrixLens &copy) : 
00038   Lens(copy),
00039   _user_mat(copy._user_mat),
00040   _left_eye_mat(copy._left_eye_mat),
00041   _right_eye_mat(copy._right_eye_mat),
00042   _ml_flags(copy._ml_flags)
00043 {
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: MatrixLens::Copy Assignment Operator
00048 //       Access: Public
00049 //  Description:
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE void MatrixLens::
00052 operator = (const MatrixLens &copy) {
00053   Lens::operator = (copy);
00054   _user_mat = copy._user_mat;
00055   _left_eye_mat = copy._left_eye_mat;
00056   _right_eye_mat = copy._right_eye_mat;
00057   _ml_flags = copy._ml_flags;
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: MatrixLens::set_user_mat
00062 //       Access: Published
00063 //  Description: Explicitly specifies the projection matrix.  This
00064 //               matrix should convert X and Y to the range
00065 //               [-film_size/2, film_size/2], where (-fs/2,-fs/2) is
00066 //               the lower left corner of the screen and (fs/2, fs/2)
00067 //               is the upper right.  Z should go to the range [-1,
00068 //               1], where -1 is the far plane and 1 is the near
00069 //               plane.  Note that this is a left-handed Y-up
00070 //               coordinate system.
00071 //
00072 //               The default film_size for a MatrixLens is 2, so the
00073 //               default range is [-1, 1] for both X and Y.  This is
00074 //               consistent with the GL conventions for projection
00075 //               matrices.
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE void MatrixLens::
00078 set_user_mat(const LMatrix4 &user_mat) {
00079   Lens::CDWriter lens_cdata(Lens::_cycler, true);
00080   _user_mat = user_mat;
00081   do_adjust_comp_flags(lens_cdata, CF_mat, 0);
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: MatrixLens::get_user_mat
00086 //       Access: Published
00087 //  Description: Returns the explicit projection matrix as set by the
00088 //               user.  This does not include transforms on the lens
00089 //               or film (e.g. a film offset or view hpr).
00090 ////////////////////////////////////////////////////////////////////
00091 INLINE const LMatrix4 &MatrixLens::
00092 get_user_mat() const {
00093   return _user_mat;
00094 }
00095 
00096 ////////////////////////////////////////////////////////////////////
00097 //     Function: MatrixLens::set_left_eye_mat
00098 //       Access: Published
00099 //  Description: Sets a custom projection matrix for the left eye.
00100 //               This is only used if the lens is attached to a stereo
00101 //               camera, in which case the left eye matrix will be
00102 //               used to draw the scene in the left eye (but the
00103 //               center matrix--the user_mat--will still be used to
00104 //               cull the scene).
00105 //
00106 //               This matrix should not be too different from the
00107 //               center matrix (set by set_user_mat()) or culling
00108 //               errors may become obvious.
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE void MatrixLens::
00111 set_left_eye_mat(const LMatrix4 &left_eye_mat) {
00112   Lens::CDWriter lens_cdata(Lens::_cycler, true);
00113   _left_eye_mat = left_eye_mat;
00114   _ml_flags |= MF_has_left_eye;
00115   do_adjust_comp_flags(lens_cdata, CF_mat, 0);
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: MatrixLens::clear_left_eye_mat
00120 //       Access: Published
00121 //  Description: Removes the custom projection matrix set for the left
00122 //               eye, and uses the center matrix (set by set_user_mat)
00123 //               instead.
00124 ////////////////////////////////////////////////////////////////////
00125 INLINE void MatrixLens::
00126 clear_left_eye_mat() {
00127   Lens::CDWriter lens_cdata(Lens::_cycler, true);
00128   _ml_flags &= ~MF_has_left_eye;
00129   do_adjust_comp_flags(lens_cdata, CF_mat, 0);
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: MatrixLens::has_left_eye_mat
00134 //       Access: Published
00135 //  Description: Returns true if the camera has a custom projection
00136 //               matrix set for the left eye, or false if the center
00137 //               matrix (set by set_user_mat) will be used for the
00138 //               left eye.
00139 ////////////////////////////////////////////////////////////////////
00140 INLINE bool MatrixLens::
00141 has_left_eye_mat() const {
00142   return (_ml_flags & MF_has_left_eye) != 0;
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: MatrixLens::get_left_eye_mat
00147 //       Access: Published
00148 //  Description: Returns the custom projection matrix for the left
00149 //               eye, if any, or the center matrix if there is no
00150 //               custom matrix set for the left eye.
00151 ////////////////////////////////////////////////////////////////////
00152 INLINE const LMatrix4 &MatrixLens::
00153 get_left_eye_mat() const {
00154   if ((_ml_flags & MF_has_left_eye) != 0) {
00155     return _left_eye_mat;
00156   }
00157   return _user_mat;
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: MatrixLens::set_right_eye_mat
00162 //       Access: Published
00163 //  Description: Sets a custom projection matrix for the right eye.
00164 //               This is only used if the lens is attached to a stereo
00165 //               camera, in which case the right eye matrix will be
00166 //               used to draw the scene in the right eye (but the
00167 //               center matrix--the user_mat--will still be used to
00168 //               cull the scene).
00169 //
00170 //               This matrix should not be too different from the
00171 //               center matrix (set by set_user_mat()) or culling
00172 //               errors may become obvious.
00173 ////////////////////////////////////////////////////////////////////
00174 INLINE void MatrixLens::
00175 set_right_eye_mat(const LMatrix4 &right_eye_mat) {
00176   Lens::CDWriter lens_cdata(Lens::_cycler, true);
00177   _right_eye_mat = right_eye_mat;
00178   _ml_flags |= MF_has_right_eye;
00179   do_adjust_comp_flags(lens_cdata, CF_mat, 0);
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: MatrixLens::clear_right_eye_mat
00184 //       Access: Published
00185 //  Description: Removes the custom projection matrix set for the right
00186 //               eye, and uses the center matrix (set by set_user_mat)
00187 //               instead.
00188 ////////////////////////////////////////////////////////////////////
00189 INLINE void MatrixLens::
00190 clear_right_eye_mat() {
00191   Lens::CDWriter lens_cdata(Lens::_cycler, true);
00192   _ml_flags &= ~MF_has_right_eye;
00193   do_adjust_comp_flags(lens_cdata, CF_mat, 0);
00194 }
00195 
00196 ////////////////////////////////////////////////////////////////////
00197 //     Function: MatrixLens::has_right_eye_mat
00198 //       Access: Published
00199 //  Description: Returns true if the camera has a custom projection
00200 //               matrix set for the right eye, or false if the center
00201 //               matrix (set by set_user_mat) will be used for the
00202 //               right eye.
00203 ////////////////////////////////////////////////////////////////////
00204 INLINE bool MatrixLens::
00205 has_right_eye_mat() const {
00206   return (_ml_flags & MF_has_right_eye) != 0;
00207 }
00208 
00209 ////////////////////////////////////////////////////////////////////
00210 //     Function: MatrixLens::get_right_eye_mat
00211 //       Access: Published
00212 //  Description: Returns the custom projection matrix for the right
00213 //               eye, if any, or the center matrix if there is no
00214 //               custom matrix set for the right eye.
00215 ////////////////////////////////////////////////////////////////////
00216 INLINE const LMatrix4 &MatrixLens::
00217 get_right_eye_mat() const {
00218   if ((_ml_flags & MF_has_right_eye) != 0) {
00219     return _right_eye_mat;
00220   }
00221   return _user_mat;
00222 }
 All Classes Functions Variables Enumerations