Browse Source

fix confusion with depth range of Lens::project()

David Rose 13 years ago
parent
commit
93bd44e85e

+ 2 - 2
panda/src/display/graphicsOutput.cxx

@@ -1144,7 +1144,7 @@ get_supports_render_texture() const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::flip_ready
-//       Access: Public, Virtual
+//       Access: Published, Virtual
 //  Description: Returns true if a frame has been rendered and needs
 //               to be flipped, false otherwise.
 ////////////////////////////////////////////////////////////////////
@@ -1155,7 +1155,7 @@ flip_ready() const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::get_host
-//       Access: Public, Virtual
+//       Access: Published, Virtual
 //  Description: This is normally called only from within
 //               make_texture_buffer().  When called on a
 //               ParasiteBuffer, it returns the host of that buffer;

+ 6 - 4
panda/src/display/graphicsOutput.h

@@ -215,14 +215,16 @@ PUBLISHED:
 
   virtual bool get_supports_render_texture() const;
 
-public:
-  // These are not intended to be called directly by the user.
+PUBLISHED:
+  // These are not intended to be called directly by the user, but
+  // they're published anyway since they might occasionally be useful
+  // for low-level debugging.
   virtual bool flip_ready() const;
+  virtual GraphicsOutput *get_host();
 
+public:
   INLINE bool operator < (const GraphicsOutput &other) const;
 
-  virtual GraphicsOutput *get_host();
-
   virtual void request_open();
   virtual void request_close();
 

+ 4 - 4
panda/src/distort/cylindricalLens.cxx

@@ -121,8 +121,8 @@ do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d, LVector3 &
 //               (-1,-1) is the lower-left corner.
 //
 //               Some lens types also set the z coordinate of the 2-d
-//               point to a value in the range (-1, 1), where 1
-//               represents a point on the near plane, and -1
+//               point to a value in the range (-1, 1), where -1
+//               represents a point on the near plane, and 1
 //               represents a point on the far plane.
 //
 //               Returns true if the 3-d point is in front of the lens
@@ -159,8 +159,8 @@ do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point
      // The y position is the Z height divided by the perspective
      // distance.
      p[2] * focal_length / pdist,
-     // Z is the distance scaled into the range 1 .. -1.
-     1.0 - 2.0 * z
+     // Z is the distance scaled into the range -1 .. 1.
+     2.0 * z - 1.0
      );
 
   // Now we have to transform the point according to the film

+ 4 - 4
panda/src/distort/fisheyeLens.cxx

@@ -149,8 +149,8 @@ do_extrude_vec(const Lens::CData *lens_cdata, const LPoint3 &point2d, LVector3 &
 //               (-1,-1) is the lower-left corner.
 //
 //               Some lens types also set the z coordinate of the 2-d
-//               point to a value in the range (-1, 1), where 1
-//               represents a point on the near plane, and -1
+//               point to a value in the range (-1, 1), where -1
+//               represents a point on the near plane, and 1
 //               represents a point on the far plane.
 //
 //               Returns true if the 3-d point is in front of the lens
@@ -204,8 +204,8 @@ do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point
   point2d.set
     (y[0] * factor,
      y[1] * factor,
-     // Z is the distance scaled into the range 1 .. -1.
-     1.0 - 2.0 * z
+     // Z is the distance scaled into the range -1 .. 1.
+     2.0 * z - 1.0
      );
 
   // Now we have to transform the point according to the film

+ 4 - 4
panda/src/distort/oSphereLens.cxx

@@ -90,8 +90,8 @@ do_extrude(const Lens::CData *lens_cdata,
 //               (-1,-1) is the lower-left corner.
 //
 //               Some lens types also set the z coordinate of the 2-d
-//               point to a value in the range (-1, 1), where 1
-//               represents a point on the near plane, and -1
+//               point to a value in the range (-1, 1), where -1
+//               represents a point on the near plane, and 1
 //               represents a point on the far plane.
 //
 //               Returns true if the 3-d point is in front of the lens
@@ -126,8 +126,8 @@ do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point
      rad_2_deg(catan2(xy[0], xy[1])) * focal_length / ospherical_k,
      // The y position is the Z height.
      p[2],
-     // Z is the distance scaled into the range 1 .. -1.
-     1.0 - 2.0 * z
+     // Z is the distance scaled into the range -1 .. 1.
+     2.0 * z - 1.0
      );
 
   // Now we have to transform the point according to the film

+ 4 - 4
panda/src/distort/pSphereLens.cxx

@@ -83,8 +83,8 @@ do_extrude(const Lens::CData *lens_cdata,
 //               (-1,-1) is the lower-left corner.
 //
 //               Some lens types also set the z coordinate of the 2-d
-//               point to a value in the range (-1, 1), where 1
-//               represents a point on the near plane, and -1
+//               point to a value in the range (-1, 1), where -1
+//               represents a point on the near plane, and 1
 //               represents a point on the far plane.
 //
 //               Returns true if the 3-d point is in front of the lens
@@ -124,8 +124,8 @@ do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point
      rad_2_deg(catan2(xy[0], xy[1])) * focal_length / pspherical_k,
      // 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.
-     1.0 - 2.0 * z
+     // Z is the distance scaled into the range -1 .. 1.
+     2.0 * z - 1.0
      );
 
   // Now we have to transform the point according to the film

+ 7 - 3
panda/src/gobj/lens.cxx

@@ -1254,7 +1254,11 @@ do_extrude_depth(const CData *cdata,
                  const LPoint3 &point2d, LPoint3 &point3d) const {
   LPoint3 near_point, far_point;
   bool result = extrude(point2d, near_point, far_point);
-  point3d = near_point + (far_point - near_point) * point2d[2];
+
+  // The depth point is, by convention, in the range -1 to 1.  Scale
+  // this to 0 .. 1 for the linear interpolation.
+  PN_stdfloat t = point2d[2] * 0.5 + 0.5;
+  point3d = near_point + (far_point - near_point) * t;
   return result;
 }
 
@@ -1317,8 +1321,8 @@ do_extrude_vec(const CData *cdata, const LPoint3 &point2d, LVector3 &vec) const
 //               (-1,-1) is the lower-left corner.
 //
 //               The z coordinate will also be set to a value in the
-//               range (-1, 1), where 1 represents a point on the near
-//               plane, and -1 represents a point on the far plane.
+//               range (-1, 1), where -1 represents a point on the near
+//               plane, and 1 represents a point on the far plane.
 //
 //               Returns true if the 3-d point is in front of the lens
 //               and within the viewing frustum (in which case point2d

+ 2 - 2
panda/src/grutil/pfmVizzer.cxx

@@ -92,8 +92,8 @@ extrude(const Lens *lens) {
 
   static LMatrix4 from_uv(2.0, 0.0, 0.0, 0.0,
                           0.0, 2.0, 0.0, 0.0,
-                          0.0, 0.0, 1.0, 0.0,
-                          -1.0, -1.0, 0.0, 1.0);
+                          0.0, 0.0, 2.0, 0.0,
+                          -1.0, -1.0, -1.0, 1.0);
 
   PfmFile result;
   result.clear(_pfm.get_x_size(), _pfm.get_y_size(), 3);