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