15 #include "perspectiveLens.h" 16 #include "bamReader.h" 26 PT(
Lens) PerspectiveLens::
63 bool PerspectiveLens::
64 do_extrude_depth(
const CData *cdata,
66 return do_extrude_depth_with_mat(cdata, point2d, point3d);
75 void PerspectiveLens::
76 do_compute_projection_mat(Lens::CData *lens_cdata) {
77 CoordinateSystem cs = lens_cdata->_cs;
78 if (cs == CS_default) {
79 cs = get_default_coordinate_system();
82 PN_stdfloat fl = do_get_focal_length(lens_cdata);
83 PN_stdfloat fFar = do_get_far(lens_cdata);
84 PN_stdfloat fNear = do_get_near(lens_cdata);
91 PN_stdfloat far_minus_near = fFar-fNear;
93 b = -2 * fFar * fNear;
101 canonical.set( fl, 0.0f, 0.0f, 0.0f,
103 0.0f, fl, 0.0f, 0.0f,
104 0.0f, 0.0f, b, 0.0f);
108 canonical.set( fl, 0.0f, 0.0f, 0.0f,
109 0.0f, fl, 0.0f, 0.0f,
110 0.0f, 0.0f, -a, -1.0f,
111 0.0f, 0.0f, b, 0.0f);
115 canonical.set( fl, 0.0f, 0.0f, 0.0f,
116 0.0f, 0.0f, -a, -1.0f,
117 0.0f, fl, 0.0f, 0.0f,
118 0.0f, 0.0f, b, 0.0f);
122 canonical.set( fl, 0.0f, 0.0f, 0.0f,
123 0.0f, fl, 0.0f, 0.0f,
125 0.0f, 0.0f, b, 0.0f);
130 <<
"Invalid coordinate system " << (int)cs <<
" in PerspectiveLens!\n";
134 lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * canonical * do_get_film_mat(lens_cdata);
136 if ((lens_cdata->_user_flags & UF_interocular_distance) == 0) {
137 lens_cdata->_projection_mat_left = lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
144 lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) *
LMatrix4::translate_mat(-iod) * canonical * do_get_film_mat(lens_cdata);
145 lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) *
LMatrix4::translate_mat(iod) * canonical * do_get_film_mat(lens_cdata);
147 if ((lens_cdata->_user_flags & UF_convergence_distance) != 0 &&
148 !cinf(lens_cdata->_convergence_distance)) {
149 nassertv(lens_cdata->_convergence_distance != 0.0f);
151 if (stereo_lens_old_convergence) {
152 cd = (0.25f / lens_cdata->_convergence_distance) *
LVector3::left(lens_cdata->_cs);
154 const LVecBase2 &fov = do_get_fov(lens_cdata);
155 cd = (2.0f / fov_to_film(fov[0], lens_cdata->_convergence_distance,
true)) * iod;
162 do_adjust_comp_flags(lens_cdata,
163 CF_projection_mat_inv | CF_projection_mat_left_inv | CF_projection_mat_right_inv,
176 PN_stdfloat PerspectiveLens::
177 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
178 return (ctan(deg_2_rad(fov * 0.5f)) * focal_length) * 2.0f;
190 PN_stdfloat PerspectiveLens::
191 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
192 return film_size * 0.5f / ctan(deg_2_rad(fov * 0.5f));
204 PN_stdfloat PerspectiveLens::
205 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
206 return rad_2_deg(catan(film_size * 0.5f / focal_length)) * 2.0f;
234 parse_params(params, scan, manager);
235 lens->fillin(scan, manager);
static const LMatrix4f & ident_mat()
Returns an identity matrix.
A base class for any number of different kinds of lenses, linear and otherwise.
static LMatrix4f translate_mat(const LVecBase3f &trans)
Returns a matrix that applies the indicated translation.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Base class for objects that can be written to and read from Bam files.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
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.
This is a 4-by-4 transform matrix.
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...
static LVector3f left(CoordinateSystem cs=CS_default)
Returns the left vector for the given coordinate system.
This is the base class for all two-component vectors and points.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
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.