24 extrude(
const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point)
const {
26 return do_extrude(cdata, LPoint3(point2d[0], point2d[1], 0.0f),
27 near_point, far_point);
42 extrude(
const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point)
const {
44 return do_extrude(cdata, point2d, near_point, far_point);
56 return do_extrude_depth(cdata, point2d, point3d);
74 return do_extrude_vec(cdata, LPoint3(point2d[0], point2d[1], 0.0f), vec);
94 return do_extrude_vec(cdata, point2d, vec);
108 project(
const LPoint3 &point3d, LPoint2 &point2d)
const {
111 bool okflag = do_project(cdata, point3d, result);
112 point2d.set(result[0], result[1]);
131 project(
const LPoint3 &point3d, LPoint3 &point2d)
const {
133 return do_project(cdata, point3d, point2d);
146 CDWriter cdata(_cycler,
true);
147 cdata->_change_event = event;
154 INLINE
const std::string &Lens::
155 get_change_event()
const {
156 CDReader cdata(_cycler);
157 return cdata->_change_event;
164 INLINE CoordinateSystem Lens::
165 get_coordinate_system()
const {
166 CDReader cdata(_cycler);
177 CDWriter cdata(_cycler,
true);
178 do_set_film_size(cdata, width);
220 CDWriter cdata(_cycler,
true);
221 do_set_film_size(cdata, film_size);
228 INLINE
const LVecBase2 &Lens::
229 get_film_size()
const {
230 CDReader cdata(_cycler);
231 return do_get_film_size(cdata);
253 CDWriter cdata(_cycler,
true);
254 do_set_film_offset(cdata, film_offset);
261 INLINE
const LVector2 &Lens::
262 get_film_offset()
const {
263 CDReader cdata(_cycler);
264 return do_get_film_offset(cdata);
276 CDWriter cdata(_cycler,
true);
277 do_set_focal_length(cdata, focal_length);
286 INLINE PN_stdfloat Lens::
287 get_focal_length()
const {
288 CDReader cdata(_cycler);
289 return do_get_focal_length(cdata);
299 CDWriter cdata(_cycler,
true);
300 do_set_fov(cdata, hfov);
312 set_fov(PN_stdfloat hfov, PN_stdfloat vfov) {
313 set_fov(LVecBase2(hfov, vfov));
325 set_fov(
const LVecBase2 &fov) {
326 CDWriter cdata(_cycler,
true);
327 do_set_fov(cdata, fov);
334 INLINE
const LVecBase2 &Lens::
336 CDReader cdata(_cycler);
337 return do_get_fov(cdata);
363 CDWriter cdata(_cycler,
true);
364 do_set_aspect_ratio(cdata, aspect_ratio);
371 INLINE PN_stdfloat Lens::
372 get_aspect_ratio()
const {
373 CDReader cdata(_cycler);
374 return do_get_aspect_ratio(cdata);
382 set_near(PN_stdfloat near_distance) {
383 CDWriter cdata(_cycler,
true);
384 do_set_near(cdata, near_distance);
390 INLINE PN_stdfloat Lens::
392 CDReader cdata(_cycler);
393 return do_get_near(cdata);
401 set_far(PN_stdfloat far_distance) {
402 CDWriter cdata(_cycler,
true);
403 do_set_far(cdata, far_distance);
409 INLINE PN_stdfloat Lens::
411 CDReader cdata(_cycler);
412 return do_get_far(cdata);
421 do_set_near_far(cdata, near_distance, far_distance);
431 set_view_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) {
442 set_view_vector(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_stdfloat j, PN_stdfloat k) {
459 CDWriter cdata(_cycler,
true);
460 do_set_interocular_distance(cdata, interocular_distance);
461 do_throw_change_event(cdata);
467 INLINE PN_stdfloat Lens::
468 get_interocular_distance()
const {
469 CDReader cdata(_cycler);
470 return cdata->_interocular_distance;
500 CDWriter cdata(_cycler,
true);
501 do_set_convergence_distance(cdata, convergence_distance);
502 do_throw_change_event(cdata);
508 INLINE PN_stdfloat Lens::
509 get_convergence_distance()
const {
510 CDReader cdata(_cycler);
511 return cdata->_convergence_distance;
526 CDWriter cdata(_cycler,
true);
527 do_set_view_mat(cdata, view_mat);
533 INLINE
const LMatrix4 &Lens::
534 get_view_mat()
const {
535 CDReader cdata(_cycler);
536 return do_get_view_mat(cdata);
542 INLINE
const LVecBase2 &Lens::
543 get_keystone()
const {
544 CDReader cdata(_cycler);
545 return cdata->_keystone;
551 INLINE
const LMatrix4 &
Lens:: 554 return cdata->_custom_film_mat;
562 INLINE
const LMatrix4 &
Lens:: 565 return do_get_projection_mat(cdata, channel);
572 INLINE
const LMatrix4 &
Lens:: 575 return do_get_projection_mat_inv(cdata, stereo_channel);
582 INLINE
const LMatrix4 &
Lens:: 585 return do_get_film_mat(cdata);
592 INLINE
const LMatrix4 &
Lens:: 595 return do_get_film_mat_inv(cdata);
602 INLINE
const LMatrix4 &
Lens:: 605 return do_get_lens_mat(cdata);
612 INLINE
const LMatrix4 &
Lens:: 615 return do_get_lens_mat_inv(cdata);
626 return cdata->_last_change;
634 do_adjust_user_flags(CData *cdata,
int clear_flags,
int set_flags) {
635 cdata->_user_flags = (cdata->_user_flags & ~clear_flags) | (
short)set_flags;
643 do_adjust_comp_flags(CData *cdata,
int clear_flags,
int set_flags) {
644 cdata->_comp_flags = (cdata->_comp_flags & ~clear_flags) | (
short)set_flags;
651 do_set_film_offset(CData *cdata,
const LVecBase2 &film_offset) {
652 cdata->_film_offset = film_offset;
653 do_adjust_comp_flags(cdata, CF_mat, 0);
654 do_throw_change_event(cdata);
660 INLINE
const LVector2 &Lens::
661 do_get_film_offset(
const CData *cdata)
const {
662 return cdata->_film_offset;
669 do_set_near(CData *cdata, PN_stdfloat near_distance) {
670 if (near_distance != cdata->_near_distance) {
671 cdata->_near_distance = near_distance;
672 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
673 do_throw_change_event(cdata);
680 INLINE PN_stdfloat Lens::
681 do_get_near(
const CData *cdata)
const {
682 return cdata->_near_distance;
689 do_set_far(CData *cdata, PN_stdfloat far_distance) {
690 if (far_distance != cdata->_far_distance) {
691 cdata->_far_distance = far_distance;
692 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
693 do_throw_change_event(cdata);
700 INLINE PN_stdfloat Lens::
701 do_get_far(
const CData *cdata)
const {
702 return cdata->_far_distance;
709 do_set_near_far(CData *cdata, PN_stdfloat near_distance, PN_stdfloat far_distance) {
710 if (near_distance != cdata->_near_distance || far_distance != cdata->_far_distance) {
711 cdata->_near_distance = near_distance;
712 cdata->_far_distance = far_distance;
713 do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
714 do_throw_change_event(cdata);
718 INLINE std::ostream &
719 operator << (std::ostream &out,
const Lens &lens) {
const LMatrix4 & get_custom_film_mat() const
Returns the custom_film_mat specified for the lens.
set_focal_length
Sets the focal length of the lens.
A base class for any number of different kinds of lenses, linear and otherwise.
PN_stdfloat get_vfov() const
Returns the vertical component of fov only.
set_view_hpr
Sets the direction in which the lens is facing.
const LMatrix4 & get_lens_mat_inv() const
Returns the matrix that transforms from a point in space to a point in front of the lens.
PN_stdfloat get_hfov() const
Returns the horizontal component of fov only.
set_interocular_distance
Sets the distance between the left and right eyes of a stereo camera.
set_aspect_ratio
Sets the aspect ratio of the lens.
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
void set_near_far(PN_stdfloat near_distance, PN_stdfloat far_distance)
Simultaneously changes the near and far planes.
get_fov
Returns the horizontal and vertical film size of the virtual film.
bool project(const LPoint3 &point3d, LPoint3 &point2d) const
Given a 3-d point in space, determine the 2-d point this maps to, in the range (-1,...
set_near
Defines the position of the near plane (or cylinder, sphere, whatever).
const LMatrix4 & get_projection_mat_inv(StereoChannel channel=SC_mono) const
Returns the matrix that transforms from a 2-d point on the film to a 3-d vector in space,...
set_film_size
Sets the horizontal size of the film without changing its shape.
const LMatrix4 & get_film_mat() const
Returns the matrix that transforms from a point behind the lens to a point on the film.
set_film_offset
Sets the horizontal and vertical offset amounts of this Lens.
set_convergence_distance
Sets the distance between between the camera plane and the point in the distance that the left and ri...
UpdateSeq get_last_change() const
Returns the UpdateSeq that is incremented whenever the lens properties are changed.
bool extrude_vec(const LPoint2 &point2d, LVector3 &vec3d) const
Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
const LMatrix4 & get_projection_mat(StereoChannel channel=SC_mono) const
Returns the complete transformation matrix from a 3-d point in space to a point on the film,...
bool extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const
Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (...
set_far
Defines the position of the far plane (or cylinder, sphere, whatever).
bool extrude_depth(const LPoint3 &point2d, LPoint3 &point3d) const
Uses the depth component of the 3-d result from project() to compute the original point in 3-d space ...
This is a sequence number that increments monotonically.
set_view_mat
Sets an arbitrary transformation on the lens.
const LMatrix4 & get_lens_mat() const
Returns the matrix that transforms from a point in front of the lens to a point in space.
void set_view_vector(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_stdfloat j, PN_stdfloat k)
Specifies the direction in which the lens is facing by giving an axis to look along,...
const LMatrix4 & get_film_mat_inv() const
Returns the matrix that transforms from a point on the film to a point behind the lens.
set_change_event
Sets the name of the event that will be generated whenever any properties of the Lens have changed.
set_fov
Sets the horizontal field of view of the lens without changing the aspect ratio.