mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
pipeline lens changes
This commit is contained in:
parent
83b87652f8
commit
be2657311d
@ -34,7 +34,7 @@ make_copy() const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CylindricalLens::extrude_impl
|
||||
// Function: CylindricalLens::do_extrude
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -51,12 +51,13 @@ make_copy() const {
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CylindricalLens::
|
||||
extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
do_extrude(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
// Undo the shifting from film offsets, etc. This puts the point
|
||||
// into the range [-film_size/2, film_size/2] in x and y.
|
||||
LPoint3 f = point2d * get_film_mat_inv();
|
||||
LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat angle = f[0] * cylindrical_k / focal_length;
|
||||
PN_stdfloat sinAngle, cosAngle;
|
||||
csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
|
||||
@ -67,15 +68,15 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
|
||||
// And we'll need to account for the lens's rotations, etc. at the
|
||||
// end of the day.
|
||||
const LMatrix4 &lens_mat = get_lens_mat();
|
||||
const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
|
||||
|
||||
near_point = (v * get_near()) * lens_mat;
|
||||
far_point = (v * get_far()) * lens_mat;
|
||||
near_point = (v * do_get_near(lens_cdata)) * lens_mat;
|
||||
far_point = (v * do_get_far(lens_cdata)) * lens_mat;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CylindricalLens::extrude_vec_impl
|
||||
// Function: CylindricalLens::do_extrude_vec
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -95,23 +96,23 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CylindricalLens::
|
||||
extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d, LVector3 &vec) const {
|
||||
// Undo the shifting from film offsets, etc. This puts the point
|
||||
// into the range [-film_size/2, film_size/2] in x and y.
|
||||
LPoint3 f = point2d * get_film_mat_inv();
|
||||
LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat angle = f[0] * cylindrical_k / focal_length;
|
||||
PN_stdfloat sinAngle, cosAngle;
|
||||
csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
|
||||
|
||||
vec = LVector3(sinAngle, cosAngle, 0.0f) * get_lens_mat();
|
||||
vec = LVector3(sinAngle, cosAngle, 0.0f) * do_get_lens_mat(lens_cdata);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CylindricalLens::project_impl
|
||||
// Function: CylindricalLens::do_project
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 3-d point in space, determine the 2-d point
|
||||
// this maps to, in the range (-1,1) in both dimensions,
|
||||
@ -128,9 +129,9 @@ extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
// is filled in), or false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CylindricalLens::
|
||||
project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// First, account for any rotations, etc. on the lens.
|
||||
LPoint3 p = point3d * get_lens_mat_inv();
|
||||
LPoint3 p = point3d * do_get_lens_mat_inv(lens_cdata);
|
||||
|
||||
// To compute the x position on the frame, we only need to consider
|
||||
// the angle of the vector about the Z axis. Project the vector
|
||||
@ -145,7 +146,7 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
|
||||
point2d.set
|
||||
(
|
||||
@ -155,12 +156,12 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// distance.
|
||||
p[2] * focal_length / pdist,
|
||||
// Z is the perspective distance scaled into the range (1, -1).
|
||||
(get_near() - pdist) / (get_far() - get_near())
|
||||
(do_get_near(lens_cdata) - pdist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata))
|
||||
);
|
||||
|
||||
// Now we have to transform the point according to the film
|
||||
// adjustments.
|
||||
point2d = point2d * get_film_mat();
|
||||
point2d = point2d * do_get_film_mat(lens_cdata);
|
||||
|
||||
return
|
||||
point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
|
||||
|
@ -49,10 +49,12 @@ public:
|
||||
virtual PT(Lens) make_copy() const;
|
||||
|
||||
protected:
|
||||
virtual bool extrude_impl(const LPoint3 &point2d,
|
||||
virtual bool do_extrude(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LPoint3 &near_point, LPoint3 &far_point) const;
|
||||
virtual bool extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const;
|
||||
virtual bool project_impl(const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
virtual bool do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LVector3 &vec) const;
|
||||
virtual bool do_project(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
|
@ -47,7 +47,7 @@ make_copy() const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FisheyeLens::extrude_impl
|
||||
// Function: FisheyeLens::do_extrude
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -64,10 +64,11 @@ make_copy() const {
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FisheyeLens::
|
||||
extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
do_extrude(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
// Undo the shifting from film offsets, etc. This puts the point
|
||||
// into the range [-film_size/2, film_size/2] in x and y.
|
||||
LPoint3 f = point2d * get_film_mat_inv();
|
||||
LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
|
||||
|
||||
// First, get the vector from the center of the film to the point,
|
||||
// and normalize it.
|
||||
@ -84,7 +85,7 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
v2 /= r;
|
||||
|
||||
// Now get the point r units around the circle in the YZ plane.
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat angle = r * fisheye_k / focal_length;
|
||||
PN_stdfloat sinAngle, cosAngle;
|
||||
csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
|
||||
@ -99,15 +100,15 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
|
||||
// And we'll need to account for the lens's rotations, etc. at the
|
||||
// end of the day.
|
||||
const LMatrix4 &lens_mat = get_lens_mat();
|
||||
const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
|
||||
|
||||
near_point = (v * get_near()) * lens_mat;
|
||||
far_point = (v * get_far()) * lens_mat;
|
||||
near_point = (v * do_get_near(lens_cdata)) * lens_mat;
|
||||
far_point = (v * do_get_far(lens_cdata)) * lens_mat;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FisheyeLens::extrude_vec_impl
|
||||
// Function: FisheyeLens::do_extrude_vec
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -127,9 +128,9 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FisheyeLens::
|
||||
extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d, LVector3 &vec) const {
|
||||
LPoint3 near_point, far_point;
|
||||
if (!extrude_impl(point2d, near_point, far_point)) {
|
||||
if (!do_extrude(lens_cdata, point2d, near_point, far_point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -139,7 +140,7 @@ extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FisheyeLens::project_impl
|
||||
// Function: FisheyeLens::do_project
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 3-d point in space, determine the 2-d point
|
||||
// this maps to, in the range (-1,1) in both dimensions,
|
||||
@ -156,9 +157,9 @@ extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
// is filled in), or false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FisheyeLens::
|
||||
project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// First, account for any rotations, etc. on the lens.
|
||||
LVector3 v2 = point3d * get_lens_mat_inv();
|
||||
LVector3 v2 = point3d * do_get_lens_mat_inv(lens_cdata);
|
||||
|
||||
// A fisheye lens projection has the property that the distance from
|
||||
// the center point to any other point on the projection is
|
||||
@ -181,7 +182,7 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// Special case. This point is either directly ahead or directly
|
||||
// behind.
|
||||
point2d.set(0.0f, 0.0f,
|
||||
(get_near() - dist) / (get_far() - get_near()));
|
||||
(do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata)));
|
||||
return v2[1] >= 0.0f;
|
||||
}
|
||||
|
||||
@ -193,19 +194,19 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// along the great circle to the point.
|
||||
PN_stdfloat r = 90.0f - rad_2_deg(catan2(x[0], x[1]));
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat factor = r * focal_length / fisheye_k;
|
||||
|
||||
point2d.set
|
||||
(y[0] * factor,
|
||||
y[1] * factor,
|
||||
// Z is the distance scaled into the range (1, -1).
|
||||
(get_near() - dist) / (get_far() - get_near())
|
||||
(do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata))
|
||||
);
|
||||
|
||||
// Now we have to transform the point according to the film
|
||||
// adjustments.
|
||||
point2d = point2d * get_film_mat();
|
||||
point2d = point2d * do_get_film_mat(lens_cdata);
|
||||
|
||||
return
|
||||
point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
|
||||
|
@ -39,10 +39,12 @@ public:
|
||||
virtual PT(Lens) make_copy() const;
|
||||
|
||||
protected:
|
||||
virtual bool extrude_impl(const LPoint3 &point2d,
|
||||
virtual bool do_extrude(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LPoint3 &near_point, LPoint3 &far_point) const;
|
||||
virtual bool extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const;
|
||||
virtual bool project_impl(const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
virtual bool do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LVector3 &vec) const;
|
||||
virtual bool do_project(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
|
@ -34,7 +34,7 @@ make_copy() const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: OSphereLens::extrude_impl
|
||||
// Function: OSphereLens::do_extrude
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -51,12 +51,13 @@ make_copy() const {
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool OSphereLens::
|
||||
extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
do_extrude(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
// Undo the shifting from film offsets, etc. This puts the point
|
||||
// into the range [-film_size/2, film_size/2] in x and y.
|
||||
LPoint3 f = point2d * get_film_mat_inv();
|
||||
LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat angle = f[0] * cylindrical_k / focal_length;
|
||||
PN_stdfloat sinAngle, cosAngle;
|
||||
csincos(deg_2_rad(angle), &sinAngle, &cosAngle);
|
||||
@ -65,14 +66,14 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
// this point.
|
||||
LPoint3 v(sinAngle, cosAngle, 0.0f);
|
||||
|
||||
near_point = (v * get_near());
|
||||
far_point = (v * get_far());
|
||||
near_point = (v * do_get_near(lens_cdata));
|
||||
far_point = (v * do_get_far(lens_cdata));
|
||||
near_point[2] = f[1] / focal_length;
|
||||
far_point[2] = f[1] / focal_length;
|
||||
|
||||
// And we'll need to account for the lens's rotations, etc. at the
|
||||
// end of the day.
|
||||
const LMatrix4 &lens_mat = get_lens_mat();
|
||||
const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
|
||||
|
||||
near_point = near_point * lens_mat;
|
||||
far_point = far_point * lens_mat;
|
||||
@ -80,7 +81,7 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: OSphereLens::project_impl
|
||||
// Function: OSphereLens::do_project
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 3-d point in space, determine the 2-d point
|
||||
// this maps to, in the range (-1,1) in both dimensions,
|
||||
@ -97,9 +98,9 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
// is filled in), or false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool OSphereLens::
|
||||
project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// First, account for any rotations, etc. on the lens.
|
||||
LPoint3 p = point3d * get_lens_mat_inv();
|
||||
LPoint3 p = point3d * do_get_lens_mat_inv(lens_cdata);
|
||||
PN_stdfloat dist = p.length();
|
||||
if (dist == 0.0f) {
|
||||
point2d.set(0.0f, 0.0f, 0.0f);
|
||||
@ -108,7 +109,7 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
|
||||
LPoint3 v3 = p / dist;
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
|
||||
// To compute the x position on the frame, we only need to consider
|
||||
// the angle of the vector about the Z axis. Project the vector
|
||||
@ -123,12 +124,12 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// distance.
|
||||
p[2] * focal_length,
|
||||
// Z is the distance scaled into the range (1, -1).
|
||||
(get_near() - dist) / (get_far() - get_near())
|
||||
(do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata))
|
||||
);
|
||||
|
||||
// Now we have to transform the point according to the film
|
||||
// adjustments.
|
||||
point2d = point2d * get_film_mat();
|
||||
point2d = point2d * do_get_film_mat(lens_cdata);
|
||||
|
||||
return
|
||||
point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
|
||||
|
@ -43,9 +43,10 @@ public:
|
||||
virtual PT(Lens) make_copy() const;
|
||||
|
||||
protected:
|
||||
virtual bool extrude_impl(const LPoint3 &point2d,
|
||||
virtual bool do_extrude(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LPoint3 &near_point, LPoint3 &far_point) const;
|
||||
virtual bool project_impl(const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
virtual bool do_project(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
|
@ -33,7 +33,7 @@ make_copy() const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PSphereLens::extrude_impl
|
||||
// Function: PSphereLens::do_extrude
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 2-d point in the range (-1,1) in both
|
||||
// dimensions, where (0,0) is the center of the
|
||||
@ -50,12 +50,13 @@ make_copy() const {
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PSphereLens::
|
||||
extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
do_extrude(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
// Undo the shifting from film offsets, etc. This puts the point
|
||||
// into the range [-film_size/2, film_size/2] in x and y.
|
||||
LPoint3 f = point2d * get_film_mat_inv();
|
||||
LPoint3 f = point2d * do_get_film_mat_inv(lens_cdata);
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
|
||||
// Rotate the forward vector through the rotation angles
|
||||
// corresponding to this point.
|
||||
@ -65,15 +66,15 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
|
||||
// And we'll need to account for the lens's rotations, etc. at the
|
||||
// end of the day.
|
||||
const LMatrix4 &lens_mat = get_lens_mat();
|
||||
const LMatrix4 &lens_mat = do_get_lens_mat(lens_cdata);
|
||||
|
||||
near_point = (v * get_near()) * lens_mat;
|
||||
far_point = (v * get_far()) * lens_mat;
|
||||
near_point = (v * do_get_near(lens_cdata)) * lens_mat;
|
||||
far_point = (v * do_get_far(lens_cdata)) * lens_mat;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PSphereLens::project_impl
|
||||
// Function: PSphereLens::do_project
|
||||
// Access: Protected, Virtual
|
||||
// Description: Given a 3-d point in space, determine the 2-d point
|
||||
// this maps to, in the range (-1,1) in both dimensions,
|
||||
@ -90,9 +91,9 @@ extrude_impl(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) co
|
||||
// is filled in), or false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PSphereLens::
|
||||
project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// First, account for any rotations, etc. on the lens.
|
||||
LVector3 v3 = point3d * get_lens_mat_inv();
|
||||
LVector3 v3 = point3d * do_get_lens_mat_inv(lens_cdata);
|
||||
PN_stdfloat dist = v3.length();
|
||||
if (dist == 0.0f) {
|
||||
point2d.set(0.0f, 0.0f, 0.0f);
|
||||
@ -101,7 +102,7 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
|
||||
v3 /= dist;
|
||||
|
||||
PN_stdfloat focal_length = get_focal_length();
|
||||
PN_stdfloat focal_length = do_get_focal_length(lens_cdata);
|
||||
|
||||
// To compute the x position on the frame, we only need to consider
|
||||
// the angle of the vector about the Z axis. Project the vector
|
||||
@ -120,12 +121,12 @@ project_impl(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
// The y position is the angle about the X axis.
|
||||
rad_2_deg(catan2(yz[1], yz[0])) * focal_length / pspherical_k,
|
||||
// Z is the distance scaled into the range (1, -1).
|
||||
(get_near() - dist) / (get_far() - get_near())
|
||||
(do_get_near(lens_cdata) - dist) / (do_get_far(lens_cdata) - do_get_near(lens_cdata))
|
||||
);
|
||||
|
||||
// Now we have to transform the point according to the film
|
||||
// adjustments.
|
||||
point2d = point2d * get_film_mat();
|
||||
point2d = point2d * do_get_film_mat(lens_cdata);
|
||||
|
||||
return
|
||||
point2d[0] >= -1.0f && point2d[0] <= 1.0f &&
|
||||
|
@ -47,9 +47,10 @@ public:
|
||||
virtual PT(Lens) make_copy() const;
|
||||
|
||||
protected:
|
||||
virtual bool extrude_impl(const LPoint3 &point2d,
|
||||
virtual bool do_extrude(const Lens::CData *lens_cdata, const LPoint3 &point2d,
|
||||
LPoint3 &near_point, LPoint3 &far_point) const;
|
||||
virtual bool project_impl(const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
virtual bool do_project(const Lens::CData *lens_cdata,
|
||||
const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
|
@ -3596,7 +3596,10 @@ bool CLP(GraphicsStateGuardian)::
|
||||
apply_vertex_buffer(VertexBufferContext *vbc,
|
||||
const GeomVertexArrayDataHandle *reader, bool force) {
|
||||
nassertr(_supports_buffers, false);
|
||||
nassertr(reader->get_modified() != UpdateSeq::initial(), false);
|
||||
if (reader->get_modified() == UpdateSeq::initial()) {
|
||||
// No need to re-apply.
|
||||
return true;
|
||||
}
|
||||
|
||||
CLP(VertexBufferContext) *gvbc = DCAST(CLP(VertexBufferContext), vbc);
|
||||
|
||||
@ -3785,7 +3788,10 @@ apply_index_buffer(IndexBufferContext *ibc,
|
||||
const GeomPrimitivePipelineReader *reader,
|
||||
bool force) {
|
||||
nassertr(_supports_buffers, false);
|
||||
nassertr(reader->get_modified() != UpdateSeq::initial(), false);
|
||||
if (reader->get_modified() == UpdateSeq::initial()) {
|
||||
// No need to re-apply.
|
||||
return true;
|
||||
}
|
||||
|
||||
CLP(IndexBufferContext) *gibc = DCAST(CLP(IndexBufferContext), ibc);
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
return extrude_impl(LPoint3(point2d[0], point2d[1], 0.0f),
|
||||
CDReader cdata(_cycler);
|
||||
return do_extrude(cdata, LPoint3(point2d[0], point2d[1], 0.0f),
|
||||
near_point, far_point);
|
||||
}
|
||||
|
||||
@ -53,7 +54,8 @@ extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
extrude(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
return extrude_impl(point2d, near_point, far_point);
|
||||
CDReader cdata(_cycler);
|
||||
return do_extrude(cdata, point2d, near_point, far_point);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -76,7 +78,8 @@ extrude(const LPoint3 &point2d, LPoint3 &near_point, LPoint3 &far_point) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
extrude_vec(const LPoint2 &point2d, LVector3 &vec) const {
|
||||
return extrude_vec_impl(LPoint3(point2d[0], point2d[1], 0.0f), vec);
|
||||
CDReader cdata(_cycler);
|
||||
return do_extrude_vec(cdata, LPoint3(point2d[0], point2d[1], 0.0f), vec);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -101,7 +104,8 @@ extrude_vec(const LPoint2 &point2d, LVector3 &vec) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
extrude_vec(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
return extrude_vec_impl(point2d, vec);
|
||||
CDReader cdata(_cycler);
|
||||
return do_extrude_vec(cdata, point2d, vec);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -120,8 +124,9 @@ extrude_vec(const LPoint3 &point2d, LVector3 &vec) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
project(const LPoint3 &point3d, LPoint2 &point2d) const {
|
||||
CDReader cdata(_cycler);
|
||||
LPoint3 result;
|
||||
bool okflag = project_impl(point3d, result);
|
||||
bool okflag = do_project(cdata, point3d, result);
|
||||
point2d.set(result[0], result[1]);
|
||||
return okflag;
|
||||
}
|
||||
@ -146,7 +151,8 @@ project(const LPoint3 &point3d, LPoint2 &point2d) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Lens::
|
||||
project(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
return project_impl(point3d, point2d);
|
||||
CDReader cdata(_cycler);
|
||||
return do_project(cdata, point3d, point2d);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -163,7 +169,8 @@ project(const LPoint3 &point3d, LPoint3 &point2d) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_change_event(const string &event) {
|
||||
_change_event = event;
|
||||
CDWriter cdata(_cycler, true);
|
||||
cdata->_change_event = event;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -175,7 +182,8 @@ set_change_event(const string &event) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const string &Lens::
|
||||
get_change_event() const {
|
||||
return _change_event;
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_change_event;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -187,7 +195,22 @@ get_change_event() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE CoordinateSystem Lens::
|
||||
get_coordinate_system() const {
|
||||
return _cs;
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_cs;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_film_size
|
||||
// Access: Published
|
||||
// Description: Sets the horizontal size of the film without changing
|
||||
// its shape. The aspect ratio remains unchanged; this
|
||||
// computes the vertical size of the film to
|
||||
// automatically maintain the aspect ratio.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_film_size(PN_stdfloat width) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_film_size(cdata, width);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -216,6 +239,45 @@ set_film_size(PN_stdfloat width, PN_stdfloat height) {
|
||||
set_film_size(LVecBase2(width, height));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_film_size
|
||||
// Access: Published
|
||||
// Description: Sets the size and shape of the "film" within the
|
||||
// lens. This both establishes the units used by
|
||||
// calls like set_focal_length(), and establishes the
|
||||
// aspect ratio of the frame.
|
||||
//
|
||||
// In a physical camera, the field of view of a lens is
|
||||
// determined by the lens' focal length and by the size
|
||||
// of the film area exposed by the lens. For instance,
|
||||
// a 35mm camera exposes a rectangle on the film about
|
||||
// 24mm x 36mm, which means a 50mm lens gives about a
|
||||
// 40-degree horizontal field of view.
|
||||
//
|
||||
// In the virtual camera, you may set the film size to
|
||||
// any units here, and specify a focal length in the
|
||||
// same units to simulate the same effect. Or, you may
|
||||
// ignore this parameter, and specify the field of view
|
||||
// and aspect ratio of the lens directly.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_film_size(const LVecBase2 &film_size) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_film_size(cdata, film_size);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_film_size
|
||||
// Access: Published
|
||||
// Description: Returns the horizontal and vertical film size of
|
||||
// the virtual film. See set_film_size().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LVecBase2 &Lens::
|
||||
get_film_size() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_film_size(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_film_offset
|
||||
// Access: Published
|
||||
@ -241,9 +303,8 @@ set_film_offset(PN_stdfloat x, PN_stdfloat y) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_film_offset(const LVecBase2 &film_offset) {
|
||||
_film_offset = film_offset;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
throw_change_event();
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_film_offset(cdata, film_offset);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -254,7 +315,52 @@ set_film_offset(const LVecBase2 &film_offset) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LVector2 &Lens::
|
||||
get_film_offset() const {
|
||||
return _film_offset;
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_film_offset(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_focal_length
|
||||
// Access: Published
|
||||
// Description: Sets the focal length of the lens. This may adjust
|
||||
// the field-of-view correspondingly, and is an
|
||||
// alternate way to specify field of view.
|
||||
//
|
||||
// For certain kinds of lenses (e.g. OrthographicLens),
|
||||
// the focal length has no meaning.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_focal_length(PN_stdfloat focal_length) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_focal_length(cdata, focal_length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_focal_length
|
||||
// Access: Published
|
||||
// Description: Returns the focal length of the lens. This may have
|
||||
// been set explicitly by a previous call to
|
||||
// set_focal_length(), or it may be computed based on
|
||||
// the lens' fov and film_size. For certain kinds of
|
||||
// lenses, the focal length has no meaning.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_focal_length() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_focal_length(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_fov
|
||||
// Access: Published
|
||||
// Description: Sets the horizontal field of view of the lens without
|
||||
// changing the aspect ratio. The vertical field of
|
||||
// view is adjusted to maintain the same aspect ratio.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_fov(PN_stdfloat hfov) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_fov(cdata, hfov);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -274,6 +380,36 @@ set_fov(PN_stdfloat hfov, PN_stdfloat vfov) {
|
||||
set_fov(LVecBase2(hfov, vfov));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_fov
|
||||
// Access: Published
|
||||
// Description: Sets the field of view of the lens in both
|
||||
// dimensions. This establishes both the field of view
|
||||
// and the aspect ratio of the lens. This is one way to
|
||||
// specify the field of view of a lens;
|
||||
// set_focal_length() is another way.
|
||||
//
|
||||
// For certain kinds of lenses (like OrthographicLens),
|
||||
// the field of view has no meaning.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_fov(const LVecBase2 &fov) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_fov(cdata, fov);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_fov
|
||||
// Access: Published
|
||||
// Description: Returns the horizontal and vertical film size of
|
||||
// the virtual film. See set_fov().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LVecBase2 &Lens::
|
||||
get_fov() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_fov(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_hfov
|
||||
// Access: Published
|
||||
@ -296,6 +432,33 @@ get_vfov() const {
|
||||
return get_fov()[1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_aspect_ratio
|
||||
// Access: Published
|
||||
// Description: Sets the aspect ratio of the lens. This is the ratio
|
||||
// of the height to the width of the generated image.
|
||||
// Setting this overrides the two-parameter fov or film
|
||||
// size setting.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_aspect_ratio(PN_stdfloat aspect_ratio) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_aspect_ratio(cdata, aspect_ratio);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_aspect_ratio
|
||||
// Access: Published
|
||||
// Description: Returns the aspect ratio of the Lens. This is
|
||||
// determined based on the indicated film size; see
|
||||
// set_film_size().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_aspect_ratio() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_aspect_ratio(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_near
|
||||
// Access: Published
|
||||
@ -305,9 +468,8 @@ get_vfov() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_near(PN_stdfloat near_distance) {
|
||||
_near_distance = near_distance;
|
||||
adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
throw_change_event();
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_near(cdata, near_distance);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -318,7 +480,8 @@ set_near(PN_stdfloat near_distance) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_near() const {
|
||||
return _near_distance;
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_near(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -330,9 +493,8 @@ get_near() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_far(PN_stdfloat far_distance) {
|
||||
_far_distance = far_distance;
|
||||
adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
throw_change_event();
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_far(cdata, far_distance);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -343,7 +505,8 @@ set_far(PN_stdfloat far_distance) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_far() const {
|
||||
return _far_distance;
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_far(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -353,10 +516,8 @@ get_far() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_near_far(PN_stdfloat near_distance, PN_stdfloat far_distance) {
|
||||
_near_distance = near_distance;
|
||||
_far_distance = far_distance;
|
||||
adjust_comp_flags(CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
throw_change_event();
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_near_far(cdata, near_distance, far_distance);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -373,6 +534,7 @@ INLINE void Lens::
|
||||
set_view_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) {
|
||||
set_view_hpr(LVecBase3(h, p, r));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_view_vector
|
||||
// Access: Published
|
||||
@ -387,6 +549,111 @@ set_view_vector(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_s
|
||||
set_view_vector(LVector3(x, y, z), LVector3(i, j, k));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_interocular_distance
|
||||
// Access: Published
|
||||
// Description: Sets the distance between the left and right eyes of
|
||||
// a stereo camera. This distance is used to apply a
|
||||
// stereo effect when the lens is rendered on a stereo
|
||||
// display region. It only has an effect on a
|
||||
// PerspectiveLens.
|
||||
//
|
||||
// The left eye and the right eye are each offset along
|
||||
// the X axis by half of this distance, so that this
|
||||
// parameter specifies the total distance between them.
|
||||
//
|
||||
// Also see set_convergence_distance(), which relates.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_interocular_distance(PN_stdfloat interocular_distance) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_interocular_distance(cdata, interocular_distance);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_interocular_distance
|
||||
// Access: Published
|
||||
// Description: See set_interocular_distance().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_interocular_distance() const {
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_interocular_distance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_convergence_distance
|
||||
// Access: Published
|
||||
// Description: Sets the distance between between the camera plane
|
||||
// and the point in the distance that the left and right
|
||||
// eyes are both looking at. This distance is used to
|
||||
// apply a stereo effect when the lens is rendered on a
|
||||
// stereo display region. It only has an effect on a
|
||||
// PerspectiveLens.
|
||||
//
|
||||
// This parameter must be greater than 0, but may be as
|
||||
// large as you like. It controls the amount to which
|
||||
// the two eyes are directed inwards towards each other,
|
||||
// which is a normal property of stereo vision. It is a
|
||||
// distance, not an angle; normally this should be set
|
||||
// to the distance from the camera to the area of
|
||||
// interest in your scene. If you want to simulate
|
||||
// parallel stereo, set this value to a very large
|
||||
// number.
|
||||
//
|
||||
// Also see set_interocular_distance(), which relates.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_convergence_distance(PN_stdfloat convergence_distance) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_convergence_distance(cdata, convergence_distance);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_convergence_distance
|
||||
// Access: Published
|
||||
// Description: See set_convergence_distance().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
get_convergence_distance() const {
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_convergence_distance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::set_view_mat
|
||||
// Access: Published
|
||||
// Description: Sets an arbitrary transformation on the lens. This
|
||||
// replaces the individual transformation components
|
||||
// like set_view_hpr().
|
||||
//
|
||||
// Setting a transformation here will have a slightly
|
||||
// different effect than putting one on the LensNode
|
||||
// that contains this lens. In particular, lighting and
|
||||
// other effects computations will still be performed on
|
||||
// the lens in its untransformed (facing forward)
|
||||
// position, but the actual projection matrix will be
|
||||
// transformed by this matrix.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
set_view_mat(const LMatrix4 &view_mat) {
|
||||
CDWriter cdata(_cycler, true);
|
||||
do_set_view_mat(cdata, view_mat);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_view_mat
|
||||
// Access: Published
|
||||
// Description: Returns the direction in which the lens is facing.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_view_mat() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_view_mat(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_keystone
|
||||
// Access: Published
|
||||
@ -395,7 +662,83 @@ set_view_vector(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat i, PN_s
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LVecBase2 &Lens::
|
||||
get_keystone() const {
|
||||
return _keystone;
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_keystone;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_projection_mat
|
||||
// Access: Published
|
||||
// Description: Returns the complete transformation matrix from a 3-d
|
||||
// point in space to a point on the film, if such a
|
||||
// matrix exists, or the identity matrix if the lens is
|
||||
// nonlinear.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_projection_mat(StereoChannel channel) const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_projection_mat(cdata, channel);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_projection_mat_inv
|
||||
// Access: Published
|
||||
// Description: Returns the matrix that transforms from a 2-d point
|
||||
// on the film to a 3-d vector in space, if such a
|
||||
// matrix exists.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_projection_mat_inv(StereoChannel stereo_channel) const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_projection_mat_inv(cdata, stereo_channel);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_film_mat
|
||||
// Access: Published
|
||||
// Description: Returns the matrix that transforms from a point
|
||||
// behind the lens to a point on the film.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_film_mat() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_film_mat(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_film_mat_inv
|
||||
// Access: Published
|
||||
// Description: Returns the matrix that transforms from a point on
|
||||
// the film to a point behind the lens.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_film_mat_inv() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_film_mat_inv(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_lens_mat
|
||||
// Access: Published
|
||||
// Description: Returns the matrix that transforms from a point
|
||||
// in front of the lens to a point in space.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_lens_mat() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_lens_mat(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::get_lens_mat_inv
|
||||
// Access: Published
|
||||
// Description: Returns the matrix that transforms from a point in
|
||||
// space to a point in front of the lens.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LMatrix4 &Lens::
|
||||
get_lens_mat_inv() const {
|
||||
CDReader cdata(_cycler);
|
||||
return do_get_lens_mat_inv(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -408,29 +751,109 @@ get_keystone() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const UpdateSeq &Lens::
|
||||
get_last_change() const {
|
||||
return _last_change;
|
||||
CDReader cdata(_cycler);
|
||||
return cdata->_last_change;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::adjust_user_flags
|
||||
// Function: Lens::do_adjust_user_flags
|
||||
// Access: Protected
|
||||
// Description: Clears from _user_flags the bits in the first
|
||||
// parameter, and sets the bits in the second parameter.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
adjust_user_flags(int clear_flags, int set_flags) {
|
||||
_user_flags = (_user_flags & ~clear_flags) | set_flags;
|
||||
do_adjust_user_flags(CData *cdata, int clear_flags, int set_flags) {
|
||||
cdata->_user_flags = (cdata->_user_flags & ~clear_flags) | set_flags;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::adjust_comp_flags
|
||||
// Function: Lens::do_adjust_comp_flags
|
||||
// Access: Protected
|
||||
// Description: Clears from _comp_flags the bits in the first
|
||||
// parameter, and sets the bits in the second parameter.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
adjust_comp_flags(int clear_flags, int set_flags) {
|
||||
_comp_flags = (_comp_flags & ~clear_flags) | set_flags;
|
||||
do_adjust_comp_flags(CData *cdata, int clear_flags, int set_flags) {
|
||||
cdata->_comp_flags = (cdata->_comp_flags & ~clear_flags) | set_flags;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_set_film_offset
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
do_set_film_offset(CData *cdata, const LVecBase2 &film_offset) {
|
||||
cdata->_film_offset = film_offset;
|
||||
do_adjust_comp_flags(cdata, CF_mat, 0);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_get_film_offset
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const LVector2 &Lens::
|
||||
do_get_film_offset(const CData *cdata) const {
|
||||
return cdata->_film_offset;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_set_near
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
do_set_near(CData *cdata, PN_stdfloat near_distance) {
|
||||
cdata->_near_distance = near_distance;
|
||||
do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_get_near
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
do_get_near(const CData *cdata) const {
|
||||
return cdata->_near_distance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_set_far
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
do_set_far(CData *cdata, PN_stdfloat far_distance) {
|
||||
cdata->_far_distance = far_distance;
|
||||
do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_get_far
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat Lens::
|
||||
do_get_far(const CData *cdata) const {
|
||||
return cdata->_far_distance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Lens::do_set_near_far
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Lens::
|
||||
do_set_near_far(CData *cdata, PN_stdfloat near_distance, PN_stdfloat far_distance) {
|
||||
cdata->_near_distance = near_distance;
|
||||
cdata->_far_distance = far_distance;
|
||||
do_adjust_comp_flags(cdata, CF_projection_mat | CF_projection_mat_inv, 0);
|
||||
do_throw_change_event(cdata);
|
||||
}
|
||||
|
||||
INLINE ostream &
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,10 @@
|
||||
#include "updateSeq.h"
|
||||
#include "geomVertexData.h"
|
||||
#include "pointerTo.h"
|
||||
#include "cycleData.h"
|
||||
#include "cycleDataReader.h"
|
||||
#include "cycleDataWriter.h"
|
||||
#include "pipelineCycler.h"
|
||||
|
||||
class BoundingVolume;
|
||||
|
||||
@ -32,11 +36,11 @@ class BoundingVolume;
|
||||
// lenses, linear and otherwise. Presently, this
|
||||
// includes perspective and orthographic lenses.
|
||||
//
|
||||
// A Lens object is the main part of a Camera node
|
||||
// (defined in sgraph), which defines the fundamental
|
||||
// interface to point-of-view for rendering. Lenses are
|
||||
// also used in other contexts, however; for instance, a
|
||||
// Spotlight is also defined using a lens.
|
||||
// A Lens object is the main part of a Camera node,
|
||||
// which defines the fundamental interface to
|
||||
// point-of-view for rendering. Lenses are also used in
|
||||
// other contexts, however; for instance, a Spotlight is
|
||||
// also defined using a lens.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_GOBJ Lens : public TypedWritableReferenceCount {
|
||||
public:
|
||||
@ -71,29 +75,29 @@ PUBLISHED:
|
||||
|
||||
void clear();
|
||||
|
||||
void set_film_size(PN_stdfloat width);
|
||||
INLINE void set_film_size(PN_stdfloat width);
|
||||
INLINE void set_film_size(PN_stdfloat width, PN_stdfloat height);
|
||||
void set_film_size(const LVecBase2 &film_size);
|
||||
const LVecBase2 &get_film_size() const;
|
||||
INLINE void set_film_size(const LVecBase2 &film_size);
|
||||
INLINE const LVecBase2 &get_film_size() const;
|
||||
|
||||
INLINE void set_film_offset(PN_stdfloat x, PN_stdfloat y);
|
||||
INLINE void set_film_offset(const LVecBase2 &film_offset);
|
||||
INLINE const LVector2 &get_film_offset() const;
|
||||
|
||||
void set_focal_length(PN_stdfloat focal_length);
|
||||
PN_stdfloat get_focal_length() const;
|
||||
INLINE void set_focal_length(PN_stdfloat focal_length);
|
||||
INLINE PN_stdfloat get_focal_length() const;
|
||||
|
||||
void set_min_fov(PN_stdfloat min_fov);
|
||||
void set_fov(PN_stdfloat fov);
|
||||
INLINE void set_fov(PN_stdfloat fov);
|
||||
INLINE void set_fov(PN_stdfloat hfov, PN_stdfloat vfov);
|
||||
void set_fov(const LVecBase2 &fov);
|
||||
const LVecBase2 &get_fov() const;
|
||||
INLINE void set_fov(const LVecBase2 &fov);
|
||||
INLINE const LVecBase2 &get_fov() const;
|
||||
INLINE PN_stdfloat get_hfov() const;
|
||||
INLINE PN_stdfloat get_vfov() const;
|
||||
PN_stdfloat get_min_fov() const;
|
||||
|
||||
void set_aspect_ratio(PN_stdfloat aspect_ratio);
|
||||
PN_stdfloat get_aspect_ratio() const;
|
||||
INLINE void set_aspect_ratio(PN_stdfloat aspect_ratio);
|
||||
INLINE PN_stdfloat get_aspect_ratio() const;
|
||||
|
||||
INLINE void set_near(PN_stdfloat near_distance);
|
||||
INLINE PN_stdfloat get_near() const;
|
||||
@ -113,13 +117,13 @@ PUBLISHED:
|
||||
const LVector3 &get_up_vector() const;
|
||||
LPoint3 get_nodal_point() const;
|
||||
|
||||
void set_interocular_distance(PN_stdfloat interocular_distance);
|
||||
PN_stdfloat get_interocular_distance() const;
|
||||
void set_convergence_distance(PN_stdfloat convergence_distance);
|
||||
PN_stdfloat get_convergence_distance() const;
|
||||
INLINE void set_interocular_distance(PN_stdfloat interocular_distance);
|
||||
INLINE PN_stdfloat get_interocular_distance() const;
|
||||
INLINE void set_convergence_distance(PN_stdfloat convergence_distance);
|
||||
INLINE PN_stdfloat get_convergence_distance() const;
|
||||
|
||||
void set_view_mat(const LMatrix4 &view_mat);
|
||||
const LMatrix4 &get_view_mat() const;
|
||||
INLINE void set_view_mat(const LMatrix4 &view_mat);
|
||||
INLINE const LMatrix4 &get_view_mat() const;
|
||||
void clear_view_mat();
|
||||
|
||||
void set_keystone(const LVecBase2 &keystone);
|
||||
@ -150,14 +154,14 @@ PUBLISHED:
|
||||
|
||||
virtual PT(BoundingVolume) make_bounds() const;
|
||||
|
||||
const LMatrix4 &get_projection_mat(StereoChannel channel = SC_mono) const;
|
||||
const LMatrix4 &get_projection_mat_inv(StereoChannel channel = SC_mono) const;
|
||||
INLINE const LMatrix4 &get_projection_mat(StereoChannel channel = SC_mono) const;
|
||||
INLINE const LMatrix4 &get_projection_mat_inv(StereoChannel channel = SC_mono) const;
|
||||
|
||||
const LMatrix4 &get_film_mat() const;
|
||||
const LMatrix4 &get_film_mat_inv() const;
|
||||
INLINE const LMatrix4 &get_film_mat() const;
|
||||
INLINE const LMatrix4 &get_film_mat_inv() const;
|
||||
|
||||
const LMatrix4 &get_lens_mat() const;
|
||||
const LMatrix4 &get_lens_mat_inv() const;
|
||||
INLINE const LMatrix4 &get_lens_mat() const;
|
||||
INLINE const LMatrix4 &get_lens_mat_inv() const;
|
||||
|
||||
virtual void output(ostream &out) const;
|
||||
virtual void write(ostream &out, int indent_level = 0) const;
|
||||
@ -166,33 +170,76 @@ public:
|
||||
INLINE const UpdateSeq &get_last_change() const;
|
||||
|
||||
protected:
|
||||
INLINE void adjust_user_flags(int clear_flags, int set_flags);
|
||||
INLINE void adjust_comp_flags(int clear_flags, int set_flags);
|
||||
class CData;
|
||||
|
||||
void throw_change_event();
|
||||
INLINE void do_adjust_user_flags(CData *cdata, int clear_flags, int set_flags);
|
||||
INLINE void do_adjust_comp_flags(CData *cdata, int clear_flags, int set_flags);
|
||||
|
||||
virtual bool extrude_impl(const LPoint3 &point2d,
|
||||
void do_set_film_size(CData *cdata, PN_stdfloat width);
|
||||
void do_set_film_size(CData *cdata, const LVecBase2 &film_size);
|
||||
const LVecBase2 &do_get_film_size(const CData *cdata) const;
|
||||
|
||||
INLINE void do_set_film_offset(CData *cdata, const LVecBase2 &film_offset);
|
||||
INLINE const LVector2 &do_get_film_offset(const CData *cdata) const;
|
||||
|
||||
void do_set_focal_length(CData *cdata, PN_stdfloat focal_length);
|
||||
PN_stdfloat do_get_focal_length(const CData *cdata) const;
|
||||
|
||||
void do_set_fov(CData *cdata, PN_stdfloat fov);
|
||||
void do_set_fov(CData *cdata, const LVecBase2 &fov);
|
||||
const LVecBase2 &do_get_fov(const CData *cdata) const;
|
||||
|
||||
void do_set_aspect_ratio(CData *cdata, PN_stdfloat aspect_ratio);
|
||||
PN_stdfloat do_get_aspect_ratio(const CData *cdata) const;
|
||||
|
||||
INLINE void do_set_near(CData *cdata, PN_stdfloat near_distance);
|
||||
INLINE PN_stdfloat do_get_near(const CData *cdata) const;
|
||||
INLINE void do_set_far(CData *cdata, PN_stdfloat far_distance);
|
||||
INLINE PN_stdfloat do_get_far(const CData *cdata) const;
|
||||
INLINE void do_set_near_far(CData *cdata, PN_stdfloat near_distance, PN_stdfloat far_distance);
|
||||
|
||||
const LMatrix4 &do_get_projection_mat(const CData *cdata, StereoChannel channel = SC_mono) const;
|
||||
const LMatrix4 &do_get_projection_mat_inv(const CData *cdata, StereoChannel channel = SC_mono) const;
|
||||
|
||||
const LMatrix4 &do_get_film_mat(const CData *cdata) const;
|
||||
const LMatrix4 &do_get_film_mat_inv(const CData *cdata) const;
|
||||
|
||||
const LMatrix4 &do_get_lens_mat(const CData *cdata) const;
|
||||
const LMatrix4 &do_get_lens_mat_inv(const CData *cdata) const;
|
||||
|
||||
void do_set_interocular_distance(CData *cdata, PN_stdfloat interocular_distance);
|
||||
void do_set_convergence_distance(CData *cdata, PN_stdfloat convergence_distance);
|
||||
|
||||
void do_set_view_mat(CData *cdata, const LMatrix4 &view_mat);
|
||||
const LMatrix4 &do_get_view_mat(const CData *cdata) const;
|
||||
|
||||
void do_throw_change_event(CData *cdata);
|
||||
|
||||
virtual bool do_extrude(const CData *cdata, const LPoint3 &point2d,
|
||||
LPoint3 &near_point, LPoint3 &far_point) const;
|
||||
virtual bool extrude_vec_impl(const LPoint3 &point2d, LVector3 &vec) const;
|
||||
virtual bool project_impl(const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
virtual bool do_extrude_vec(const CData *cdata,
|
||||
const LPoint3 &point2d, LVector3 &vec) const;
|
||||
virtual bool do_project(const CData *cdata,
|
||||
const LPoint3 &point3d, LPoint3 &point2d) const;
|
||||
|
||||
virtual void compute_film_size();
|
||||
virtual void compute_focal_length();
|
||||
virtual void compute_fov();
|
||||
virtual void compute_aspect_ratio();
|
||||
virtual void compute_view_hpr();
|
||||
virtual void compute_view_vector();
|
||||
virtual void compute_projection_mat();
|
||||
virtual void compute_film_mat();
|
||||
virtual void compute_lens_mat();
|
||||
virtual void do_compute_film_size(CData *cdata);
|
||||
virtual void do_compute_focal_length(CData *cdata);
|
||||
virtual void do_compute_fov(CData *cdata);
|
||||
virtual void do_compute_aspect_ratio(CData *cdata);
|
||||
virtual void do_compute_view_hpr(CData *cdata);
|
||||
virtual void do_compute_view_vector(CData *cdata);
|
||||
virtual void do_compute_projection_mat(CData *cdata);
|
||||
virtual void do_compute_film_mat(CData *cdata);
|
||||
virtual void do_compute_lens_mat(CData *cdata);
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
virtual PN_stdfloat film_to_fov(PN_stdfloat film_size, PN_stdfloat focal_length, bool horiz) const;
|
||||
|
||||
private:
|
||||
void resequence_fov_triad(char &newest, char &older_a, char &older_b) const;
|
||||
int define_geom_data();
|
||||
void do_resequence_fov_triad(const CData *cdata,
|
||||
char &newest, char &older_a, char &older_b) const;
|
||||
int do_define_geom_data(CData *cdata);
|
||||
static void build_shear_mat(LMatrix4 &shear_mat,
|
||||
const LPoint3 &cul, const LPoint3 &cur,
|
||||
const LPoint3 &cll, const LPoint3 &clr);
|
||||
@ -200,30 +247,6 @@ private:
|
||||
const LVector3 &vec);
|
||||
|
||||
protected:
|
||||
string _change_event;
|
||||
UpdateSeq _last_change;
|
||||
CoordinateSystem _cs;
|
||||
|
||||
LVecBase2 _film_size;
|
||||
LVector2 _film_offset;
|
||||
PN_stdfloat _focal_length;
|
||||
LVecBase2 _fov;
|
||||
PN_stdfloat _min_fov;
|
||||
PN_stdfloat _aspect_ratio;
|
||||
PN_stdfloat _near_distance, _far_distance;
|
||||
|
||||
LVecBase3 _view_hpr;
|
||||
LVector3 _view_vector, _up_vector;
|
||||
PN_stdfloat _interocular_distance;
|
||||
PN_stdfloat _convergence_distance;
|
||||
LVecBase2 _keystone;
|
||||
|
||||
LMatrix4 _film_mat, _film_mat_inv;
|
||||
LMatrix4 _lens_mat, _lens_mat_inv;
|
||||
LMatrix4 _projection_mat, _projection_mat_inv;
|
||||
LMatrix4 _projection_mat_left, _projection_mat_left_inv;
|
||||
LMatrix4 _projection_mat_right, _projection_mat_right_inv;
|
||||
|
||||
enum UserFlags {
|
||||
// Parameters the user may have explicitly specified.
|
||||
UF_film_width = 0x0001,
|
||||
@ -260,6 +283,46 @@ protected:
|
||||
CF_focal_length = 0x1000,
|
||||
CF_fov = 0x2000,
|
||||
};
|
||||
|
||||
// This is the data that must be cycled between pipeline stages.
|
||||
class EXPCL_PANDA_GOBJ CData : public CycleData {
|
||||
public:
|
||||
CData();
|
||||
CData(const CData ©);
|
||||
ALLOC_DELETED_CHAIN(CData);
|
||||
virtual CycleData *make_copy() const;
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
|
||||
virtual void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
virtual TypeHandle get_parent_type() const {
|
||||
return Lens::get_class_type();
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
string _change_event;
|
||||
UpdateSeq _last_change;
|
||||
CoordinateSystem _cs;
|
||||
|
||||
LVecBase2 _film_size;
|
||||
LVector2 _film_offset;
|
||||
PN_stdfloat _focal_length;
|
||||
LVecBase2 _fov;
|
||||
PN_stdfloat _min_fov;
|
||||
PN_stdfloat _aspect_ratio;
|
||||
PN_stdfloat _near_distance, _far_distance;
|
||||
|
||||
LVecBase3 _view_hpr;
|
||||
LVector3 _view_vector, _up_vector;
|
||||
PN_stdfloat _interocular_distance;
|
||||
PN_stdfloat _convergence_distance;
|
||||
LVecBase2 _keystone;
|
||||
|
||||
LMatrix4 _film_mat, _film_mat_inv;
|
||||
LMatrix4 _lens_mat, _lens_mat_inv;
|
||||
LMatrix4 _projection_mat, _projection_mat_inv;
|
||||
LMatrix4 _projection_mat_left, _projection_mat_left_inv;
|
||||
LMatrix4 _projection_mat_right, _projection_mat_right_inv;
|
||||
|
||||
short _user_flags;
|
||||
short _comp_flags;
|
||||
|
||||
@ -271,6 +334,22 @@ protected:
|
||||
|
||||
PT(GeomVertexData) _geom_data;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
register_type(_type_handle, "Lens::CData");
|
||||
}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
PipelineCycler<CData> _cycler;
|
||||
typedef CycleDataReader<CData> CDReader;
|
||||
typedef CycleDataWriter<CData> CDWriter;
|
||||
|
||||
public:
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
@ -289,6 +368,7 @@ public:
|
||||
TypedWritableReferenceCount::init_type();
|
||||
register_type(_type_handle, "Lens",
|
||||
TypedWritableReferenceCount::get_class_type());
|
||||
CData::init_type();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -76,8 +76,9 @@ operator = (const MatrixLens ©) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MatrixLens::
|
||||
set_user_mat(const LMatrix4 &user_mat) {
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
_user_mat = user_mat;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
do_adjust_comp_flags(lens_cdata, CF_mat, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -108,9 +109,10 @@ get_user_mat() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MatrixLens::
|
||||
set_left_eye_mat(const LMatrix4 &left_eye_mat) {
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
_left_eye_mat = left_eye_mat;
|
||||
_ml_flags |= MF_has_left_eye;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
do_adjust_comp_flags(lens_cdata, CF_mat, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -122,8 +124,9 @@ set_left_eye_mat(const LMatrix4 &left_eye_mat) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MatrixLens::
|
||||
clear_left_eye_mat() {
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
_ml_flags &= ~MF_has_left_eye;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
do_adjust_comp_flags(lens_cdata, CF_mat, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -170,9 +173,10 @@ get_left_eye_mat() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MatrixLens::
|
||||
set_right_eye_mat(const LMatrix4 &right_eye_mat) {
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
_right_eye_mat = right_eye_mat;
|
||||
_ml_flags |= MF_has_right_eye;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
do_adjust_comp_flags(lens_cdata, CF_mat, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -184,8 +188,9 @@ set_right_eye_mat(const LMatrix4 &right_eye_mat) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MatrixLens::
|
||||
clear_right_eye_mat() {
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
_ml_flags &= ~MF_has_right_eye;
|
||||
adjust_comp_flags(CF_mat, 0);
|
||||
do_adjust_comp_flags(lens_cdata, CF_mat, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -54,28 +54,28 @@ write(ostream &out, int indent_level) const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MatrixLens::compute_projection_mat
|
||||
// Function: MatrixLens::do_compute_projection_mat
|
||||
// Access: Protected, Virtual
|
||||
// Description: Computes the complete transformation matrix from 3-d
|
||||
// point to 2-d point, if the lens is linear.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MatrixLens::
|
||||
compute_projection_mat() {
|
||||
_projection_mat = get_lens_mat_inv() * _user_mat * get_film_mat();
|
||||
do_compute_projection_mat(Lens::CData *lens_cdata) {
|
||||
lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * _user_mat * do_get_film_mat(lens_cdata);
|
||||
|
||||
if (_ml_flags & MF_has_left_eye) {
|
||||
_projection_mat_left = get_lens_mat_inv() * _left_eye_mat * get_film_mat();
|
||||
lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * _left_eye_mat * do_get_film_mat(lens_cdata);
|
||||
} else {
|
||||
_projection_mat_left = _projection_mat;
|
||||
lens_cdata->_projection_mat_left = lens_cdata->_projection_mat;
|
||||
}
|
||||
|
||||
if (_ml_flags & MF_has_right_eye) {
|
||||
_projection_mat_right = get_lens_mat_inv() * _right_eye_mat * get_film_mat();
|
||||
lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * _right_eye_mat * do_get_film_mat(lens_cdata);
|
||||
} else {
|
||||
_projection_mat_right = _projection_mat;
|
||||
lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
|
||||
}
|
||||
|
||||
adjust_comp_flags(CF_projection_mat_inv,
|
||||
do_adjust_comp_flags(lens_cdata, CF_projection_mat_inv,
|
||||
CF_projection_mat);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
virtual void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
protected:
|
||||
virtual void compute_projection_mat();
|
||||
virtual void do_compute_projection_mat(Lens::CData *lens_cdata);
|
||||
|
||||
private:
|
||||
LMatrix4 _user_mat;
|
||||
|
@ -65,20 +65,20 @@ write(ostream &out, int indent_level) const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: OrthographicLens::compute_projection_mat
|
||||
// Function: OrthographicLens::do_compute_projection_mat
|
||||
// Access: Protected, Virtual
|
||||
// Description: Computes the complete transformation matrix from 3-d
|
||||
// point to 2-d point, if the lens is linear.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void OrthographicLens::
|
||||
compute_projection_mat() {
|
||||
CoordinateSystem cs = _cs;
|
||||
do_compute_projection_mat(Lens::CData *lens_cdata) {
|
||||
CoordinateSystem cs = lens_cdata->_cs;
|
||||
if (cs == CS_default) {
|
||||
cs = get_default_coordinate_system();
|
||||
}
|
||||
|
||||
PN_stdfloat a = 2.0f / (_far_distance - _near_distance);
|
||||
PN_stdfloat b = -(_far_distance + _near_distance) / (_far_distance - _near_distance);
|
||||
PN_stdfloat a = 2.0f / (lens_cdata->_far_distance - lens_cdata->_near_distance);
|
||||
PN_stdfloat b = -(lens_cdata->_far_distance + lens_cdata->_near_distance) / (lens_cdata->_far_distance - lens_cdata->_near_distance);
|
||||
|
||||
LMatrix4 canonical;
|
||||
switch (cs) {
|
||||
@ -116,11 +116,11 @@ compute_projection_mat() {
|
||||
canonical = LMatrix4::ident_mat();
|
||||
}
|
||||
|
||||
_projection_mat = get_lens_mat_inv() * canonical * get_film_mat();
|
||||
_projection_mat_left = _projection_mat_right = _projection_mat;
|
||||
lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * canonical * do_get_film_mat(lens_cdata);
|
||||
lens_cdata->_projection_mat_left = lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
|
||||
|
||||
adjust_comp_flags(CF_projection_mat_inv | CF_projection_mat_left_inv |
|
||||
CF_projection_mat_right_inv,
|
||||
do_adjust_comp_flags(lens_cdata,
|
||||
CF_projection_mat_inv | CF_projection_mat_left_inv | CF_projection_mat_right_inv,
|
||||
CF_projection_mat);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
protected:
|
||||
virtual void compute_projection_mat();
|
||||
virtual void do_compute_projection_mat(Lens::CData *lens_cdata);
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
|
@ -28,7 +28,8 @@ PerspectiveLens() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PerspectiveLens::
|
||||
PerspectiveLens(PN_stdfloat hfov, PN_stdfloat vfov) {
|
||||
_fov.set(hfov, vfov);
|
||||
Lens::CDWriter lens_cdata(Lens::_cycler, true);
|
||||
lens_cdata->_fov.set(hfov, vfov);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -54,21 +54,21 @@ is_perspective() const {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PerspectiveLens::compute_projection_mat
|
||||
// Function: PerspectiveLens::do_compute_projection_mat
|
||||
// Access: Protected, Virtual
|
||||
// Description: Computes the complete transformation matrix from 3-d
|
||||
// point to 2-d point, if the lens is linear.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PerspectiveLens::
|
||||
compute_projection_mat() {
|
||||
CoordinateSystem cs = _cs;
|
||||
do_compute_projection_mat(Lens::CData *lens_cdata) {
|
||||
CoordinateSystem cs = lens_cdata->_cs;
|
||||
if (cs == CS_default) {
|
||||
cs = get_default_coordinate_system();
|
||||
}
|
||||
|
||||
PN_stdfloat fl = get_focal_length();
|
||||
PN_stdfloat fFar = get_far();
|
||||
PN_stdfloat fNear = get_near();
|
||||
PN_stdfloat fl = do_get_focal_length(lens_cdata);
|
||||
PN_stdfloat fFar = do_get_far(lens_cdata);
|
||||
PN_stdfloat fNear = do_get_near(lens_cdata);
|
||||
PN_stdfloat far_minus_near = fFar-fNear;
|
||||
PN_stdfloat a = (fFar + fNear);
|
||||
PN_stdfloat b = -2.0f * fFar * fNear;
|
||||
@ -112,29 +112,29 @@ compute_projection_mat() {
|
||||
canonical = LMatrix4::ident_mat();
|
||||
}
|
||||
|
||||
_projection_mat = get_lens_mat_inv() * canonical * get_film_mat();
|
||||
lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * canonical * do_get_film_mat(lens_cdata);
|
||||
|
||||
if ((_user_flags & UF_interocular_distance) == 0) {
|
||||
_projection_mat_left = _projection_mat_right = _projection_mat;
|
||||
if ((lens_cdata->_user_flags & UF_interocular_distance) == 0) {
|
||||
lens_cdata->_projection_mat_left = lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
|
||||
|
||||
} else {
|
||||
// Compute the left and right projection matrices in case this
|
||||
// lens is assigned to a stereo DisplayRegion.
|
||||
|
||||
LVector3 iod = _interocular_distance * 0.5f * LVector3::left(_cs);
|
||||
_projection_mat_left = get_lens_mat_inv() * LMatrix4::translate_mat(-iod) * canonical * get_film_mat();
|
||||
_projection_mat_right = get_lens_mat_inv() * LMatrix4::translate_mat(iod) * canonical * get_film_mat();
|
||||
LVector3 iod = lens_cdata->_interocular_distance * 0.5f * LVector3::left(lens_cdata->_cs);
|
||||
lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(-iod) * canonical * do_get_film_mat(lens_cdata);
|
||||
lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * LMatrix4::translate_mat(iod) * canonical * do_get_film_mat(lens_cdata);
|
||||
|
||||
if (_user_flags & UF_convergence_distance) {
|
||||
nassertv(_convergence_distance != 0.0f);
|
||||
LVector3 cd = (0.25f / _convergence_distance) * LVector3::left(_cs);
|
||||
_projection_mat_left *= LMatrix4::translate_mat(cd);
|
||||
_projection_mat_right *= LMatrix4::translate_mat(-cd);
|
||||
if (lens_cdata->_user_flags & UF_convergence_distance) {
|
||||
nassertv(lens_cdata->_convergence_distance != 0.0f);
|
||||
LVector3 cd = (0.25f / lens_cdata->_convergence_distance) * LVector3::left(lens_cdata->_cs);
|
||||
lens_cdata->_projection_mat_left *= LMatrix4::translate_mat(cd);
|
||||
lens_cdata->_projection_mat_right *= LMatrix4::translate_mat(-cd);
|
||||
}
|
||||
}
|
||||
|
||||
adjust_comp_flags(CF_projection_mat_inv | CF_projection_mat_left_inv |
|
||||
CF_projection_mat_right_inv,
|
||||
do_adjust_comp_flags(lens_cdata,
|
||||
CF_projection_mat_inv | CF_projection_mat_left_inv | CF_projection_mat_right_inv,
|
||||
CF_projection_mat);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
virtual bool is_perspective() const;
|
||||
|
||||
protected:
|
||||
virtual void compute_projection_mat();
|
||||
virtual void do_compute_projection_mat(Lens::CData *lens_cdata);
|
||||
|
||||
virtual PN_stdfloat fov_to_film(PN_stdfloat fov, PN_stdfloat focal_length, bool horiz) const;
|
||||
virtual PN_stdfloat fov_to_focal_length(PN_stdfloat fov, PN_stdfloat film_size, bool horiz) const;
|
||||
|
@ -823,7 +823,7 @@ protected:
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
register_type(_type_handle, "Geom::CData");
|
||||
register_type(_type_handle, "Texture::CData");
|
||||
}
|
||||
|
||||
private:
|
||||
@ -897,6 +897,7 @@ public:
|
||||
TypedWritableReferenceCount::init_type();
|
||||
register_type(_type_handle, "Texture",
|
||||
TypedWritableReferenceCount::get_class_type());
|
||||
CData::init_type();
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
|
@ -95,6 +95,18 @@ operator const CycleDataType * () const {
|
||||
return _pointer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CycleDataReader::p (full)
|
||||
// Access: Public
|
||||
// Description: This allows the CycleDataReader to be passed to any
|
||||
// function that expects a const CycleDataType pointer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class CycleDataType>
|
||||
INLINE const CycleDataType *CycleDataReader<CycleDataType>::
|
||||
p() const {
|
||||
return _pointer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CycleDataReader::get_current_thread (full)
|
||||
// Access: Public
|
||||
@ -178,6 +190,18 @@ operator const CycleDataType * () const {
|
||||
return _pointer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CycleDataReader::p (trivial)
|
||||
// Access: Public
|
||||
// Description: This allows the CycleDataReader to be passed to any
|
||||
// function that expects a const CycleDataType pointer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class CycleDataType>
|
||||
INLINE const CycleDataType *CycleDataReader<CycleDataType>::
|
||||
p() const {
|
||||
return _pointer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CycleDataReader::get_current_thread (trivial)
|
||||
// Access: Public
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
|
||||
INLINE const CycleDataType *operator -> () const;
|
||||
INLINE operator const CycleDataType * () const;
|
||||
INLINE const CycleDataType *p() const;
|
||||
|
||||
INLINE Thread *get_current_thread() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user