Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/lens.I

Go to the documentation of this file.
00001 // Filename: lens.I
00002 // Created by:  drose (29Nov01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: Lens::extrude
00022 //       Access: Published
00023 //  Description: Given a 2-d point in the range (-1,1) in both
00024 //               dimensions, where (0,0) is the center of the
00025 //               lens and (-1,-1) is the lower-left corner,
00026 //               compute the corresponding vector in space that maps
00027 //               to this point, if such a vector can be determined.
00028 //               The vector is returned by indicating the points on
00029 //               the near plane and far plane that both map to the
00030 //               indicated 2-d point.
00031 //
00032 //               Returns true if the vector is defined, or false
00033 //               otherwise.
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE bool Lens::
00036 extrude(const LPoint2f &point2d, LPoint3f &near_point, LPoint3f &far_point) const {
00037   return extrude_impl(LPoint3f(point2d[0], point2d[1], 0.0f),
00038                       near_point, far_point);
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: Lens::extrude
00043 //       Access: Published
00044 //  Description: Given a 2-d point in the range (-1,1) in both
00045 //               dimensions, where (0,0) is the center of the
00046 //               lens and (-1,-1) is the lower-left corner,
00047 //               compute the corresponding vector in space that maps
00048 //               to this point, if such a vector can be determined.
00049 //               The vector is returned by indicating the points on
00050 //               the near plane and far plane that both map to the
00051 //               indicated 2-d point.
00052 //
00053 //               The z coordinate of the 2-d point is ignored.
00054 //
00055 //               Returns true if the vector is defined, or false
00056 //               otherwise.
00057 ////////////////////////////////////////////////////////////////////
00058 INLINE bool Lens::
00059 extrude(const LPoint3f &point2d, LPoint3f &near_point, LPoint3f &far_point) const {
00060   return extrude_impl(point2d, near_point, far_point);
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: Lens::project
00065 //       Access: Published
00066 //  Description: Given a 3-d point in space, determine the 2-d point
00067 //               this maps to, in the range (-1,1) in both dimensions,
00068 //               where (0,0) is the center of the lens and
00069 //               (-1,-1) is the lower-left corner.
00070 //
00071 //               Returns true if the 3-d point is in front of the lens
00072 //               and within the viewing frustum (in which case point2d
00073 //               is filled in), or false otherwise (in which case
00074 //               point2d will be filled in with something, which may
00075 //               or may not be meaningful).
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE bool Lens::
00078 project(const LPoint3f &point3d, LPoint2f &point2d) const {
00079   LPoint3f result;
00080   bool okflag = project_impl(point3d, result);
00081   point2d.set(result[0], result[1]);
00082   return okflag;
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: Lens::project
00087 //       Access: Published
00088 //  Description: Given a 3-d point in space, determine the 2-d point
00089 //               this maps to, in the range (-1,1) in both dimensions,
00090 //               where (0,0) is the center of the lens and
00091 //               (-1,-1) is the lower-left corner.
00092 //
00093 //               The z coordinate will also be set to a value in the
00094 //               range (-1, 1), where 1 represents a point on the near
00095 //               plane, and -1 represents a point on the far plane.
00096 //
00097 //               Returns true if the 3-d point is in front of the lens
00098 //               and within the viewing frustum (in which case point2d
00099 //               is filled in), or false otherwise (in which case
00100 //               point2d will be filled in with something, which may
00101 //               or may not be meaningful).
00102 ////////////////////////////////////////////////////////////////////
00103 INLINE bool Lens::
00104 project(const LPoint3f &point3d, LPoint3f &point2d) const {
00105   return project_impl(point3d, point2d);
00106 }
00107 
00108 ////////////////////////////////////////////////////////////////////
00109 //     Function: Lens::set_change_event
00110 //       Access: Published
00111 //  Description: Sets the name of the event that will be generated
00112 //               whenever any properties of the Lens have
00113 //               changed.  If this is not set for a particular lens,
00114 //               no event will be generated.
00115 //
00116 //               The event is thrown with one parameter, the lens
00117 //               itself.  This can be used to automatically track
00118 //               changes to camera fov, etc. in the application.
00119 ////////////////////////////////////////////////////////////////////
00120 INLINE void Lens::
00121 set_change_event(const string &event) {
00122   _change_event = event;
00123 }
00124 
00125 ////////////////////////////////////////////////////////////////////
00126 //     Function: Lens::get_change_event
00127 //       Access: Published
00128 //  Description: Returns the name of the event that will be generated
00129 //               whenever any properties of this particular Lens have
00130 //               changed.
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE const string &Lens::
00133 get_change_event() const {
00134   return _change_event;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: Lens::get_coordinate_system
00139 //       Access: Published
00140 //  Description: Returns the coordinate system that all 3-d
00141 //               computations are performed within for this
00142 //               Lens.  Normally, this is CS_default.
00143 ////////////////////////////////////////////////////////////////////
00144 INLINE CoordinateSystem Lens::
00145 get_coordinate_system() const {
00146   return _cs;
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: Lens::set_film_size
00151 //       Access: Published
00152 //  Description: Sets the size and shape of the "film" within the
00153 //               lens.  This both establishes the units used by
00154 //               calls like set_focal_length(), and establishes the
00155 //               aspect ratio of the frame.
00156 //
00157 //               In a physical camera, the field of view of a lens is
00158 //               determined by the lens' focal length and by the size
00159 //               of the film area exposed by the lens.  For instance,
00160 //               a 35mm camera exposes a rectangle on the film about
00161 //               24mm x 36mm, which means a 50mm lens gives about a
00162 //               40-degree horizontal field of view.
00163 //
00164 //               In the virtual camera, you may set the film size to
00165 //               any units here, and specify a focal length in the
00166 //               same units to simulate the same effect.  Or, you may
00167 //               ignore this parameter, and specify the field of view
00168 //               and aspect ratio of the lens directly.
00169 ////////////////////////////////////////////////////////////////////
00170 INLINE void Lens::
00171 set_film_size(float width, float height) {
00172   set_film_size(LVecBase2f(width, height));
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: Lens::set_film_offset
00177 //       Access: Published
00178 //  Description: Sets the horizontal and vertical offset amounts of
00179 //               this Lens.  These are both in the same units
00180 //               specified in set_film_size().
00181 //
00182 //               This can be used to establish an off-axis lens.
00183 ////////////////////////////////////////////////////////////////////
00184 INLINE void Lens::
00185 set_film_offset(float x, float y) {
00186   set_film_offset(LVecBase2f(x, y));
00187 }
00188 
00189 ////////////////////////////////////////////////////////////////////
00190 //     Function: Lens::set_film_offset
00191 //       Access: Published
00192 //  Description: Sets the horizontal and vertical offset amounts of
00193 //               this Lens.  These are both in the same units
00194 //               specified in set_film_size().
00195 //
00196 //               This can be used to establish an off-axis lens.
00197 ////////////////////////////////////////////////////////////////////
00198 INLINE void Lens::
00199 set_film_offset(const LVecBase2f &film_offset) {
00200   _film_offset = film_offset;
00201   adjust_comp_flags(CF_mat, 0);
00202   throw_change_event();
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: Lens::get_film_offset
00207 //       Access: Published
00208 //  Description: Returns the horizontal and vertical offset amounts of
00209 //               this Lens.  See set_film_offset().
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE const LVector2f &Lens::
00212 get_film_offset() const {
00213   return _film_offset;
00214 }
00215 
00216 ////////////////////////////////////////////////////////////////////
00217 //     Function: Lens::set_fov
00218 //       Access: Published
00219 //  Description: Sets the field of view of the lens in both
00220 //               dimensions.  This establishes both the field of view
00221 //               and the aspect ratio of the lens.  This is one way to
00222 //               specify the field of view of a lens;
00223 //               set_focal_length() is another way.
00224 //
00225 //               For certain kinds of lenses (like OrthoLens),
00226 //               the field of view has no meaning.
00227 ////////////////////////////////////////////////////////////////////
00228 INLINE void Lens::
00229 set_fov(float hfov, float vfov) {
00230   set_fov(LVecBase2f(hfov, vfov));
00231 }
00232 
00233 ////////////////////////////////////////////////////////////////////
00234 //     Function: Lens::get_hfov
00235 //       Access: Published
00236 //  Description: Returns the horizontal component of fov only.  See
00237 //               get_fov().
00238 ////////////////////////////////////////////////////////////////////
00239 INLINE float Lens::
00240 get_hfov() const {
00241   return get_fov()[0];
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: Lens::get_vfov
00246 //       Access: Published
00247 //  Description: Returns the vertical component of fov only.  See
00248 //               get_fov().
00249 ////////////////////////////////////////////////////////////////////
00250 INLINE float Lens::
00251 get_vfov() const {
00252   return get_fov()[1];
00253 }
00254 
00255 ////////////////////////////////////////////////////////////////////
00256 //     Function: Lens::set_near
00257 //       Access: Published
00258 //  Description: Defines the position of the near plane (or cylinder,
00259 //               sphere, whatever).  Points closer to the lens than
00260 //               this may not be rendered.
00261 ////////////////////////////////////////////////////////////////////
00262 INLINE void Lens::
00263 set_near(float near_distance) {
00264   _near_distance = near_distance;
00265   adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
00266   throw_change_event();
00267 }
00268 
00269 ////////////////////////////////////////////////////////////////////
00270 //     Function: Lens::get_near
00271 //       Access: Published
00272 //  Description: Returns the position of the near plane (or cylinder,
00273 //               sphere, whatever).
00274 ////////////////////////////////////////////////////////////////////
00275 INLINE float Lens::
00276 get_near() const {
00277   return _near_distance;
00278 }
00279 
00280 ////////////////////////////////////////////////////////////////////
00281 //     Function: Lens::set_far
00282 //       Access: Published
00283 //  Description: Defines the position of the far plane (or cylinder,
00284 //               sphere, whatever).  Points farther from the lens than
00285 //               this may not be rendered.
00286 ////////////////////////////////////////////////////////////////////
00287 INLINE void Lens::
00288 set_far(float far_distance) {
00289   _far_distance = far_distance;
00290   adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
00291   throw_change_event();
00292 }
00293 
00294 ////////////////////////////////////////////////////////////////////
00295 //     Function: Lens::get_far
00296 //       Access: Published
00297 //  Description: Returns the position of the far plane (or cylinder,
00298 //               sphere, whatever).
00299 ////////////////////////////////////////////////////////////////////
00300 INLINE float Lens::
00301 get_far() const {
00302   return _far_distance;
00303 }
00304 
00305 ////////////////////////////////////////////////////////////////////
00306 //     Function: Lens::set_near_far
00307 //       Access: Published
00308 //  Description: Simultaneously changes the near and far planes.
00309 ////////////////////////////////////////////////////////////////////
00310 INLINE void Lens::
00311 set_near_far(float near_distance, float far_distance) {
00312   _near_distance = near_distance;
00313   _far_distance = far_distance;
00314   adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
00315   throw_change_event();
00316 }
00317 
00318 ////////////////////////////////////////////////////////////////////
00319 //     Function: Lens::set_view_hpr
00320 //       Access: Published
00321 //  Description: Sets the direction in which the lens is facing.
00322 //               Normally, this is down the forward axis (usually the
00323 //               Y axis), but it may be rotated.  This is only one way
00324 //               of specifying the rotation; you may also specify an
00325 //               explicit vector in which to look, or you may give a
00326 //               complete transformation matrix.
00327 ////////////////////////////////////////////////////////////////////
00328 INLINE void Lens::
00329 set_view_hpr(float h, float p, float r) {
00330   set_view_hpr(LVecBase3f(h, p, r));
00331 }
00332 ////////////////////////////////////////////////////////////////////
00333 //     Function: Lens::set_view_vector
00334 //       Access: Published
00335 //  Description: Specifies the direction in which the lens is facing
00336 //               by giving an axis to look along, and a perpendicular
00337 //               (or at least non-parallel) up axis.
00338 //
00339 //               See also set_view_hpr().
00340 ////////////////////////////////////////////////////////////////////
00341 INLINE void Lens::
00342 set_view_vector(float x, float y, float z, float i, float j, float k) {
00343   set_view_vector(LVector3f(x, y, z), LVector3f(i, j, k));
00344 }
00345 
00346 ////////////////////////////////////////////////////////////////////
00347 //     Function: Lens::get_last_change
00348 //       Access: Public
00349 //  Description: Returns the UpdateSeq that is incremented whenever
00350 //               the lens properties are changed.  As long as this
00351 //               number remains the same, you may assume the lens
00352 //               properties are unchanged.
00353 ////////////////////////////////////////////////////////////////////
00354 INLINE const UpdateSeq &Lens::
00355 get_last_change() const {
00356   return _last_change;
00357 }
00358 
00359 ////////////////////////////////////////////////////////////////////
00360 //     Function: Lens::adjust_user_flags
00361 //       Access: Protected
00362 //  Description: Clears from _user_flags the bits in the first
00363 //               parameter, and sets the bits in the second parameter.
00364 ////////////////////////////////////////////////////////////////////
00365 INLINE void Lens::
00366 adjust_user_flags(int clear_flags, int set_flags) {
00367   _user_flags = (_user_flags & ~clear_flags) | set_flags;
00368 }
00369 
00370 ////////////////////////////////////////////////////////////////////
00371 //     Function: Lens::adjust_comp_flags
00372 //       Access: Protected
00373 //  Description: Clears from _comp_flags the bits in the first
00374 //               parameter, and sets the bits in the second parameter.
00375 ////////////////////////////////////////////////////////////////////
00376 INLINE void Lens::
00377 adjust_comp_flags(int clear_flags, int set_flags) {
00378   _comp_flags = (_comp_flags & ~clear_flags) | set_flags;
00379 }
00380 
00381 EXPCL_PANDA INLINE ostream &
00382 operator << (ostream &out, const Lens &lens) {
00383   lens.output(out);
00384   return out;
00385 }

Generated on Fri May 2 00:39:35 2003 for Panda by doxygen1.3