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

panda/src/pgraph/fog.I

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

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