Panda3D
 All Classes Functions Variables Enumerations
fog.I
1 // Filename: fog.I
2 // Created by: drose (14Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: Fog::get_mode
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE Fog::Mode Fog::
22 get_mode() const {
23  return _mode;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: Fog::set_mode
28 // Access: Published
29 // Description: Specifies the computation that is used to determine
30 // the fog effect. If this is M_linear, then the fog
31 // will range from linearly from the onset point to the
32 // opaque point (or for the distances specified in
33 // set_linear_range), and the fog object should be
34 // parented into the scene graph, or to the camera.
35 //
36 // If this is anything else, the onset point and opaque
37 // point are not used, and the fog effect is based on
38 // the value specified to set_exp_density(), and it
39 // doesn't matter to which node the fog object is
40 // parented, or if it is parented anywhere at all.
41 ////////////////////////////////////////////////////////////////////
42 INLINE void Fog::
43 set_mode(Mode mode) {
44  _mode = mode;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: Fog::get_color
49 // Access: Published
50 // Description: Returns the color of the fog.
51 ////////////////////////////////////////////////////////////////////
52 INLINE const LColor &Fog::
53 get_color() const {
54  return _color;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: Fog::set_color
59 // Access: Published
60 // Description: Sets the color of the fog.
61 ////////////////////////////////////////////////////////////////////
62 INLINE void Fog::
63 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) {
64  _color[0] = r;
65  _color[1] = g;
66  _color[2] = b;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: Fog::set_color
71 // Access: Published
72 // Description: Sets the color of the fog. The alpha component is
73 // not used.
74 ////////////////////////////////////////////////////////////////////
75 INLINE void Fog::
77  _color = color;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: Fog::set_linear_range
82 // Access: Published
83 // Description: Specifies the effects of the fog in linear distance
84 // units. This is only used if the mode is M_linear.
85 //
86 // This specifies a fog that begins at distance onset
87 // units from the origin, and becomes totally opaque at
88 // distance opaque units from the origin, along the
89 // forward axis (usually Y).
90 //
91 // This function also implicitly sets the mode the
92 // M_linear, if it is not already set.
93 ////////////////////////////////////////////////////////////////////
94 INLINE void Fog::
95 set_linear_range(PN_stdfloat onset, PN_stdfloat opaque) {
96  LVector3 forward = LVector3::forward();
97  _linear_onset_point = onset * forward;
98  _linear_opaque_point = opaque * forward;
99  _transformed_onset = onset;
100  _transformed_opaque = opaque;
101  _mode = M_linear;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: Fog::get_linear_onset_point
106 // Access: Published
107 // Description: Returns the point in space at which the fog begins.
108 // This is only used if the mode is M_linear.
109 ////////////////////////////////////////////////////////////////////
110 INLINE const LPoint3 &Fog::
112  return _linear_onset_point;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: Fog::set_linear_onset_point
117 // Access: Published
118 // Description: Specifies the point in space at which the fog begins.
119 // This is only used if the mode is M_linear.
120 ////////////////////////////////////////////////////////////////////
121 INLINE void Fog::
122 set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
123  _linear_onset_point.set(x, y, z);
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: Fog::set_linear_onset_point
128 // Access: Published
129 // Description: Specifies the point in space at which the fog begins.
130 // This is only used if the mode is M_linear.
131 ////////////////////////////////////////////////////////////////////
132 INLINE void Fog::
133 set_linear_onset_point(const LPoint3 &linear_onset_point) {
134  _linear_onset_point = linear_onset_point;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: Fog::get_linear_opaque_point
139 // Access: Published
140 // Description: Returns the point in space at which the fog
141 // completely obscures geometry. This is only used if
142 // the mode is M_linear.
143 ////////////////////////////////////////////////////////////////////
144 INLINE const LPoint3 &Fog::
146  return _linear_opaque_point;
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: Fog::set_linear_opaque_point
151 // Access: Published
152 // Description: Specifies the point in space at which the fog
153 // completely obscures geometry. This is only used if
154 // the mode is M_linear.
155 ////////////////////////////////////////////////////////////////////
156 INLINE void Fog::
157 set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
158  _linear_opaque_point.set(x, y, z);
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: Fog::set_linear_opaque_point
163 // Access: Published
164 // Description: Specifies the point in space at which the fog
165 // completely obscures geometry. This is only used if
166 // the mode is M_linear.
167 ////////////////////////////////////////////////////////////////////
168 INLINE void Fog::
169 set_linear_opaque_point(const LPoint3 &linear_opaque_point) {
170  _linear_opaque_point = linear_opaque_point;
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: Fog::set_linear_fallback
175 // Access: Published
176 // Description: Fog effects are traditionally defined in
177 // camera-relative space, but the Panda Fog node has a
178 // special mode in which it can define a linear fog
179 // effect in an arbitrary coordinate space.
180 //
181 // This is done by specifying 3-d onset and opaque
182 // points, and parenting the Fog object somewhere within
183 // the scene graph. In this mode, the fog will be
184 // rendered as if it extended along the vector from the
185 // onset point to the opaque point, in 3-d space.
186 //
187 // However, the underlying fog effect supported by
188 // hardware is generally only one-dimensional, and must
189 // be rendered based on linear distance from the camera
190 // plane. Thus, this in-the-world effect is most
191 // effective when the fog vector from onset point to
192 // opaque point is most nearly parallel to the camera's
193 // eye vector.
194 //
195 // As the angle between the fog vector and the eye
196 // vector increases, the accuracy of the effect
197 // diminishes, up to a complete breakdown of the effect
198 // at a 90 degree angle.
199 //
200 // This function exists to define the workaround to this
201 // problem. The linear fallback parameters given here
202 // specify how the fog should be rendered when the
203 // parameters are exceeded in this way.
204 //
205 // The angle parameter is the minimum angle, in degrees,
206 // of the fog vector to the eye vector, at which the
207 // fallback effect should be employed. The onset and
208 // opaque parameters specify the camera-relative onset
209 // and opaque distances to pass to the rendering
210 // hardware when employing the fallback effect. This
211 // supercedes the 3-d onset point and opaque points.
212 ////////////////////////////////////////////////////////////////////
213 INLINE void Fog::
214 set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque) {
215  _linear_fallback_cosa = ccos(deg_2_rad(angle));
216  _linear_fallback_onset = onset;
217  _linear_fallback_opaque = opaque;
218 }
219 
220 ////////////////////////////////////////////////////////////////////
221 // Function: Fog::get_exp_density
222 // Access: Published
223 // Description: Returns the density of the fog for exponential
224 // calculations. This is only used if the mode is not
225 // M_linear.
226 ////////////////////////////////////////////////////////////////////
227 INLINE PN_stdfloat Fog::
229  return _exp_density;
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: Fog::set_exp_density
234 // Access: Published
235 // Description: Sets the density of the fog for exponential
236 // calculations. This is only used if the mode is not
237 // M_linear.
238 //
239 // If the mode is currently set to M_linear, this
240 // function implicitly sets it to M_exponential.
241 ////////////////////////////////////////////////////////////////////
242 INLINE void Fog::
243 set_exp_density(PN_stdfloat exp_density) {
244  nassertv((exp_density >= 0.0) && (exp_density <= 1.0));
245  _exp_density = exp_density;
246 
247  if (_mode == M_linear) {
248  _mode = M_exponential;
249  }
250 }
PN_stdfloat get_exp_density() const
Returns the density of the fog for exponential calculations.
Definition: fog.I:228
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b)
Sets the color of the fog.
Definition: fog.I:63
void set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque)
Fog effects are traditionally defined in camera-relative space, but the Panda Fog node has a special ...
Definition: fog.I:214
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
void set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Specifies the point in space at which the fog begins.
Definition: fog.I:122
void set_linear_opaque_point(const LPoint3 &linear_opaque_point)
Specifies the point in space at which the fog completely obscures geometry.
Definition: fog.I:169
static LVector3f forward(CoordinateSystem cs=CS_default)
Returns the forward vector for the given coordinate system.
Definition: lvector3.h:565
const LColor & get_color() const
Returns the color of the fog.
Definition: fog.I:53
void set_mode(Mode mode)
Specifies the computation that is used to determine the fog effect.
Definition: fog.I:43
void set_linear_range(PN_stdfloat onset, PN_stdfloat opaque)
Specifies the effects of the fog in linear distance units.
Definition: fog.I:95
const LPoint3 & get_linear_opaque_point() const
Returns the point in space at which the fog completely obscures geometry.
Definition: fog.I:145
void set_exp_density(PN_stdfloat exp_density)
Sets the density of the fog for exponential calculations.
Definition: fog.I:243
const LPoint3 & get_linear_onset_point() const
Returns the point in space at which the fog begins.
Definition: fog.I:111
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111