15 #include "cylindricalLens.h" 16 #include "deg_2_rad.h" 22 static const PN_stdfloat cylindrical_k = 60.0f;
31 PT(
Lens) CylindricalLens::
53 bool CylindricalLens::
54 do_extrude(
const Lens::CData *lens_cdata,
58 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
60 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
61 PN_stdfloat angle = f[0] * cylindrical_k / focal_length;
62 PN_stdfloat sinAngle, cosAngle;
63 csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
67 LPoint3 v(sinAngle, cosAngle, f[1] / focal_length);
71 const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
72 const LMatrix4 &proj_inv_mat = do_get_projection_mat_inv(lens_cdata);
74 near_point = (v * do_get_near(lens_cdata)) * proj_inv_mat * lens_mat;
75 far_point = (v * do_get_far(lens_cdata)) * proj_inv_mat * lens_mat;
99 bool CylindricalLens::
100 do_extrude_vec(
const Lens::CData *lens_cdata,
const LPoint3 &point2d,
LVector3 &vec)
const {
103 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
105 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
106 PN_stdfloat angle = f[0] * cylindrical_k / focal_length;
107 PN_stdfloat sinAngle, cosAngle;
108 csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
110 vec =
LVector3(sinAngle, cosAngle, 0.0f) * do_get_projection_mat_inv(lens_cdata) * do_get_lens_mat(lens_cdata);
132 bool CylindricalLens::
133 do_project(
const Lens::CData *lens_cdata,
const LPoint3 &point3d,
LPoint3 &point2d)
const {
135 LPoint3 p = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata);
144 PN_stdfloat pdist = xy.length();
146 point2d.set(0.0f, 0.0f, 0.0f);
150 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
153 PN_stdfloat z = (pdist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));
158 rad_2_deg(catan2(xy[0], xy[1])) * focal_length / cylindrical_k,
161 p[2] * focal_length / pdist,
168 point2d = point2d * do_get_film_mat(lens_cdata);
171 point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
172 point2d[1] >= -1.0f && point2d[1] <= 1.0f;
184 PN_stdfloat CylindricalLens::
185 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool horiz)
const {
187 return focal_length * fov / cylindrical_k;
189 return (ctan(deg_2_rad(fov * 0.5f)) * focal_length) * 2.0f;
202 PN_stdfloat CylindricalLens::
203 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool horiz)
const {
205 return film_size * cylindrical_k / fov;
207 return film_size * 0.5f / ctan(deg_2_rad(fov * 0.5f));
220 PN_stdfloat CylindricalLens::
221 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool horiz)
const {
223 return film_size * cylindrical_k / focal_length;
225 return rad_2_deg(catan(film_size * 0.5f / focal_length)) * 2.0f;
A base class for any number of different kinds of lenses, linear and otherwise.
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 ...
This is a 4-by-4 transform matrix.
This is a two-component vector offset.
TypeHandle is the identifier used to differentiate C++ class types.