Panda3D

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(LMatrix4f::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.0f);
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 LMatrix4f &user_mat) {
00079   _user_mat = user_mat;
00080   adjust_comp_flags(CF_mat, 0);
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: MatrixLens::get_user_mat
00085 //       Access: Published
00086 //  Description: Returns the explicit projection matrix as set by the
00087 //               user.  This does not include transforms on the lens
00088 //               or film (e.g. a film offset or view hpr).
00089 ////////////////////////////////////////////////////////////////////
00090 INLINE const LMatrix4f &MatrixLens::
00091 get_user_mat() const {
00092   return _user_mat;
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: MatrixLens::set_left_eye_mat
00097 //       Access: Published
00098 //  Description: Sets a custom projection matrix for the left eye.
00099 //               This is only used if the lens is attached to a stereo
00100 //               camera, in which case the left eye matrix will be
00101 //               used to draw the scene in the left eye (but the
00102 //               center matrix--the user_mat--will still be used to
00103 //               cull the scene).
00104 //
00105 //               This matrix should not be too different from the
00106 //               center matrix (set by set_user_mat()) or culling
00107 //               errors may become obvious.
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE void MatrixLens::
00110 set_left_eye_mat(const LMatrix4f &left_eye_mat) {
00111   _left_eye_mat = left_eye_mat;
00112   _ml_flags |= MF_has_left_eye;
00113   adjust_comp_flags(CF_mat, 0);
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: MatrixLens::clear_left_eye_mat
00118 //       Access: Published
00119 //  Description: Removes the custom projection matrix set for the left
00120 //               eye, and uses the center matrix (set by set_user_mat)
00121 //               instead.
00122 ////////////////////////////////////////////////////////////////////
00123 INLINE void MatrixLens::
00124 clear_left_eye_mat() {
00125   _ml_flags &= ~MF_has_left_eye;
00126   adjust_comp_flags(CF_mat, 0);
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: MatrixLens::has_left_eye_mat
00131 //       Access: Published
00132 //  Description: Returns true if the camera has a custom projection
00133 //               matrix set for the left eye, or false if the center
00134 //               matrix (set by set_user_mat) will be used for the
00135 //               left eye.
00136 ////////////////////////////////////////////////////////////////////
00137 INLINE bool MatrixLens::
00138 has_left_eye_mat() const {
00139   return (_ml_flags & MF_has_left_eye) != 0;
00140 }
00141 
00142 ////////////////////////////////////////////////////////////////////
00143 //     Function: MatrixLens::get_left_eye_mat
00144 //       Access: Published
00145 //  Description: Returns the custom projection matrix for the left
00146 //               eye, if any, or the center matrix if there is no
00147 //               custom matrix set for the left eye.
00148 ////////////////////////////////////////////////////////////////////
00149 INLINE const LMatrix4f &MatrixLens::
00150 get_left_eye_mat() const {
00151   if ((_ml_flags & MF_has_left_eye) != 0) {
00152     return _left_eye_mat;
00153   }
00154   return _user_mat;
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: MatrixLens::set_right_eye_mat
00159 //       Access: Published
00160 //  Description: Sets a custom projection matrix for the right eye.
00161 //               This is only used if the lens is attached to a stereo
00162 //               camera, in which case the right eye matrix will be
00163 //               used to draw the scene in the right eye (but the
00164 //               center matrix--the user_mat--will still be used to
00165 //               cull the scene).
00166 //
00167 //               This matrix should not be too different from the
00168 //               center matrix (set by set_user_mat()) or culling
00169 //               errors may become obvious.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE void MatrixLens::
00172 set_right_eye_mat(const LMatrix4f &right_eye_mat) {
00173   _right_eye_mat = right_eye_mat;
00174   _ml_flags |= MF_has_right_eye;
00175   adjust_comp_flags(CF_mat, 0);
00176 }
00177 
00178 ////////////////////////////////////////////////////////////////////
00179 //     Function: MatrixLens::clear_right_eye_mat
00180 //       Access: Published
00181 //  Description: Removes the custom projection matrix set for the right
00182 //               eye, and uses the center matrix (set by set_user_mat)
00183 //               instead.
00184 ////////////////////////////////////////////////////////////////////
00185 INLINE void MatrixLens::
00186 clear_right_eye_mat() {
00187   _ml_flags &= ~MF_has_right_eye;
00188   adjust_comp_flags(CF_mat, 0);
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //     Function: MatrixLens::has_right_eye_mat
00193 //       Access: Published
00194 //  Description: Returns true if the camera has a custom projection
00195 //               matrix set for the right eye, or false if the center
00196 //               matrix (set by set_user_mat) will be used for the
00197 //               right eye.
00198 ////////////////////////////////////////////////////////////////////
00199 INLINE bool MatrixLens::
00200 has_right_eye_mat() const {
00201   return (_ml_flags & MF_has_right_eye) != 0;
00202 }
00203 
00204 ////////////////////////////////////////////////////////////////////
00205 //     Function: MatrixLens::get_right_eye_mat
00206 //       Access: Published
00207 //  Description: Returns the custom projection matrix for the right
00208 //               eye, if any, or the center matrix if there is no
00209 //               custom matrix set for the right eye.
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE const LMatrix4f &MatrixLens::
00212 get_right_eye_mat() const {
00213   if ((_ml_flags & MF_has_right_eye) != 0) {
00214     return _right_eye_mat;
00215   }
00216   return _user_mat;
00217 }
 All Classes Functions Variables Enumerations