Panda3D
fog.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fog.h
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 #ifndef FOG_H
15 #define FOG_H
16 
17 #include "pandabase.h"
18 
19 #include "pandaNode.h"
20 #include "luse.h"
21 #include "cmath.h"
22 #include "deg_2_rad.h"
23 
24 class TransformState;
25 
26 /**
27  * Specifies how atmospheric fog effects are applied to geometry. The Fog
28  * object is now a PandaNode, which means it can be used similarly to a Light
29  * to define effects relative to a particular coordinate system within the
30  * scene graph.
31  *
32  * In exponential mode, the fog effects are always camera-relative, and it
33  * does not matter where the Fog node is parented. However, in linear mode,
34  * the onset and opaque distances are defined as offsets along the local
35  * forward axis (e.g. the Y axis). This allows the fog effect to be
36  * localized to a particular region in space, rather than always camera-
37  * relative. If the fog object is not parented to any node, it is used to
38  * generate traditonal camera-relative fog, as if it were parented to the
39  * camera.
40  */
41 class EXPCL_PANDA_PGRAPH Fog : public PandaNode {
42 PUBLISHED:
43  explicit Fog(const std::string &name);
44 
45 protected:
46  Fog(const Fog &copy);
47 
48 public:
49  virtual ~Fog();
50 
51  virtual PandaNode *make_copy() const;
52  virtual void xform(const LMatrix4 &mat);
53 
54 PUBLISHED:
55  enum Mode {
56  M_linear, // f = (end - z) / (end - start)
57  M_exponential, // f = e^(-density * z)
58  M_exponential_squared // f = e^((-density * z)^2)
59  };
60 
61  INLINE Mode get_mode() const;
62  INLINE void set_mode(Mode mode);
63  MAKE_PROPERTY(mode, get_mode, set_mode);
64 
65  INLINE const LColor &get_color() const;
66  INLINE void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b);
67  INLINE void set_color(const LColor &color);
68  MAKE_PROPERTY(color, get_color, set_color);
69 
70  INLINE void set_linear_range(PN_stdfloat onset, PN_stdfloat opaque);
71 
72  INLINE const LPoint3 &get_linear_onset_point() const;
73  INLINE void set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
74  INLINE void set_linear_onset_point(const LPoint3 &linear_onset_point);
75  MAKE_PROPERTY(linear_onset_point, get_linear_onset_point, set_linear_onset_point);
76 
77  INLINE const LPoint3 &get_linear_opaque_point() const;
78  INLINE void set_linear_opaque_point(const LPoint3 &linear_opaque_point);
79  INLINE void set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
80  MAKE_PROPERTY(linear_opaque_point, get_linear_opaque_point, set_linear_opaque_point);
81 
82  INLINE void set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque);
83 
84  INLINE PN_stdfloat get_exp_density() const;
85  INLINE void set_exp_density(PN_stdfloat exp_density);
86  MAKE_PROPERTY(exp_density, get_exp_density, set_exp_density);
87 
88  void output(std::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 std::ostream &operator << (std::ostream &out, Fog::Mode mode);
136 
137 INLINE std::ostream &operator << (std::ostream &out, const Fog &fog) {
138  fog.output(out);
139  return out;
140 }
141 
142 #include "fog.I"
143 
144 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Indicates a coordinate-system transform on vertices.
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:3589
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:3580
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:310
Specifies how atmospheric fog effects are applied to geometry.
Definition: fog.h:41
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:487
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38