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