Panda3D
 All Classes Functions Variables Enumerations
matrixLens.I
1 // Filename: matrixLens.I
2 // Created by: drose (12Dec01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: MatrixLens::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE MatrixLens::
21 MatrixLens() :
22  _user_mat(LMatrix4::ident_mat()),
23  _ml_flags(0)
24 {
25  // The default film size for a MatrixLens is 2, which makes the
26  // default range for both X and Y be [-1, 1]. This also,
27  // incidentally, makes the film_mat be identity.
28  set_film_size(2.0);
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: MatrixLens::Copy Constructor
33 // Access: Public
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 INLINE MatrixLens::
37 MatrixLens(const MatrixLens &copy) :
38  Lens(copy),
39  _user_mat(copy._user_mat),
40  _left_eye_mat(copy._left_eye_mat),
41  _right_eye_mat(copy._right_eye_mat),
42  _ml_flags(copy._ml_flags)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: MatrixLens::Copy Assignment Operator
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 INLINE void MatrixLens::
52 operator = (const MatrixLens &copy) {
53  Lens::operator = (copy);
54  _user_mat = copy._user_mat;
55  _left_eye_mat = copy._left_eye_mat;
56  _right_eye_mat = copy._right_eye_mat;
57  _ml_flags = copy._ml_flags;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: MatrixLens::set_user_mat
62 // Access: Published
63 // Description: Explicitly specifies the projection matrix. This
64 // matrix should convert X and Y to the range
65 // [-film_size/2, film_size/2], where (-fs/2,-fs/2) is
66 // the lower left corner of the screen and (fs/2, fs/2)
67 // is the upper right. Z should go to the range [-1,
68 // 1], where -1 is the far plane and 1 is the near
69 // plane. Note that this is a left-handed Y-up
70 // coordinate system.
71 //
72 // The default film_size for a MatrixLens is 2, so the
73 // default range is [-1, 1] for both X and Y. This is
74 // consistent with the GL conventions for projection
75 // matrices.
76 ////////////////////////////////////////////////////////////////////
77 INLINE void MatrixLens::
78 set_user_mat(const LMatrix4 &user_mat) {
79  Lens::CDWriter lens_cdata(Lens::_cycler, true);
80  _user_mat = user_mat;
81  do_adjust_comp_flags(lens_cdata, CF_mat, 0);
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: MatrixLens::get_user_mat
86 // Access: Published
87 // Description: Returns the explicit projection matrix as set by the
88 // user. This does not include transforms on the lens
89 // or film (e.g. a film offset or view hpr).
90 ////////////////////////////////////////////////////////////////////
91 INLINE const LMatrix4 &MatrixLens::
92 get_user_mat() const {
93  return _user_mat;
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: MatrixLens::set_left_eye_mat
98 // Access: Published
99 // Description: Sets a custom projection matrix for the left eye.
100 // This is only used if the lens is attached to a stereo
101 // camera, in which case the left eye matrix will be
102 // used to draw the scene in the left eye (but the
103 // center matrix--the user_mat--will still be used to
104 // cull the scene).
105 //
106 // This matrix should not be too different from the
107 // center matrix (set by set_user_mat()) or culling
108 // errors may become obvious.
109 ////////////////////////////////////////////////////////////////////
110 INLINE void MatrixLens::
111 set_left_eye_mat(const LMatrix4 &left_eye_mat) {
112  Lens::CDWriter lens_cdata(Lens::_cycler, true);
113  _left_eye_mat = left_eye_mat;
114  _ml_flags |= MF_has_left_eye;
115  do_adjust_comp_flags(lens_cdata, CF_mat, 0);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: MatrixLens::clear_left_eye_mat
120 // Access: Published
121 // Description: Removes the custom projection matrix set for the left
122 // eye, and uses the center matrix (set by set_user_mat)
123 // instead.
124 ////////////////////////////////////////////////////////////////////
125 INLINE void MatrixLens::
127  Lens::CDWriter lens_cdata(Lens::_cycler, true);
128  _ml_flags &= ~MF_has_left_eye;
129  do_adjust_comp_flags(lens_cdata, CF_mat, 0);
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: MatrixLens::has_left_eye_mat
134 // Access: Published
135 // Description: Returns true if the camera has a custom projection
136 // matrix set for the left eye, or false if the center
137 // matrix (set by set_user_mat) will be used for the
138 // left eye.
139 ////////////////////////////////////////////////////////////////////
140 INLINE bool MatrixLens::
142  return (_ml_flags & MF_has_left_eye) != 0;
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function: MatrixLens::get_left_eye_mat
147 // Access: Published
148 // Description: Returns the custom projection matrix for the left
149 // eye, if any, or the center matrix if there is no
150 // custom matrix set for the left eye.
151 ////////////////////////////////////////////////////////////////////
152 INLINE const LMatrix4 &MatrixLens::
154  if ((_ml_flags & MF_has_left_eye) != 0) {
155  return _left_eye_mat;
156  }
157  return _user_mat;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: MatrixLens::set_right_eye_mat
162 // Access: Published
163 // Description: Sets a custom projection matrix for the right eye.
164 // This is only used if the lens is attached to a stereo
165 // camera, in which case the right eye matrix will be
166 // used to draw the scene in the right eye (but the
167 // center matrix--the user_mat--will still be used to
168 // cull the scene).
169 //
170 // This matrix should not be too different from the
171 // center matrix (set by set_user_mat()) or culling
172 // errors may become obvious.
173 ////////////////////////////////////////////////////////////////////
174 INLINE void MatrixLens::
175 set_right_eye_mat(const LMatrix4 &right_eye_mat) {
176  Lens::CDWriter lens_cdata(Lens::_cycler, true);
177  _right_eye_mat = right_eye_mat;
178  _ml_flags |= MF_has_right_eye;
179  do_adjust_comp_flags(lens_cdata, CF_mat, 0);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: MatrixLens::clear_right_eye_mat
184 // Access: Published
185 // Description: Removes the custom projection matrix set for the right
186 // eye, and uses the center matrix (set by set_user_mat)
187 // instead.
188 ////////////////////////////////////////////////////////////////////
189 INLINE void MatrixLens::
191  Lens::CDWriter lens_cdata(Lens::_cycler, true);
192  _ml_flags &= ~MF_has_right_eye;
193  do_adjust_comp_flags(lens_cdata, CF_mat, 0);
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: MatrixLens::has_right_eye_mat
198 // Access: Published
199 // Description: Returns true if the camera has a custom projection
200 // matrix set for the right eye, or false if the center
201 // matrix (set by set_user_mat) will be used for the
202 // right eye.
203 ////////////////////////////////////////////////////////////////////
204 INLINE bool MatrixLens::
206  return (_ml_flags & MF_has_right_eye) != 0;
207 }
208 
209 ////////////////////////////////////////////////////////////////////
210 // Function: MatrixLens::get_right_eye_mat
211 // Access: Published
212 // Description: Returns the custom projection matrix for the right
213 // eye, if any, or the center matrix if there is no
214 // custom matrix set for the right eye.
215 ////////////////////////////////////////////////////////////////////
216 INLINE const LMatrix4 &MatrixLens::
218  if ((_ml_flags & MF_has_right_eye) != 0) {
219  return _right_eye_mat;
220  }
221  return _user_mat;
222 }
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:45
const LMatrix4 & get_left_eye_mat() const
Returns the custom projection matrix for the left eye, if any, or the center matrix if there is no cu...
Definition: matrixLens.I:153
A completely generic linear lens.
Definition: matrixLens.h:31
const LMatrix4 & get_right_eye_mat() const
Returns the custom projection matrix for the right eye, if any, or the center matrix if there is no c...
Definition: matrixLens.I:217
const LMatrix4 & get_user_mat() const
Returns the explicit projection matrix as set by the user.
Definition: matrixLens.I:92
void set_film_size(PN_stdfloat width)
Sets the horizontal size of the film without changing its shape.
Definition: lens.I:226
void set_right_eye_mat(const LMatrix4 &user_mat)
Sets a custom projection matrix for the right eye.
Definition: matrixLens.I:175
void clear_right_eye_mat()
Removes the custom projection matrix set for the right eye, and uses the center matrix (set by set_us...
Definition: matrixLens.I:190
bool has_left_eye_mat() const
Returns true if the camera has a custom projection matrix set for the left eye, or false if the cente...
Definition: matrixLens.I:141
void set_user_mat(const LMatrix4 &user_mat)
Explicitly specifies the projection matrix.
Definition: matrixLens.I:78
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
void clear_left_eye_mat()
Removes the custom projection matrix set for the left eye, and uses the center matrix (set by set_use...
Definition: matrixLens.I:126
void set_left_eye_mat(const LMatrix4 &user_mat)
Sets a custom projection matrix for the left eye.
Definition: matrixLens.I:111
bool has_right_eye_mat() const
Returns true if the camera has a custom projection matrix set for the right eye, or false if the cent...
Definition: matrixLens.I:205