52 bool PerspectiveLens::
53 do_extrude_depth(
const CData *cdata,
54 const LPoint3 &point2d, LPoint3 &point3d)
const {
55 return do_extrude_depth_with_mat(cdata, point2d, point3d);
62 void PerspectiveLens::
63 do_compute_projection_mat(Lens::CData *lens_cdata) {
64 CoordinateSystem cs = lens_cdata->_cs;
65 if (cs == CS_default) {
66 cs = get_default_coordinate_system();
69 PN_stdfloat fl = do_get_focal_length(lens_cdata);
70 PN_stdfloat fFar = do_get_far(lens_cdata);
71 PN_stdfloat fNear = do_get_near(lens_cdata);
78 }
else if (cinf(fNear)) {
83 PN_stdfloat far_minus_near = fFar-fNear;
85 b = -2 * fFar * fNear;
93 canonical.set( fl, 0.0f, 0.0f, 0.0f,
100 canonical.set( fl, 0.0f, 0.0f, 0.0f,
101 0.0f, fl, 0.0f, 0.0f,
102 0.0f, 0.0f, -a, -1.0f,
103 0.0f, 0.0f, b, 0.0f);
107 canonical.set( fl, 0.0f, 0.0f, 0.0f,
108 0.0f, 0.0f, -a, -1.0f,
109 0.0f, fl, 0.0f, 0.0f,
110 0.0f, 0.0f, b, 0.0f);
114 canonical.set( fl, 0.0f, 0.0f, 0.0f,
115 0.0f, fl, 0.0f, 0.0f,
117 0.0f, 0.0f, b, 0.0f);
122 <<
"Invalid coordinate system " << (int)cs <<
" in PerspectiveLens!\n";
123 canonical = LMatrix4::ident_mat();
126 lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * canonical * do_get_film_mat(lens_cdata);
128 if ((lens_cdata->_user_flags & UF_interocular_distance) == 0) {
129 lens_cdata->_projection_mat_left = lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
135 LVector3 iod = lens_cdata->_interocular_distance * 0.5f * LVector3::left(lens_cdata->_cs);
136 lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(-iod) * canonical * do_get_film_mat(lens_cdata);
137 lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(iod) * canonical * do_get_film_mat(lens_cdata);
139 if ((lens_cdata->_user_flags & UF_convergence_distance) != 0 &&
140 !cinf(lens_cdata->_convergence_distance)) {
141 nassertv(lens_cdata->_convergence_distance != 0.0f);
143 if (stereo_lens_old_convergence) {
144 cd = (0.25f / lens_cdata->_convergence_distance) * LVector3::left(lens_cdata->_cs);
146 const LVecBase2 &fov = do_get_fov(lens_cdata);
147 cd = (2.0f / fov_to_film(fov[0], lens_cdata->_convergence_distance,
true)) * iod;
149 lens_cdata->_projection_mat_left *= LMatrix4::translate_mat(cd);
150 lens_cdata->_projection_mat_right *= LMatrix4::translate_mat(-cd);
154 do_adjust_comp_flags(lens_cdata,
155 CF_projection_mat_inv | CF_projection_mat_left_inv | CF_projection_mat_right_inv,
165 PN_stdfloat PerspectiveLens::
166 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
167 return (ctan(deg_2_rad(fov * 0.5f)) * focal_length) * 2.0f;
176 PN_stdfloat PerspectiveLens::
177 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
178 return film_size * 0.5f / ctan(deg_2_rad(fov * 0.5f));
187 PN_stdfloat PerspectiveLens::
188 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
189 return rad_2_deg(catan(film_size * 0.5f / focal_length)) * 2.0f;
212 lens->fillin(scan, manager);
A base class for any number of different kinds of lenses, linear and otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
PT(Lens) PerspectiveLens
Allocates a new Lens just like this one.
Base class for objects that can be written to and read from Bam files.
virtual bool is_linear() const
Returns true if the lens represents a linear projection (e.g.
virtual bool is_perspective() const
Returns true if the lens represents a perspective projection (i.e.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A perspective-type lens: a normal camera.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Lens.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.