Panda3D
fog.h
1 // Filename: fog.h
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 #ifndef FOG_H
16 #define FOG_H
17 
18 #include "pandabase.h"
19 
20 #include "pandaNode.h"
21 #include "luse.h"
22 #include "cmath.h"
23 #include "deg_2_rad.h"
24 
25 class TransformState;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : Fog
29 // Description : Specifies how atmospheric fog effects are applied to
30 // geometry. The Fog object is now a PandaNode, which
31 // means it can be used similarly to a Light to define
32 // effects relative to a particular coordinate system
33 // within the scene graph.
34 //
35 // In exponential mode, the fog effects are always
36 // camera-relative, and it does not matter where the Fog
37 // node is parented. However, in linear mode, the onset
38 // and opaque distances are defined as offsets along the
39 // local forward axis (e.g. the Y axis). This allows
40 // the fog effect to be localized to a particular region
41 // in space, rather than always camera-relative. If the
42 // fog object is not parented to any node, it is used to
43 // generate traditonal camera-relative fog, as if it
44 // were parented to the camera.
45 ////////////////////////////////////////////////////////////////////
46 class EXPCL_PANDA_PGRAPH Fog : public PandaNode {
47 PUBLISHED:
48  Fog(const string &name);
49 
50 protected:
51  Fog(const Fog &copy);
52 
53 public:
54  virtual ~Fog();
55 
56  virtual PandaNode *make_copy() const;
57  virtual void xform(const LMatrix4 &mat);
58 
59 PUBLISHED:
60  enum Mode {
61  M_linear, // f = (end - z) / (end - start)
62  M_exponential, // f = e^(-density * z)
63  M_exponential_squared // f = e^((-density * z)^2)
64  };
65 
66  INLINE Mode get_mode() const;
67  INLINE void set_mode(Mode mode);
68 
69  INLINE const LColor &get_color() const;
70  INLINE void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b);
71  INLINE void set_color(const LColor &color);
72 
73  INLINE void set_linear_range(PN_stdfloat onset, PN_stdfloat opaque);
74 
75  INLINE const LPoint3 &get_linear_onset_point() const;
76  INLINE void set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
77  INLINE void set_linear_onset_point(const LPoint3 &linear_onset_point);
78 
79  INLINE const LPoint3 &get_linear_opaque_point() const;
80  INLINE void set_linear_opaque_point(const LPoint3 &linear_opaque_point);
81  INLINE void set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
82 
83  INLINE void set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque);
84 
85  INLINE PN_stdfloat get_exp_density() const;
86  INLINE void set_exp_density(PN_stdfloat exp_density);
87 
88  void output(ostream &out) const;
89 
90 public:
91  void adjust_to_camera(const TransformState *camera_transform);
92  void get_linear_range(PN_stdfloat &onset, PN_stdfloat &opaque);
93 
94 protected:
95  void compute_density();
96 
97 public:
98  static void register_with_read_factory();
99  virtual void write_datagram(BamWriter *manager, Datagram &dg);
100 
101 protected:
102  static TypedWritable *make_from_bam(const FactoryParams &params);
103  void fillin(DatagramIterator &scan, BamReader *manager);
104 
105 protected:
106  Mode _mode;
107  LColor _color;
108  LPoint3 _linear_onset_point;
109  LPoint3 _linear_opaque_point;
110  PN_stdfloat _exp_density;
111 
112  PN_stdfloat _linear_fallback_cosa;
113  PN_stdfloat _linear_fallback_onset, _linear_fallback_opaque;
114 
115  PN_stdfloat _transformed_onset, _transformed_opaque;
116 
117 public:
118  static TypeHandle get_class_type() {
119  return _type_handle;
120  }
121  static void init_type() {
122  PandaNode::init_type();
123  register_type(_type_handle, "Fog",
124  PandaNode::get_class_type());
125  }
126  virtual TypeHandle get_type() const {
127  return get_class_type();
128  }
129  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
130 
131 private:
132  static TypeHandle _type_handle;
133 };
134 
135 EXPCL_PANDA_PGRAPH ostream &operator << (ostream &out, Fog::Mode mode);
136 
137 INLINE ostream &operator << (ostream &out, const Fog &fog) {
138  fog.output(out);
139  return out;
140 }
141 
142 #include "fog.I"
143 
144 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:4164
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so...
Definition: pandaNode.cxx:377
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
Specifies how atmospheric fog effects are applied to geometry.
Definition: fog.h:46
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43