Panda3D
ambientLight.cxx
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 ambientLight.cxx
10  * @author mike
11  * @date 1997-01-09
12  */
13 
14 #include "ambientLight.h"
15 #include "bamWriter.h"
16 #include "bamReader.h"
17 #include "datagram.h"
18 #include "datagramIterator.h"
19 
20 TypeHandle AmbientLight::_type_handle;
21 
22 /**
23  *
24  */
25 AmbientLight::
26 AmbientLight(const std::string &name) :
27  LightNode(name)
28 {
29 }
30 
31 /**
32  * Do not call the copy constructor directly; instead, use make_copy() or
33  * copy_subgraph() to make a copy of a node.
34  */
35 AmbientLight::
36 AmbientLight(const AmbientLight &copy) :
37  LightNode(copy)
38 {
39 }
40 
41 /**
42  * Returns the relative priority associated with all lights of this class.
43  * This priority is used to order lights whose instance priority
44  * (get_priority()) is the same--the idea is that other things being equal,
45  * AmbientLights (for instance) are less important than DirectionalLights.
46  */
49  return (int)CP_ambient_priority;
50 }
51 
52 /**
53  * Returns a newly-allocated PandaNode that is a shallow copy of this one. It
54  * will be a different pointer, but its internal data may or may not be shared
55  * with that of the original PandaNode. No children will be copied.
56  */
58 make_copy() const {
59  return new AmbientLight(*this);
60 }
61 
62 /**
63  *
64  */
65 void AmbientLight::
66 write(std::ostream &out, int indent_level) const {
67  indent(out, indent_level) << *this << ":\n";
68  indent(out, indent_level + 2)
69  << "color " << get_color() << "\n";
70 }
71 
72 /**
73  * Returns true if this is an AmbientLight, false if it is some other kind of
74  * light.
75  */
76 bool AmbientLight::
78  return true;
79 }
80 
81 /**
82  *
83  */
84 void AmbientLight::
85 bind(GraphicsStateGuardianBase *, const NodePath &, int) {
86  // AmbientLights aren't bound to light id's; this function should never be
87  // called.
88  nassert_raise("cannot bind AmbientLight");
89 }
90 
91 /**
92  * Tells the BamReader how to create objects of type AmbientLight.
93  */
94 void AmbientLight::
96  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
97 }
98 
99 /**
100  * Writes the contents of this object to the datagram for shipping out to a
101  * Bam file.
102  */
103 void AmbientLight::
105  LightNode::write_datagram(manager, dg);
106 }
107 
108 /**
109  * This function is called by the BamReader's factory when a new object of
110  * type AmbientLight is encountered in the Bam file. It should create the
111  * AmbientLight and extract its information from the file.
112  */
113 TypedWritable *AmbientLight::
114 make_from_bam(const FactoryParams &params) {
115  AmbientLight *node = new AmbientLight("");
116  DatagramIterator scan;
117  BamReader *manager;
118 
119  parse_params(params, scan, manager);
120  node->fillin(scan, manager);
121 
122  return node;
123 }
124 
125 /**
126  * This internal function is called by make_from_bam to read in all of the
127  * relevant data from the BamFile for the new AmbientLight.
128  */
129 void AmbientLight::
130 fillin(DatagramIterator &scan, BamReader *manager) {
131  LightNode::fillin(scan, manager);
132 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
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: lightNode.cxx:79
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A derivative of Light and of PandaNode.
Definition: lightNode.h:27
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual int get_class_priority() const
Returns the relative priority associated with all lights of this class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A light source that seems to illuminate all points in space at once.
Definition: ambientLight.h:26
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
static void register_with_read_factory()
Tells the BamReader how to create objects of type AmbientLight.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool is_ambient_light() const final
Returns true if this is an AmbientLight, false if it is some other kind of light.