15 #include "fisheyeLens.h" 16 #include "deg_2_rad.h" 35 static const PN_stdfloat fisheye_k = 60.0f;
44 PT(
Lens) FisheyeLens::
67 do_extrude(
const Lens::CData *lens_cdata,
71 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
79 PN_stdfloat r = v2.
length();
82 v.set(0.0f, 1.0f, 0.0f);
88 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
89 PN_stdfloat angle = r * fisheye_k / focal_length;
90 PN_stdfloat sinAngle, cosAngle;
91 csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
96 v.set(p[0]*v2[1] + p[2]*v2[0],
98 p[2]*v2[1] - p[0]*v2[0]);
103 const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
104 const LMatrix4 &proj_inv_mat = do_get_projection_mat_inv(lens_cdata);
106 near_point = (v * do_get_near(lens_cdata)) * proj_inv_mat * lens_mat;
107 far_point = (v * do_get_far(lens_cdata)) * proj_inv_mat * lens_mat;
132 do_extrude_vec(
const Lens::CData *lens_cdata,
const LPoint3 &point2d,
LVector3 &vec)
const {
134 if (!do_extrude(lens_cdata, point2d, near_point, far_point)) {
138 vec = far_point - near_point;
161 do_project(
const Lens::CData *lens_cdata,
const LPoint3 &point3d,
LPoint3 &point2d)
const {
163 LVector3 v2 = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata);
173 PN_stdfloat dist = v2.
length();
185 point2d.set(0.0f, 0.0f,
186 (do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata)));
187 return v2[1] >= 0.0f;
192 LVector2 x(v2[1], v2[0]*y[0]+v2[2]*y[1]);
196 PN_stdfloat r = 90.0f - rad_2_deg(catan2(x[0], x[1]));
198 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
199 PN_stdfloat factor = r * focal_length / fisheye_k;
202 PN_stdfloat z = (dist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));
213 point2d = point2d * do_get_film_mat(lens_cdata);
216 point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
217 point2d[1] >= -1.0f && point2d[1] <= 1.0f;
229 PN_stdfloat FisheyeLens::
230 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
231 return focal_length * fov / fisheye_k;
243 PN_stdfloat FisheyeLens::
244 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
245 return film_size * fisheye_k / fov;
257 PN_stdfloat FisheyeLens::
258 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
259 return film_size * fisheye_k / focal_length;
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.
float length() const
Returns the length of the vector, by the Pythagorean theorem.
This is a two-component vector offset.
TypeHandle is the identifier used to differentiate C++ class types.