00001 // Filename: lens.I 00002 // Created by: drose (29Nov01) 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 //////////////////////////////////////////////////////////////////// 00017 // Function: Lens::extrude 00018 // Access: Published 00019 // Description: Given a 2-d point in the range (-1,1) in both 00020 // dimensions, where (0,0) is the center of the 00021 // lens and (-1,-1) is the lower-left corner, 00022 // compute the corresponding vector in space that maps 00023 // to this point, if such a vector can be determined. 00024 // The vector is returned by indicating the points on 00025 // the near plane and far plane that both map to the 00026 // indicated 2-d point. 00027 // 00028 // Returns true if the vector is defined, or false 00029 // otherwise. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE bool Lens:: 00032 extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const { 00033 CDReader cdata(_cycler); 00034 return do_extrude(cdata, LPoint3(point2d[0], point2d[1], 0.0f), 00035 near_point, far_point); 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: Lens::extrude 00040 // Access: Published 00041 // Description: Given a 2-d point in the range (-1,1) in both 00042 // dimensions, where (0,0) is the center of the 00043 // lens and (-1,-1) is the lower-left corner, 00044 // compute the corresponding vector in space that maps 00045 // to this point, if such a vector can be determined. 00046 // The vector is returned by indicating the points on 00047 // the near plane and far plane that both map to the 00048 // indicated 2-d point. 00049 // 00050 // The z coordinate of the 2-d point is ignored. 00051 // 00052 // Returns true if the vector is defined, or false 00053 // otherwise. 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE bool Lens:: 00056 extrude(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const { 00057 CDReader cdata(_cycler); 00058 return do_extrude(cdata, point2d, near_point, far_point); 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: Lens::extrude_vec 00063 // Access: Published 00064 // Description: Given a 2-d point in the range (-1,1) in both 00065 // dimensions, where (0,0) is the center of the 00066 // lens and (-1,-1) is the lower-left corner, 00067 // compute the vector that corresponds to the view 00068 // direction. This will be parallel to the normal on 00069 // the surface (the far plane) corresponding to the lens 00070 // shape at this point. 00071 // 00072 // See the comment block on Lens::extrude_vec_impl() for 00073 // a more in-depth comment on the meaning of this 00074 // vector. 00075 // 00076 // Returns true if the vector is defined, or false 00077 // otherwise. 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE bool Lens:: 00080 extrude_vec(const LPoint2 &point2d, LVector3 &vec) const { 00081 CDReader cdata(_cycler); 00082 return do_extrude_vec(cdata, LPoint3(point2d[0], point2d[1], 0.0f), vec); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: Lens::extrude_vec 00087 // Access: Published 00088 // Description: Given a 2-d point in the range (-1,1) in both 00089 // dimensions, where (0,0) is the center of the 00090 // lens and (-1,-1) is the lower-left corner, 00091 // compute the vector that corresponds to the view 00092 // direction. This will be parallel to the normal on 00093 // the surface (the far plane) corresponding to the lens 00094 // shape at this point. 00095 // 00096 // See the comment block on Lens::extrude_vec_impl() for 00097 // a more in-depth comment on the meaning of this 00098 // vector. 00099 // 00100 // The z coordinate of the 2-d point is ignored. 00101 // 00102 // Returns true if the vector is defined, or false 00103 // otherwise. 00104 //////////////////////////////////////////////////////////////////// 00105 INLINE bool Lens:: 00106 extrude_vec(const LPoint3 &point2d, LVector3 &vec) const { 00107 CDReader cdata(_cycler); 00108 return do_extrude_vec(cdata, point2d, vec); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: Lens::project 00113 // Access: Published 00114 // Description: Given a 3-d point in space, determine the 2-d point 00115 // this maps to, in the range (-1,1) in both dimensions, 00116 // where (0,0) is the center of the lens and 00117 // (-1,-1) is the lower-left corner. 00118 // 00119 // Returns true if the 3-d point is in front of the lens 00120 // and within the viewing frustum (in which case point2d 00121 // is filled in), or false otherwise (in which case 00122 // point2d will be filled in with something, which may 00123 // or may not be meaningful). 00124 //////////////////////////////////////////////////////////////////// 00125 INLINE bool Lens:: 00126 project(const LPoint3 &point3d, LPoint2 &point2d) const { 00127 CDReader cdata(_cycler); 00128 LPoint3 result; 00129 bool okflag = do_project(cdata, point3d, result); 00130 point2d.set(result[0], result[1]); 00131 return okflag; 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: Lens::project 00136 // Access: Published 00137 // Description: Given a 3-d point in space, determine the 2-d point 00138 // this maps to, in the range (-1,1) in both dimensions, 00139 // where (0,0) is the center of the lens and 00140 // (-1,-1) is the lower-left corner. 00141 // 00142 // The z coordinate will also be set to a value in the 00143 // range (-1, 1), where 1 represents a point on the near 00144 // plane, and -1 represents a point on the far plane. 00145 // 00146 // Returns true if the 3-d point is in front of the lens 00147 // and within the viewing frustum (in which case point2d 00148 // is filled in), or false otherwise (in which case 00149 // point2d will be filled in with something, which may 00150 // or may not be meaningful). 00151 //////////////////////////////////////////////////////////////////// 00152 INLINE bool Lens:: 00153 project(const LPoint3 &point3d, LPoint3 &point2d) const { 00154 CDReader cdata(_cycler); 00155 return do_project(cdata, point3d, point2d); 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: Lens::set_change_event 00160 // Access: Published 00161 // Description: Sets the name of the event that will be generated 00162 // whenever any properties of the Lens have 00163 // changed. If this is not set for a particular lens, 00164 // no event will be generated. 00165 // 00166 // The event is thrown with one parameter, the lens 00167 // itself. This can be used to automatically track 00168 // changes to camera fov, etc. in the application. 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE void Lens:: 00171 set_change_event(const string &event) { 00172 CDWriter cdata(_cycler, true); 00173 cdata->_change_event = event; 00174 } 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: Lens::get_change_event 00178 // Access: Published 00179 // Description: Returns the name of the event that will be generated 00180 // whenever any properties of this particular Lens have 00181 // changed. 00182 //////////////////////////////////////////////////////////////////// 00183 INLINE const string &Lens:: 00184 get_change_event() const { 00185 CDReader cdata(_cycler); 00186 return cdata->_change_event; 00187 } 00188 00189 //////////////////////////////////////////////////////////////////// 00190 // Function: Lens::get_coordinate_system 00191 // Access: Published 00192 // Description: Returns the coordinate system that all 3-d 00193 // computations are performed within for this 00194 // Lens. Normally, this is CS_default. 00195 //////////////////////////////////////////////////////////////////// 00196 INLINE CoordinateSystem Lens:: 00197 get_coordinate_system() const { 00198 CDReader cdata(_cycler); 00199 return cdata->_cs; 00200 } 00201 00202 //////////////////////////////////////////////////////////////////// 00203 // Function: Lens::set_film_size 00204 // Access: Published 00205 // Description: Sets the horizontal size of the film without changing 00206 // its shape. The aspect ratio remains unchanged; this 00207 // computes the vertical size of the film to 00208 // automatically maintain the aspect ratio. 00209 //////////////////////////////////////////////////////////////////// 00210 INLINE void Lens:: 00211 set_film_size(PN_stdfloat width) { 00212 CDWriter cdata(_cycler, true); 00213 do_set_film_size(cdata, width); 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: Lens::set_film_size 00218 // Access: Published 00219 // Description: Sets the size and shape of the "film" within the 00220 // lens. This both establishes the units used by 00221 // calls like set_focal_length(), and establishes the 00222 // aspect ratio of the frame. 00223 // 00224 // In a physical camera, the field of view of a lens is 00225 // determined by the lens' focal length and by the size 00226 // of the film area exposed by the lens. For instance, 00227 // a 35mm camera exposes a rectangle on the film about 00228 // 24mm x 36mm, which means a 50mm lens gives about a 00229 // 40-degree horizontal field of view. 00230 // 00231 // In the virtual camera, you may set the film size to 00232 // any units here, and specify a focal length in the 00233 // same units to simulate the same effect. Or, you may 00234 // ignore this parameter, and specify the field of view 00235 // and aspect ratio of the lens directly. 00236 //////////////////////////////////////////////////////////////////// 00237 INLINE void Lens:: 00238 set_film_size(PN_stdfloat width, PN_stdfloat height) { 00239 set_film_size(LVecBase2(width, height)); 00240 } 00241 00242 //////////////////////////////////////////////////////////////////// 00243 // Function: Lens::set_film_size 00244 // Access: Published 00245 // Description: Sets the size and shape of the "film" within the 00246 // lens. This both establishes the units used by 00247 // calls like set_focal_length(), and establishes the 00248 // aspect ratio of the frame. 00249 // 00250 // In a physical camera, the field of view of a lens is 00251 // determined by the lens' focal length and by the size 00252 // of the film area exposed by the lens. For instance, 00253 // a 35mm camera exposes a rectangle on the film about 00254 // 24mm x 36mm, which means a 50mm lens gives about a 00255 // 40-degree horizontal field of view. 00256 // 00257 // In the virtual camera, you may set the film size to 00258 // any units here, and specify a focal length in the 00259 // same units to simulate the same effect. Or, you may 00260 // ignore this parameter, and specify the field of view 00261 // and aspect ratio of the lens directly. 00262 //////////////////////////////////////////////////////////////////// 00263 INLINE void Lens:: 00264 set_film_size(const LVecBase2 &film_size) { 00265 CDWriter cdata(_cycler, true); 00266 do_set_film_size(cdata, film_size); 00267 } 00268 00269 //////////////////////////////////////////////////////////////////// 00270 // Function: Lens::get_film_size 00271 // Access: Published 00272 // Description: Returns the horizontal and vertical film size of 00273 // the virtual film. See set_film_size(). 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE const LVecBase2 &Lens:: 00276 get_film_size() const { 00277 CDReader cdata(_cycler); 00278 return do_get_film_size(cdata); 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: Lens::set_film_offset 00283 // Access: Published 00284 // Description: Sets the horizontal and vertical offset amounts of 00285 // this Lens. These are both in the same units 00286 // specified in set_film_size(). 00287 // 00288 // This can be used to establish an off-axis lens. 00289 //////////////////////////////////////////////////////////////////// 00290 INLINE void Lens:: 00291 set_film_offset(PN_stdfloat x, PN_stdfloat y) { 00292 set_film_offset(LVecBase2(x, y)); 00293 } 00294 00295 //////////////////////////////////////////////////////////////////// 00296 // Function: Lens::set_film_offset 00297 // Access: Published 00298 // Description: Sets the horizontal and vertical offset amounts of 00299 // this Lens. These are both in the same units 00300 // specified in set_film_size(). 00301 // 00302 // This can be used to establish an off-axis lens. 00303 //////////////////////////////////////////////////////////////////// 00304 INLINE void Lens:: 00305 set_film_offset(const LVecBase2 &film_offset) { 00306 CDWriter cdata(_cycler, true); 00307 do_set_film_offset(cdata, film_offset); 00308 } 00309 00310 //////////////////////////////////////////////////////////////////// 00311 // Function: Lens::get_film_offset 00312 // Access: Published 00313 // Description: Returns the horizontal and vertical offset amounts of 00314 // this Lens. See set_film_offset(). 00315 //////////////////////////////////////////////////////////////////// 00316 INLINE const LVector2 &Lens:: 00317 get_film_offset() const { 00318 CDReader cdata(_cycler); 00319 return do_get_film_offset(cdata); 00320 } 00321 00322 //////////////////////////////////////////////////////////////////// 00323 // Function: Lens::set_focal_length 00324 // Access: Published 00325 // Description: Sets the focal length of the lens. This may adjust 00326 // the field-of-view correspondingly, and is an 00327 // alternate way to specify field of view. 00328 // 00329 // For certain kinds of lenses (e.g. OrthographicLens), 00330 // the focal length has no meaning. 00331 //////////////////////////////////////////////////////////////////// 00332 INLINE void Lens:: 00333 set_focal_length(PN_stdfloat focal_length) { 00334 CDWriter cdata(_cycler, true); 00335 do_set_focal_length(cdata, focal_length); 00336 } 00337 00338 //////////////////////////////////////////////////////////////////// 00339 // Function: Lens::get_focal_length 00340 // Access: Published 00341 // Description: Returns the focal length of the lens. This may have 00342 // been set explicitly by a previous call to 00343 // set_focal_length(), or it may be computed based on 00344 // the lens' fov and film_size. For certain kinds of 00345 // lenses, the focal length has no meaning. 00346 //////////////////////////////////////////////////////////////////// 00347 INLINE PN_stdfloat Lens:: 00348 get_focal_length() const { 00349 CDReader cdata(_cycler); 00350 return do_get_focal_length(cdata); 00351 } 00352 00353 //////////////////////////////////////////////////////////////////// 00354 // Function: Lens::set_fov 00355 // Access: Published 00356 // Description: Sets the horizontal field of view of the lens without 00357 // changing the aspect ratio. The vertical field of 00358 // view is adjusted to maintain the same aspect ratio. 00359 //////////////////////////////////////////////////////////////////// 00360 INLINE void Lens:: 00361 set_fov(PN_stdfloat hfov) { 00362 CDWriter cdata(_cycler, true); 00363 do_set_fov(cdata, hfov); 00364 } 00365 00366 //////////////////////////////////////////////////////////////////// 00367 // Function: Lens::set_fov 00368 // Access: Published 00369 // Description: Sets the field of view of the lens in both 00370 // dimensions. This establishes both the field of view 00371 // and the aspect ratio of the lens. This is one way to 00372 // specify the field of view of a lens; 00373 // set_focal_length() is another way. 00374 // 00375 // For certain kinds of lenses (like OrthoLens), 00376 // the field of view has no meaning. 00377 //////////////////////////////////////////////////////////////////// 00378 INLINE void Lens:: 00379 set_fov(PN_stdfloat hfov, PN_stdfloat vfov) { 00380 set_fov(LVecBase2(hfov, vfov)); 00381 } 00382 00383 //////////////////////////////////////////////////////////////////// 00384 // Function: Lens::set_fov 00385 // Access: Published 00386 // Description: Sets the field of view of the lens in both 00387 // dimensions. This establishes both the field of view 00388 // and the aspect ratio of the lens. This is one way to 00389 // specify the field of view of a lens; 00390 // set_focal_length() is another way. 00391 // 00392 // For certain kinds of lenses (like OrthographicLens), 00393 // the field of view has no meaning. 00394 //////////////////////////////////////////////////////////////////// 00395 INLINE void Lens:: 00396 set_fov(const LVecBase2 &fov) { 00397 CDWriter cdata(_cycler, true); 00398 do_set_fov(cdata, fov); 00399 } 00400 00401 //////////////////////////////////////////////////////////////////// 00402 // Function: Lens::get_fov 00403 // Access: Published 00404 // Description: Returns the horizontal and vertical film size of 00405 // the virtual film. See set_fov(). 00406 //////////////////////////////////////////////////////////////////// 00407 INLINE const LVecBase2 &Lens:: 00408 get_fov() const { 00409 CDReader cdata(_cycler); 00410 return do_get_fov(cdata); 00411 } 00412 00413 //////////////////////////////////////////////////////////////////// 00414 // Function: Lens::get_hfov 00415 // Access: Published 00416 // Description: Returns the horizontal component of fov only. See 00417 // get_fov(). 00418 //////////////////////////////////////////////////////////////////// 00419 INLINE PN_stdfloat Lens:: 00420 get_hfov() const { 00421 return get_fov()[0]; 00422 } 00423 00424 //////////////////////////////////////////////////////////////////// 00425 // Function: Lens::get_vfov 00426 // Access: Published 00427 // Description: Returns the vertical component of fov only. See 00428 // get_fov(). 00429 //////////////////////////////////////////////////////////////////// 00430 INLINE PN_stdfloat Lens:: 00431 get_vfov() const { 00432 return get_fov()[1]; 00433 } 00434 00435 //////////////////////////////////////////////////////////////////// 00436 // Function: Lens::set_aspect_ratio 00437 // Access: Published 00438 // Description: Sets the aspect ratio of the lens. This is the ratio 00439 // of the height to the width of the generated image. 00440 // Setting this overrides the two-parameter fov or film 00441 // size setting. 00442 //////////////////////////////////////////////////////////////////// 00443 INLINE void Lens:: 00444 set_aspect_ratio(PN_stdfloat aspect_ratio) { 00445 CDWriter cdata(_cycler, true); 00446 do_set_aspect_ratio(cdata, aspect_ratio); 00447 } 00448 00449 //////////////////////////////////////////////////////////////////// 00450 // Function: Lens::get_aspect_ratio 00451 // Access: Published 00452 // Description: Returns the aspect ratio of the Lens. This is 00453 // determined based on the indicated film size; see 00454 // set_film_size(). 00455 //////////////////////////////////////////////////////////////////// 00456 INLINE PN_stdfloat Lens:: 00457 get_aspect_ratio() const { 00458 CDReader cdata(_cycler); 00459 return do_get_aspect_ratio(cdata); 00460 } 00461 00462 //////////////////////////////////////////////////////////////////// 00463 // Function: Lens::set_near 00464 // Access: Published 00465 // Description: Defines the position of the near plane (or cylinder, 00466 // sphere, whatever). Points closer to the lens than 00467 // this may not be rendered. 00468 //////////////////////////////////////////////////////////////////// 00469 INLINE void Lens:: 00470 set_near(PN_stdfloat near_distance) { 00471 CDWriter cdata(_cycler, true); 00472 do_set_near(cdata, near_distance); 00473 } 00474 00475 //////////////////////////////////////////////////////////////////// 00476 // Function: Lens::get_near 00477 // Access: Published 00478 // Description: Returns the position of the near plane (or cylinder, 00479 // sphere, whatever). 00480 //////////////////////////////////////////////////////////////////// 00481 INLINE PN_stdfloat Lens:: 00482 get_near() const { 00483 CDReader cdata(_cycler); 00484 return do_get_near(cdata); 00485 } 00486 00487 //////////////////////////////////////////////////////////////////// 00488 // Function: Lens::set_far 00489 // Access: Published 00490 // Description: Defines the position of the far plane (or cylinder, 00491 // sphere, whatever). Points farther from the lens than 00492 // this may not be rendered. 00493 //////////////////////////////////////////////////////////////////// 00494 INLINE void Lens:: 00495 set_far(PN_stdfloat far_distance) { 00496 CDWriter cdata(_cycler, true); 00497 do_set_far(cdata, far_distance); 00498 } 00499 00500 //////////////////////////////////////////////////////////////////// 00501 // Function: Lens::get_far 00502 // Access: Published 00503 // Description: Returns the position of the far plane (or cylinder, 00504 // sphere, whatever). 00505 //////////////////////////////////////////////////////////////////// 00506 INLINE PN_stdfloat Lens:: 00507 get_far() const { 00508 CDReader cdata(_cycler); 00509 return do_get_far(cdata); 00510 } 00511 00512 //////////////////////////////////////////////////////////////////// 00513 // Function: Lens::set_near_far 00514 // Access: Published 00515 // Description: Simultaneously changes the near and far planes. 00516 //////////////////////////////////////////////////////////////////// 00517 INLINE void Lens:: 00518 set_near_far(PN_stdfloat near_distance, PN_stdfloat far_distance) { 00519 CDWriter cdata(_cycler, true); 00520 do_set_near_far(cdata, near_distance, far_distance); 00521 } 00522 00523 //////////////////////////////////////////////////////////////////// 00524 // Function: Lens::set_view_hpr 00525 // Access: Published 00526 // Description: Sets the direction in which the lens is facing. 00527 // Normally, this is down the forward axis (usually the 00528 // Y axis), but it may be rotated. This is only one way 00529 // of specifying the rotation; you may also specify an 00530 // explicit vector in which to look, or you may give a 00531 // complete transformation matrix. 00532 //////////////////////////////////////////////////////////////////// 00533 INLINE void Lens:: 00534 set_view_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) { 00535 set_view_hpr(LVecBase3(h, p, r)); 00536 } 00537 00538 //////////////////////////////////////////////////////////////////// 00539 // Function: Lens::set_view_vector 00540 // Access: Published 00541 // Description: Specifies the direction in which the lens is facing 00542 // by giving an axis to look along, and a perpendicular 00543 // (or at least non-parallel) up axis. 00544 // 00545 // See also set_view_hpr(). 00546 //////////////////////////////////////////////////////////////////// 00547 INLINE void Lens:: 00548 set_view_vector(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_stdfloat j, PN_stdfloat k) { 00549 set_view_vector(LVector3(x, y, z), LVector3(i, j, k)); 00550 } 00551 00552 //////////////////////////////////////////////////////////////////// 00553 // Function: Lens::set_interocular_distance 00554 // Access: Published 00555 // Description: Sets the distance between the left and right eyes of 00556 // a stereo camera. This distance is used to apply a 00557 // stereo effect when the lens is rendered on a stereo 00558 // display region. It only has an effect on a 00559 // PerspectiveLens. 00560 // 00561 // The left eye and the right eye are each offset along 00562 // the X axis by half of this distance, so that this 00563 // parameter specifies the total distance between them. 00564 // 00565 // Also see set_convergence_distance(), which relates. 00566 //////////////////////////////////////////////////////////////////// 00567 INLINE void Lens:: 00568 set_interocular_distance(PN_stdfloat interocular_distance) { 00569 CDWriter cdata(_cycler, true); 00570 do_set_interocular_distance(cdata, interocular_distance); 00571 do_throw_change_event(cdata); 00572 } 00573 00574 //////////////////////////////////////////////////////////////////// 00575 // Function: Lens::get_interocular_distance 00576 // Access: Published 00577 // Description: See set_interocular_distance(). 00578 //////////////////////////////////////////////////////////////////// 00579 INLINE PN_stdfloat Lens:: 00580 get_interocular_distance() const { 00581 CDReader cdata(_cycler); 00582 return cdata->_interocular_distance; 00583 } 00584 00585 //////////////////////////////////////////////////////////////////// 00586 // Function: Lens::set_convergence_distance 00587 // Access: Published 00588 // Description: Sets the distance between between the camera plane 00589 // and the point in the distance that the left and right 00590 // eyes are both looking at. This distance is used to 00591 // apply a stereo effect when the lens is rendered on a 00592 // stereo display region. It only has an effect on a 00593 // PerspectiveLens. 00594 // 00595 // This parameter must be greater than 0, but may be as 00596 // large as you like. It controls the amount to which 00597 // the two eyes are directed inwards towards each other, 00598 // which is a normal property of stereo vision. It is a 00599 // distance, not an angle; normally this should be set 00600 // to the distance from the camera to the area of 00601 // interest in your scene. If you want to simulate 00602 // parallel stereo, set this value to a very large 00603 // number. 00604 // 00605 // Also see set_interocular_distance(), which relates. 00606 //////////////////////////////////////////////////////////////////// 00607 INLINE void Lens:: 00608 set_convergence_distance(PN_stdfloat convergence_distance) { 00609 CDWriter cdata(_cycler, true); 00610 do_set_convergence_distance(cdata, convergence_distance); 00611 do_throw_change_event(cdata); 00612 } 00613 00614 //////////////////////////////////////////////////////////////////// 00615 // Function: Lens::get_convergence_distance 00616 // Access: Published 00617 // Description: See set_convergence_distance(). 00618 //////////////////////////////////////////////////////////////////// 00619 INLINE PN_stdfloat Lens:: 00620 get_convergence_distance() const { 00621 CDReader cdata(_cycler); 00622 return cdata->_convergence_distance; 00623 } 00624 00625 //////////////////////////////////////////////////////////////////// 00626 // Function: Lens::set_view_mat 00627 // Access: Published 00628 // Description: Sets an arbitrary transformation on the lens. This 00629 // replaces the individual transformation components 00630 // like set_view_hpr(). 00631 // 00632 // Setting a transformation here will have a slightly 00633 // different effect than putting one on the LensNode 00634 // that contains this lens. In particular, lighting and 00635 // other effects computations will still be performed on 00636 // the lens in its untransformed (facing forward) 00637 // position, but the actual projection matrix will be 00638 // transformed by this matrix. 00639 //////////////////////////////////////////////////////////////////// 00640 INLINE void Lens:: 00641 set_view_mat(const LMatrix4 &view_mat) { 00642 CDWriter cdata(_cycler, true); 00643 do_set_view_mat(cdata, view_mat); 00644 } 00645 00646 //////////////////////////////////////////////////////////////////// 00647 // Function: Lens::get_view_mat 00648 // Access: Published 00649 // Description: Returns the direction in which the lens is facing. 00650 //////////////////////////////////////////////////////////////////// 00651 INLINE const LMatrix4 &Lens:: 00652 get_view_mat() const { 00653 CDReader cdata(_cycler); 00654 return do_get_view_mat(cdata); 00655 } 00656 00657 //////////////////////////////////////////////////////////////////// 00658 // Function: Lens::get_keystone 00659 // Access: Published 00660 // Description: Returns the keystone correction specified for the 00661 // lens. 00662 //////////////////////////////////////////////////////////////////// 00663 INLINE const LVecBase2 &Lens:: 00664 get_keystone() const { 00665 CDReader cdata(_cycler); 00666 return cdata->_keystone; 00667 } 00668 00669 //////////////////////////////////////////////////////////////////// 00670 // Function: Lens::get_projection_mat 00671 // Access: Published 00672 // Description: Returns the complete transformation matrix from a 3-d 00673 // point in space to a point on the film, if such a 00674 // matrix exists, or the identity matrix if the lens is 00675 // nonlinear. 00676 //////////////////////////////////////////////////////////////////// 00677 INLINE const LMatrix4 &Lens:: 00678 get_projection_mat(StereoChannel channel) const { 00679 CDReader cdata(_cycler); 00680 return do_get_projection_mat(cdata, channel); 00681 } 00682 00683 //////////////////////////////////////////////////////////////////// 00684 // Function: Lens::get_projection_mat_inv 00685 // Access: Published 00686 // Description: Returns the matrix that transforms from a 2-d point 00687 // on the film to a 3-d vector in space, if such a 00688 // matrix exists. 00689 //////////////////////////////////////////////////////////////////// 00690 INLINE const LMatrix4 &Lens:: 00691 get_projection_mat_inv(StereoChannel stereo_channel) const { 00692 CDReader cdata(_cycler); 00693 return do_get_projection_mat_inv(cdata, stereo_channel); 00694 } 00695 00696 //////////////////////////////////////////////////////////////////// 00697 // Function: Lens::get_film_mat 00698 // Access: Published 00699 // Description: Returns the matrix that transforms from a point 00700 // behind the lens to a point on the film. 00701 //////////////////////////////////////////////////////////////////// 00702 INLINE const LMatrix4 &Lens:: 00703 get_film_mat() const { 00704 CDReader cdata(_cycler); 00705 return do_get_film_mat(cdata); 00706 } 00707 00708 //////////////////////////////////////////////////////////////////// 00709 // Function: Lens::get_film_mat_inv 00710 // Access: Published 00711 // Description: Returns the matrix that transforms from a point on 00712 // the film to a point behind the lens. 00713 //////////////////////////////////////////////////////////////////// 00714 INLINE const LMatrix4 &Lens:: 00715 get_film_mat_inv() const { 00716 CDReader cdata(_cycler); 00717 return do_get_film_mat_inv(cdata); 00718 } 00719 00720 //////////////////////////////////////////////////////////////////// 00721 // Function: Lens::get_lens_mat 00722 // Access: Published 00723 // Description: Returns the matrix that transforms from a point 00724 // in front of the lens to a point in space. 00725 //////////////////////////////////////////////////////////////////// 00726 INLINE const LMatrix4 &Lens:: 00727 get_lens_mat() const { 00728 CDReader cdata(_cycler); 00729 return do_get_lens_mat(cdata); 00730 } 00731 00732 //////////////////////////////////////////////////////////////////// 00733 // Function: Lens::get_lens_mat_inv 00734 // Access: Published 00735 // Description: Returns the matrix that transforms from a point in 00736 // space to a point in front of the lens. 00737 //////////////////////////////////////////////////////////////////// 00738 INLINE const LMatrix4 &Lens:: 00739 get_lens_mat_inv() const { 00740 CDReader cdata(_cycler); 00741 return do_get_lens_mat_inv(cdata); 00742 } 00743 00744 //////////////////////////////////////////////////////////////////// 00745 // Function: Lens::get_last_change 00746 // Access: Published 00747 // Description: Returns the UpdateSeq that is incremented whenever 00748 // the lens properties are changed. As long as this 00749 // number remains the same, you may assume the lens 00750 // properties are unchanged. 00751 //////////////////////////////////////////////////////////////////// 00752 INLINE UpdateSeq Lens:: 00753 get_last_change() const { 00754 CDReader cdata(_cycler); 00755 return cdata->_last_change; 00756 } 00757 00758 //////////////////////////////////////////////////////////////////// 00759 // Function: Lens::do_adjust_user_flags 00760 // Access: Protected 00761 // Description: Clears from _user_flags the bits in the first 00762 // parameter, and sets the bits in the second parameter. 00763 //////////////////////////////////////////////////////////////////// 00764 INLINE void Lens:: 00765 do_adjust_user_flags(CData *cdata, int clear_flags, int set_flags) { 00766 cdata->_user_flags = (cdata->_user_flags & ~clear_flags) | set_flags; 00767 } 00768 00769 //////////////////////////////////////////////////////////////////// 00770 // Function: Lens::do_adjust_comp_flags 00771 // Access: Protected 00772 // Description: Clears from _comp_flags the bits in the first 00773 // parameter, and sets the bits in the second parameter. 00774 //////////////////////////////////////////////////////////////////// 00775 INLINE void Lens:: 00776 do_adjust_comp_flags(CData *cdata, int clear_flags, int set_flags) { 00777 cdata->_comp_flags = (cdata->_comp_flags & ~clear_flags) | set_flags; 00778 } 00779 00780 //////////////////////////////////////////////////////////////////// 00781 // Function: Lens::do_set_film_offset 00782 // Access: Protected 00783 // Description: 00784 //////////////////////////////////////////////////////////////////// 00785 INLINE void Lens:: 00786 do_set_film_offset(CData *cdata, const LVecBase2 &film_offset) { 00787 cdata->_film_offset = film_offset; 00788 do_adjust_comp_flags(cdata, CF_mat, 0); 00789 do_throw_change_event(cdata); 00790 } 00791 00792 //////////////////////////////////////////////////////////////////// 00793 // Function: Lens::do_get_film_offset 00794 // Access: Protected 00795 // Description: 00796 //////////////////////////////////////////////////////////////////// 00797 INLINE const LVector2 &Lens:: 00798 do_get_film_offset(const CData *cdata) const { 00799 return cdata->_film_offset; 00800 } 00801 00802 //////////////////////////////////////////////////////////////////// 00803 // Function: Lens::do_set_near 00804 // Access: Protected 00805 // Description: 00806 //////////////////////////////////////////////////////////////////// 00807 INLINE void Lens:: 00808 do_set_near(CData *cdata, PN_stdfloat near_distance) { 00809 cdata->_near_distance = near_distance; 00810 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0); 00811 do_throw_change_event(cdata); 00812 } 00813 00814 //////////////////////////////////////////////////////////////////// 00815 // Function: Lens::do_get_near 00816 // Access: Protected 00817 // Description: 00818 //////////////////////////////////////////////////////////////////// 00819 INLINE PN_stdfloat Lens:: 00820 do_get_near(const CData *cdata) const { 00821 return cdata->_near_distance; 00822 } 00823 00824 //////////////////////////////////////////////////////////////////// 00825 // Function: Lens::do_set_far 00826 // Access: Protected 00827 // Description: 00828 //////////////////////////////////////////////////////////////////// 00829 INLINE void Lens:: 00830 do_set_far(CData *cdata, PN_stdfloat far_distance) { 00831 cdata->_far_distance = far_distance; 00832 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0); 00833 do_throw_change_event(cdata); 00834 } 00835 00836 //////////////////////////////////////////////////////////////////// 00837 // Function: Lens::do_get_far 00838 // Access: Protected 00839 // Description: 00840 //////////////////////////////////////////////////////////////////// 00841 INLINE PN_stdfloat Lens:: 00842 do_get_far(const CData *cdata) const { 00843 return cdata->_far_distance; 00844 } 00845 00846 //////////////////////////////////////////////////////////////////// 00847 // Function: Lens::do_set_near_far 00848 // Access: Protected 00849 // Description: 00850 //////////////////////////////////////////////////////////////////// 00851 INLINE void Lens:: 00852 do_set_near_far(CData *cdata, PN_stdfloat near_distance, PN_stdfloat far_distance) { 00853 cdata->_near_distance = near_distance; 00854 cdata->_far_distance = far_distance; 00855 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0); 00856 do_throw_change_event(cdata); 00857 } 00858 00859 INLINE ostream & 00860 operator << (ostream &out, const Lens &lens) { 00861 lens.output(out); 00862 return out; 00863 } 00864