Browse Source

add project()

David Rose 14 years ago
parent
commit
5cbc418073
2 changed files with 36 additions and 0 deletions
  1. 34 0
      panda/src/grutil/pfmFile.cxx
  2. 2 0
      panda/src/grutil/pfmFile.h

+ 34 - 0
panda/src/grutil/pfmFile.cxx

@@ -26,6 +26,7 @@
 #include "geomPoints.h"
 #include "geomPoints.h"
 #include "geomTriangles.h"
 #include "geomTriangles.h"
 #include "geomVertexWriter.h"
 #include "geomVertexWriter.h"
+#include "lens.h"
 #include "look_at.h"
 #include "look_at.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -524,6 +525,39 @@ xform(const LMatrix4 &transform) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::project
+//       Access: Published
+//  Description: Adjusts each (x, y, z) point of the Pfm file by
+//               projecting it through the indicated lens, converting
+//               each point to a (u, v, 0) texture coordinate.  The
+//               resulting file can be generated to a mesh (with
+//               set_vis_inverse(true) and generate_vis_mesh(true))
+//               that will apply the lens distortion to an arbitrary
+//               texture image.
+////////////////////////////////////////////////////////////////////
+void PfmFile::
+project(const Lens *lens) {
+  nassertv(is_valid());
+
+  static LMatrix4 to_uv(0.5, 0.0, 0.0, 0.0,
+                        0.0, 0.5, 0.0, 0.0, 
+                        0.0, 0.0, 0.0, 0.0, 
+                        0.5, 0.5, 0.0, 1.0);
+  
+  Table::iterator ti;
+  for (ti = _table.begin(); ti != _table.end(); ++ti) {
+    if (_zero_special && (*ti) == LPoint3::zero()) {
+      continue;
+    }
+
+    LPoint3 &p = (*ti);
+    LPoint3 film;
+    lens->project(p, film);
+    p = to_uv.xform_point(film);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::compute_planar_bounds
 //     Function: PfmFile::compute_planar_bounds
 //       Access: Published
 //       Access: Published

+ 2 - 0
panda/src/grutil/pfmFile.h

@@ -21,6 +21,7 @@
 #include "boundingHexahedron.h"
 #include "boundingHexahedron.h"
 
 
 class GeomNode;
 class GeomNode;
+class Lens;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : PfmFile
 //       Class : PfmFile
@@ -62,6 +63,7 @@ PUBLISHED:
   void resize(int new_x_size, int new_y_size);
   void resize(int new_x_size, int new_y_size);
   void reverse_rows();
   void reverse_rows();
   void xform(const LMatrix4 &transform);
   void xform(const LMatrix4 &transform);
+  void project(const Lens *lens);
 
 
   PT(BoundingHexahedron) compute_planar_bounds(double point_dist, double sample_radius) const;
   PT(BoundingHexahedron) compute_planar_bounds(double point_dist, double sample_radius) const;