Panda3D
|
00001 // Filename: fog.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: Fog::get_mode 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE Fog::Mode Fog:: 00022 get_mode() const { 00023 return _mode; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: Fog::set_mode 00028 // Access: Published 00029 // Description: Specifies the computation that is used to determine 00030 // the fog effect. If this is M_linear, then the fog 00031 // will range from linearly from the onset point to the 00032 // opaque point (or for the distances specified in 00033 // set_linear_range), and the fog object should be 00034 // parented into the scene graph, or to the camera. 00035 // 00036 // If this is anything else, the onset point and opaque 00037 // point are not used, and the fog effect is based on 00038 // the value specified to set_exp_density(), and it 00039 // doesn't matter to which node the fog object is 00040 // parented, or if it is parented anywhere at all. 00041 //////////////////////////////////////////////////////////////////// 00042 INLINE void Fog:: 00043 set_mode(Mode mode) { 00044 _mode = mode; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: Fog::get_color 00049 // Access: Published 00050 // Description: Returns the color of the fog. 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE const LColor &Fog:: 00053 get_color() const { 00054 return _color; 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: Fog::set_color 00059 // Access: Published 00060 // Description: Sets the color of the fog. 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE void Fog:: 00063 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) { 00064 _color[0] = r; 00065 _color[1] = g; 00066 _color[2] = b; 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: Fog::set_color 00071 // Access: Published 00072 // Description: Sets the color of the fog. The alpha component is 00073 // not used. 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE void Fog:: 00076 set_color(const LColor &color) { 00077 _color = color; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: Fog::set_linear_range 00082 // Access: Published 00083 // Description: Specifies the effects of the fog in linear distance 00084 // units. This is only used if the mode is M_linear. 00085 // 00086 // This specifies a fog that begins at distance onset 00087 // units from the origin, and becomes totally opaque at 00088 // distance opaque units from the origin, along the 00089 // forward axis (usually Y). 00090 // 00091 // This function also implicitly sets the mode the 00092 // M_linear, if it is not already set. 00093 //////////////////////////////////////////////////////////////////// 00094 INLINE void Fog:: 00095 set_linear_range(PN_stdfloat onset, PN_stdfloat opaque) { 00096 LVector3 forward = LVector3::forward(); 00097 _linear_onset_point = onset * forward; 00098 _linear_opaque_point = opaque * forward; 00099 _transformed_onset = onset; 00100 _transformed_opaque = opaque; 00101 _mode = M_linear; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: Fog::get_linear_onset_point 00106 // Access: Published 00107 // Description: Returns the point in space at which the fog begins. 00108 // This is only used if the mode is M_linear. 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE const LPoint3 &Fog:: 00111 get_linear_onset_point() const { 00112 return _linear_onset_point; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: Fog::set_linear_onset_point 00117 // Access: Published 00118 // Description: Specifies the point in space at which the fog begins. 00119 // This is only used if the mode is M_linear. 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE void Fog:: 00122 set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00123 _linear_onset_point.set(x, y, z); 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: Fog::set_linear_onset_point 00128 // Access: Published 00129 // Description: Specifies the point in space at which the fog begins. 00130 // This is only used if the mode is M_linear. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE void Fog:: 00133 set_linear_onset_point(const LPoint3 &linear_onset_point) { 00134 _linear_onset_point = linear_onset_point; 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: Fog::get_linear_opaque_point 00139 // Access: Published 00140 // Description: Returns the point in space at which the fog 00141 // completely obscures geometry. This is only used if 00142 // the mode is M_linear. 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE const LPoint3 &Fog:: 00145 get_linear_opaque_point() const { 00146 return _linear_opaque_point; 00147 } 00148 00149 //////////////////////////////////////////////////////////////////// 00150 // Function: Fog::set_linear_opaque_point 00151 // Access: Published 00152 // Description: Specifies the point in space at which the fog 00153 // completely obscures geometry. This is only used if 00154 // the mode is M_linear. 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE void Fog:: 00157 set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00158 _linear_opaque_point.set(x, y, z); 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: Fog::set_linear_opaque_point 00163 // Access: Published 00164 // Description: Specifies the point in space at which the fog 00165 // completely obscures geometry. This is only used if 00166 // the mode is M_linear. 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE void Fog:: 00169 set_linear_opaque_point(const LPoint3 &linear_opaque_point) { 00170 _linear_opaque_point = linear_opaque_point; 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: Fog::set_linear_fallback 00175 // Access: Published 00176 // Description: Fog effects are traditionally defined in 00177 // camera-relative space, but the Panda Fog node has a 00178 // special mode in which it can define a linear fog 00179 // effect in an arbitrary coordinate space. 00180 // 00181 // This is done by specifying 3-d onset and opaque 00182 // points, and parenting the Fog object somewhere within 00183 // the scene graph. In this mode, the fog will be 00184 // rendered as if it extended along the vector from the 00185 // onset point to the opaque point, in 3-d space. 00186 // 00187 // However, the underlying fog effect supported by 00188 // hardware is generally only one-dimensional, and must 00189 // be rendered based on linear distance from the camera 00190 // plane. Thus, this in-the-world effect is most 00191 // effective when the fog vector from onset point to 00192 // opaque point is most nearly parallel to the camera's 00193 // eye vector. 00194 // 00195 // As the angle between the fog vector and the eye 00196 // vector increases, the accuracy of the effect 00197 // diminishes, up to a complete breakdown of the effect 00198 // at a 90 degree angle. 00199 // 00200 // This function exists to define the workaround to this 00201 // problem. The linear fallback parameters given here 00202 // specify how the fog should be rendered when the 00203 // parameters are exceeded in this way. 00204 // 00205 // The angle parameter is the minimum angle, in degrees, 00206 // of the fog vector to the eye vector, at which the 00207 // fallback effect should be employed. The onset and 00208 // opaque parameters specify the camera-relative onset 00209 // and opaque distances to pass to the rendering 00210 // hardware when employing the fallback effect. This 00211 // supercedes the 3-d onset point and opaque points. 00212 //////////////////////////////////////////////////////////////////// 00213 INLINE void Fog:: 00214 set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque) { 00215 _linear_fallback_cosa = ccos(deg_2_rad(angle)); 00216 _linear_fallback_onset = onset; 00217 _linear_fallback_opaque = opaque; 00218 } 00219 00220 //////////////////////////////////////////////////////////////////// 00221 // Function: Fog::get_exp_density 00222 // Access: Published 00223 // Description: Returns the density of the fog for exponential 00224 // calculations. This is only used if the mode is not 00225 // M_linear. 00226 //////////////////////////////////////////////////////////////////// 00227 INLINE PN_stdfloat Fog:: 00228 get_exp_density() const { 00229 return _exp_density; 00230 } 00231 00232 //////////////////////////////////////////////////////////////////// 00233 // Function: Fog::set_exp_density 00234 // Access: Published 00235 // Description: Sets the density of the fog for exponential 00236 // calculations. This is only used if the mode is not 00237 // M_linear. 00238 // 00239 // If the mode is currently set to M_linear, this 00240 // function implicitly sets it to M_exponential. 00241 //////////////////////////////////////////////////////////////////// 00242 INLINE void Fog:: 00243 set_exp_density(PN_stdfloat exp_density) { 00244 nassertv((exp_density >= 0.0) && (exp_density <= 1.0)); 00245 _exp_density = exp_density; 00246 00247 if (_mode == M_linear) { 00248 _mode = M_exponential; 00249 } 00250 }