15 #include "pandabase.h" 19 #include "mathNumbers.h" 21 #include "transformState.h" 22 #include "bamReader.h" 23 #include "bamWriter.h" 25 #include "datagramIterator.h" 32 operator << (ostream &out, Fog::Mode mode) {
35 return out <<
"linear";
37 case Fog::M_exponential:
38 return out <<
"exponential";
40 case Fog::M_exponential_squared:
41 return out <<
"exponential-squared";
44 return out <<
"**invalid**(" << (int)mode <<
")";
53 Fog(
const string &name) :
57 _color.set(1.0f, 1.0f, 1.0f, 1.0f);
58 _linear_onset_point.set(0.0f, 0.0f, 0.0f);
59 _linear_opaque_point.set(0.0f, 100.0f, 0.0f);
61 _linear_fallback_cosa = -1.0f;
62 _linear_fallback_onset = 0.0f;
63 _linear_fallback_opaque = 0.0f;
64 _transformed_onset = 0.0f;
65 _transformed_opaque = 0.0f;
74 Fog(
const Fog ©) :
79 _linear_onset_point = copy._linear_onset_point;
80 _linear_opaque_point = copy._linear_opaque_point;
81 _exp_density = copy._exp_density;
82 _linear_fallback_cosa = copy._linear_fallback_cosa;
83 _linear_fallback_onset = copy._linear_fallback_onset;
84 _linear_fallback_opaque = copy._linear_fallback_opaque;
85 _transformed_onset = copy._transformed_onset;
86 _transformed_opaque = copy._transformed_opaque;
108 return new Fog(*
this);
120 _linear_onset_point = _linear_onset_point * mat;
121 _linear_opaque_point = _linear_opaque_point * mat;
130 output(ostream &out)
const {
131 out <<
"fog: " << _mode;
134 out <<
"(" << _linear_onset_point <<
") -> (" 135 << _linear_opaque_point <<
")";
139 case M_exponential_squared:
158 LPoint3 onset_point, opaque_point;
164 CPT(TransformState) rel_transform =
165 camera_transform->invert_compose(this_np.get_net_transform());
167 const LMatrix4 &mat = rel_transform->get_mat();
170 LVector3 fog_vector = (_linear_opaque_point - _linear_onset_point) * mat;
172 PN_stdfloat cosa = fog_vector.dot(forward);
173 if (cabs(cosa) < _linear_fallback_cosa) {
176 _transformed_onset = _linear_fallback_onset;
177 _transformed_opaque = _linear_fallback_opaque;
180 _transformed_onset = forward.dot(_linear_onset_point * mat);
181 _transformed_opaque = forward.dot(_linear_opaque_point * mat);
186 _transformed_onset = forward.dot(_linear_onset_point);
187 _transformed_opaque = forward.dot(_linear_opaque_point);
198 onset = _transformed_onset;
199 opaque = _transformed_opaque;
247 parse_params(params, scan, manager);
248 node->fillin(scan, manager);
262 PandaNode::fillin(scan, manager);
void get_linear_range(PN_stdfloat &onset, PN_stdfloat &opaque)
Retrieves the current onset and offset ranges.
PN_int8 get_int8()
Extracts a signed 8-bit integer.
A basic node of the scene graph or data graph.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Fog.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
Base class for objects that can be written to and read from Bam files.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
void adjust_to_camera(const TransformState *camera_transform)
This function is intended to be called by the cull traverser to compute the appropriate camera-relati...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
static LVector3f forward(CoordinateSystem cs=CS_default)
Returns the forward vector for the given coordinate system.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
This is a 4-by-4 transform matrix.
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
Specifies how atmospheric fog effects are applied to geometry.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
int get_num_parents(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of parent nodes this node has.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
bool normalize()
Normalizes the vector in place.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...