Browse Source

add set_reflection()

David Rose 20 years ago
parent
commit
60c571f684

+ 12 - 11
direct/src/showbase/ShowBase.py

@@ -1574,7 +1574,7 @@ class ShowBase(DirectObject.DirectObject):
 
         return saved
 
-    def saveCubemap(self, namePrefix = 'cubemap_#.png',
+    def saveCubeMap(self, namePrefix = 'cube_map_#.png',
                     defaultFilename = 0, source = None,
                     camera = None, size = 128,
                     cameraMask = BitMask32.allOn()):
@@ -1627,22 +1627,22 @@ class ShowBase(DirectObject.DirectObject):
 
         return saved
 
-    def saveSpheremap(self, namePrefix = 'spheremap.png',
+    def saveSphereMap(self, namePrefix = 'spheremap.png',
                       defaultFilename = 0, source = None,
                       camera = None, size = 256,
                       cameraMask = BitMask32.allOn(),
                       numVertices = 1000):
 
-        """ This works much like saveCubemap(), and uses the graphics
-        API's hardware cubemapping ability to get a 360-degree view of
-        the world.  But then it converts the six cubemap faces into a
-        single fisheye texture, suitable for applying as a static
-        environment map (sphere map).
+        """ This works much like saveCubeMap(), and uses the graphics
+        API's hardware cube-mapping ability to get a 360-degree view
+        of the world.  But then it converts the six cube map faces
+        into a single fisheye texture, suitable for applying as a
+        static environment map (sphere map).
 
-        For static environment maps, sphere maps are often preferable
-        to static cube maps because they require only a single texture
-        and because they are supported on a broader range of hardware.
-        """
+        For eye-relative static environment maps, sphere maps are
+        often preferable to cube maps because they require only a
+        single texture and because they are supported on a broader
+        range of hardware.  """
 
         if source == None:
             source = base.win
@@ -1688,6 +1688,7 @@ class ShowBase(DirectObject.DirectObject):
         fm = FisheyeMaker('card')
         fm.setNumVertices(numVertices)
         fm.setSquareInscribed(1, 1.1)
+        fm.setReflection(1)
         card = root.attachNewNode(fm.generate())
         card.setTexture(buffer.getTexture())
         

+ 16 - 1
panda/src/grutil/fisheyeMaker.I

@@ -69,6 +69,21 @@ set_num_vertices(int num_vertices) {
 ////////////////////////////////////////////////////////////////////
 INLINE void FisheyeMaker::
 set_square_inscribed(bool square_inscribed, float square_radius) {
-  _square_inscribed = true;
+  _square_inscribed = square_inscribed;
   _square_radius = square_radius;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: FisheyeMaker::set_reflection
+//       Access: Public
+//  Description: Sets the flag indicating whether the texture image
+//               should be mirrored (true) or normal (false).  When
+//               this is true, the 3-D texture coordinates will be
+//               reversed so that the image is appropriate for a
+//               reflection.  This is the best choice for generating a
+//               sphere map from a cube map.  The default is false.
+////////////////////////////////////////////////////////////////////
+INLINE void FisheyeMaker::
+set_reflection(bool reflection) {
+  _reflect = (reflection) ? -1.0 : 1.0;
+}

+ 4 - 3
panda/src/grutil/fisheyeMaker.cxx

@@ -40,6 +40,7 @@ reset() {
   _num_vertices = 1000;
   _square_inscribed = false;
   _square_radius = 1.0f;
+  set_reflection(false);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -363,12 +364,12 @@ add_vertex(GeomVertexWriter &vertex, GeomVertexWriter &texcoord,
   if (b >= MathNumbers::pi_f) {
     // Special case: we want to stop at the back pole, not continue
     // around it.
-    texcoord.add_data3f(0, -1, 0);
+    texcoord.add_data3f(0, _reflect, 0);
 
   } else {
     float sinb, cosb;
     csincos(b, &sinb, &cosb);
-    LPoint3f tc(sinb * cosa, cosb, sinb * sina);
+    LPoint3f tc(sinb * cosa, cosb * _reflect, sinb * sina);
     texcoord.add_data3f(tc);
   }
 }
@@ -405,6 +406,6 @@ add_square_vertex(GeomVertexWriter &vertex, GeomVertexWriter &texcoord,
     vertex.add_data3f(point);
   }
 
-  texcoord.add_data3f(0, -1, 0);
+  texcoord.add_data3f(0, _reflect, 0);
 }
   

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

@@ -49,6 +49,7 @@ PUBLISHED:
   void set_fov(float fov);
   INLINE void set_num_vertices(int num_vertices);
   INLINE void set_square_inscribed(bool square_inscribed, float square_radius);
+  INLINE void set_reflection(bool reflection);
 
   PT(PandaNode) generate();
 
@@ -64,6 +65,7 @@ private:
   int _num_vertices;
   bool _square_inscribed;
   float _square_radius;
+  float _reflect;
 };
 
 #include "fisheyeMaker.I"