Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/fog.h

Go to the documentation of this file.
00001 // Filename: fog.h
00002 // Created by:  drose (14Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef FOG_H
00020 #define FOG_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pandaNode.h"
00025 #include "luse.h"
00026 #include "cmath.h"
00027 #include "deg_2_rad.h"
00028 
00029 class TransformState;
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : Fog
00033 // Description : Specifies how atmospheric fog effects are applied to
00034 //               geometry.  The Fog object is now a PandaNode, which
00035 //               means it can be used similarly to a Light to define
00036 //               effects relative to a particular coordinate system
00037 //               within the scene graph.
00038 //
00039 //               In exponential mode, the fog effects are always
00040 //               camera-relative, and it does not matter where the Fog
00041 //               node is parented.  However, in linear mode, the onset
00042 //               and opaque distances are defined as offsets along the
00043 //               local forward axis (e.g. the Y axis).  This allows
00044 //               the fog effect to be localized to a particular region
00045 //               in space, rather than always camera-relative.  If the
00046 //               fog object is not parented to any node, it is used to
00047 //               generate traditonal camera-relative fog, as if it
00048 //               were parented to the camera.
00049 ////////////////////////////////////////////////////////////////////
00050 class EXPCL_PANDA Fog : public PandaNode {
00051 PUBLISHED:
00052   Fog(const string &name);
00053 
00054 protected:
00055   Fog(const Fog &copy);
00056 
00057 public:
00058   virtual ~Fog();
00059 
00060   virtual PandaNode *make_copy() const;
00061   virtual void xform(const LMatrix4f &mat);
00062 
00063 PUBLISHED:
00064   enum Mode {
00065     M_linear,                   // f = (end - z) / (end - start)
00066     M_exponential,              // f = e^(-density * z)
00067     M_exponential_squared       // f = e^((-density * z)^2)
00068   };
00069 
00070   INLINE Mode get_mode() const;
00071   INLINE void set_mode(Mode mode);
00072 
00073   INLINE const Colorf &get_color() const;
00074   INLINE void set_color(float r, float g, float b);
00075   INLINE void set_color(const Colorf &color);
00076 
00077   INLINE void set_linear_range(float onset, float opaque);
00078 
00079   INLINE const LPoint3f &get_linear_onset_point() const;
00080   INLINE void set_linear_onset_point(float x, float y, float z);
00081   INLINE void set_linear_onset_point(const LPoint3f &linear_onset_point);
00082 
00083   INLINE const LPoint3f &get_linear_opaque_point() const;
00084   INLINE void set_linear_opaque_point(const LPoint3f &linear_opaque_point);
00085   INLINE void set_linear_opaque_point(float x, float y, float z);
00086 
00087   INLINE void set_linear_fallback(float angle, float onset, float opaque);
00088 
00089   INLINE float get_exp_density() const;
00090   INLINE void set_exp_density(float exp_density);
00091 
00092   void output(ostream &out) const;
00093 
00094 public:
00095   void adjust_to_camera(const TransformState *camera_transform);
00096   void get_linear_range(float &onset, float &opaque);
00097 
00098 protected:
00099   void compute_density();
00100 
00101 public:
00102   static void register_with_read_factory();
00103   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00104 
00105 protected:
00106   static TypedWritable *make_from_bam(const FactoryParams &params);
00107   void fillin(DatagramIterator &scan, BamReader *manager);
00108 
00109 protected:
00110   Mode _mode;
00111   Colorf _color;
00112   LPoint3f _linear_onset_point;
00113   LPoint3f _linear_opaque_point;
00114   float _exp_density;
00115 
00116   float _linear_fallback_cosa;
00117   float _linear_fallback_onset, _linear_fallback_opaque;
00118   
00119   float _transformed_onset, _transformed_opaque;
00120 
00121 public:
00122   static TypeHandle get_class_type() {
00123     return _type_handle;
00124   }
00125   static void init_type() {
00126     PandaNode::init_type();
00127     register_type(_type_handle, "Fog",
00128                   PandaNode::get_class_type());
00129   }
00130   virtual TypeHandle get_type() const {
00131     return get_class_type();
00132   }
00133   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00134 
00135 private:
00136   static TypeHandle _type_handle;
00137 };
00138 
00139 EXPCL_PANDA ostream &operator << (ostream &out, Fog::Mode mode);
00140 
00141 INLINE ostream &operator << (ostream &out, const Fog &fog) {
00142   fog.output(out);
00143   return out;
00144 }
00145 
00146 #include "fog.I"
00147 
00148 #endif

Generated on Fri May 2 00:41:38 2003 for Panda by doxygen1.3