33 static const PN_stdfloat fisheye_k = 60.0f;
40 PT(
Lens) FisheyeLens::
57 do_extrude(
const Lens::CData *lens_cdata,
58 const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point)
const {
61 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
65 LVector2 v2(f[0], f[1]);
69 PN_stdfloat r = v2.length();
72 v.set(0.0f, 1.0f, 0.0f);
78 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
79 PN_stdfloat angle = r * fisheye_k / focal_length;
80 PN_stdfloat sinAngle, cosAngle;
81 csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
83 LVector3 p(0.0, cosAngle, sinAngle);
86 v.set(p[0]*v2[1] + p[2]*v2[0],
88 p[2]*v2[1] - p[0]*v2[0]);
93 const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
94 const LMatrix4 &proj_inv_mat = do_get_projection_mat_inv(lens_cdata);
96 near_point = (v * do_get_near(lens_cdata)) * proj_inv_mat * lens_mat;
97 far_point = (v * do_get_far(lens_cdata)) * proj_inv_mat * lens_mat;
116 do_extrude_vec(
const Lens::CData *lens_cdata,
const LPoint3 &point2d, LVector3 &vec)
const {
117 LPoint3 near_point, far_point;
118 if (!do_extrude(lens_cdata, point2d, near_point, far_point)) {
122 vec = far_point - near_point;
140 do_project(
const Lens::CData *lens_cdata,
const LPoint3 &point3d, LPoint3 &point2d)
const {
142 LVector3 v2 = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata);
152 PN_stdfloat dist = v2.length();
158 LVector2 y(v2[0], v2[2]);
161 if (y == LVector2(0.0f, 0.0f)) {
163 point2d.set(0.0f, 0.0f,
164 (do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata)));
165 return v2[1] >= 0.0f;
169 LVector2 x(v2[1], v2[0]*y[0]+v2[2]*y[1]);
173 PN_stdfloat r = 90.0f - rad_2_deg(catan2(x[0], x[1]));
175 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
176 PN_stdfloat factor = r * focal_length / fisheye_k;
179 PN_stdfloat z = (dist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));
189 point2d = point2d * do_get_film_mat(lens_cdata);
192 point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
193 point2d[1] >= -1.0f && point2d[1] <= 1.0f;
202 PN_stdfloat FisheyeLens::
203 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
204 return focal_length * fov / fisheye_k;
213 PN_stdfloat FisheyeLens::
214 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
215 return film_size * fisheye_k / fov;
224 PN_stdfloat FisheyeLens::
225 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
226 return film_size * fisheye_k / focal_length;
A base class for any number of different kinds of lenses, linear and otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.