15 #include "pSphereLens.h"
16 #include "deg_2_rad.h"
22 static const PN_stdfloat pspherical_k = 60.0f;
53 do_extrude(
const Lens::CData *lens_cdata,
57 LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
59 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
69 const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
70 const LMatrix4 &proj_inv_mat = do_get_projection_mat_inv(lens_cdata);
72 near_point = (v * do_get_near(lens_cdata)) * proj_inv_mat * lens_mat;
73 far_point = (v * do_get_far(lens_cdata)) * proj_inv_mat * lens_mat;
95 do_project(
const Lens::CData *lens_cdata,
const LPoint3 &point3d,
LPoint3 &point2d)
const {
97 LVector3 v3 = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata);
98 PN_stdfloat dist = v3.
length();
100 point2d.set(0.0f, 0.0f, 0.0f);
106 PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
116 LVector2d yz(v3[0]*xy[0] + v3[1]*xy[1], v3[2]);
119 PN_stdfloat z = (dist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));
124 rad_2_deg(catan2(xy[0], xy[1])) * focal_length / pspherical_k,
126 rad_2_deg(catan2(yz[1], yz[0])) * focal_length / pspherical_k,
133 point2d = point2d * do_get_film_mat(lens_cdata);
136 point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
137 point2d[1] >= -1.0f && point2d[1] <= 1.0f;
149 PN_stdfloat PSphereLens::
150 fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length,
bool)
const {
151 return focal_length * fov / pspherical_k;
163 PN_stdfloat PSphereLens::
164 fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size,
bool)
const {
165 return film_size * pspherical_k / fov;
177 PN_stdfloat PSphereLens::
178 film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length,
bool)
const {
179 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.
This is a two-component vector offset.
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 ...
float length() const
Returns the length of the vector, by the Pythagorean theorem.
This is a 4-by-4 transform matrix.
This is a two-component vector offset.
static LMatrix3f rotate_mat(float angle)
Returns a matrix that rotates by the given angle in degrees counterclockwise.
TypeHandle is the identifier used to differentiate C++ class types.