20 static const PN_stdfloat pspherical_k = 60.0f;
26 PT(
Lens) PSphereLens::
43 do_extrude(
const Lens::CData *lens_cdata,
44 const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point)
const {
47 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
49 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
53 LPoint3 v = LPoint3(0.0f, 1.0f, 0.0f) *
54 LMatrix3::rotate_mat(f[1] * pspherical_k / focal_length, LVector3(1.0f, 0.0f, 0.0f)) *
55 LMatrix3::rotate_mat(f[0] * pspherical_k / focal_length, LVector3(0.0f, 0.0f, -1.0f));
59 const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
60 const LMatrix4 &proj_inv_mat = do_get_projection_mat_inv(lens_cdata);
62 near_point = (v * do_get_near(lens_cdata)) * proj_inv_mat * lens_mat;
63 far_point = (v * do_get_far(lens_cdata)) * proj_inv_mat * lens_mat;
80 do_project(
const Lens::CData *lens_cdata,
const LPoint3 &point3d, LPoint3 &point2d)
const {
82 LVector3 v3 = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata);
83 PN_stdfloat dist = v3.length();
85 point2d.set(0.0f, 0.0f, 0.0f);
91 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
96 LVector2 xy(v3[0], v3[1]);
100 LVector2d yz(v3[0]*xy[0] + v3[1]*xy[1], v3[2]);
103 PN_stdfloat z = (dist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));
108 rad_2_deg(catan2(xy[0], xy[1])) * focal_length / pspherical_k,
110 rad_2_deg(catan2(yz[1], yz[0])) * focal_length / pspherical_k,
116 point2d = point2d * do_get_film_mat(lens_cdata);
119 point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
120 point2d[1] >= -1.0f && point2d[1] <= 1.0f;
129 PN_stdfloat PSphereLens::
130 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
131 return focal_length * fov / pspherical_k;
140 PN_stdfloat PSphereLens::
141 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
142 return film_size * pspherical_k / fov;
151 PN_stdfloat PSphereLens::
152 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
153 return film_size * pspherical_k / focal_length;
A PSphereLens is a special nonlinear lens that doesn't correspond to any real physical lenses.
A base class for any number of different kinds of lenses, linear and otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.