Panda3D
ambientLight.cxx
1 // Filename: ambientLight.cxx
2 // Created by: mike (09Jan97)
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 #include "ambientLight.h"
16 #include "bamWriter.h"
17 #include "bamReader.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 TypeHandle AmbientLight::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: AmbientLight::Constructor
25 // Access: Published
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 AmbientLight::
29 AmbientLight(const string &name) :
30  LightNode(name)
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: AmbientLight::Copy Constructor
36 // Access: Protected
37 // Description: Do not call the copy constructor directly; instead,
38 // use make_copy() or copy_subgraph() to make a copy of
39 // a node.
40 ////////////////////////////////////////////////////////////////////
41 AmbientLight::
42 AmbientLight(const AmbientLight &copy) :
43  LightNode(copy)
44 {
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: AmbientLight::get_class_priority
49 // Access: Published, Virtual
50 // Description: Returns the relative priority associated with all
51 // lights of this class. This priority is used to order
52 // lights whose instance priority (get_priority()) is
53 // the same--the idea is that other things being equal,
54 // AmbientLights (for instance) are less important than
55 // DirectionalLights.
56 ////////////////////////////////////////////////////////////////////
59  return (int)CP_ambient_priority;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: AmbientLight::make_copy
64 // Access: Public, Virtual
65 // Description: Returns a newly-allocated PandaNode that is a shallow
66 // copy of this one. It will be a different pointer,
67 // but its internal data may or may not be shared with
68 // that of the original PandaNode. No children will be
69 // copied.
70 ////////////////////////////////////////////////////////////////////
72 make_copy() const {
73  return new AmbientLight(*this);
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: AmbientLight::write
78 // Access: Public, Virtual
79 // Description:
80 ////////////////////////////////////////////////////////////////////
81 void AmbientLight::
82 write(ostream &out, int indent_level) const {
83  indent(out, indent_level) << *this << ":\n";
84  indent(out, indent_level + 2)
85  << "color " << get_color() << "\n";
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: AmbientLight::is_ambient_light
90 // Access: Published, Virtual
91 // Description: Returns true if this is an AmbientLight, false if it
92 // is some other kind of light.
93 ////////////////////////////////////////////////////////////////////
94 bool AmbientLight::
96  return true;
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: AmbientLight::bind
101 // Access: Public, Virtual
102 // Description:
103 ////////////////////////////////////////////////////////////////////
104 void AmbientLight::
105 bind(GraphicsStateGuardianBase *, const NodePath &, int) {
106  // AmbientLights aren't bound to light id's; this function should
107  // never be called.
108  nassertv(false);
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: AmbientLight::register_with_read_factory
113 // Access: Public, Static
114 // Description: Tells the BamReader how to create objects of type
115 // AmbientLight.
116 ////////////////////////////////////////////////////////////////////
117 void AmbientLight::
119  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: AmbientLight::write_datagram
124 // Access: Public, Virtual
125 // Description: Writes the contents of this object to the datagram
126 // for shipping out to a Bam file.
127 ////////////////////////////////////////////////////////////////////
128 void AmbientLight::
130  LightNode::write_datagram(manager, dg);
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: AmbientLight::make_from_bam
135 // Access: Protected, Static
136 // Description: This function is called by the BamReader's factory
137 // when a new object of type AmbientLight is encountered
138 // in the Bam file. It should create the AmbientLight
139 // and extract its information from the file.
140 ////////////////////////////////////////////////////////////////////
141 TypedWritable *AmbientLight::
142 make_from_bam(const FactoryParams &params) {
143  AmbientLight *node = new AmbientLight("");
144  DatagramIterator scan;
145  BamReader *manager;
146 
147  parse_params(params, scan, manager);
148  node->fillin(scan, manager);
149 
150  return node;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: AmbientLight::fillin
155 // Access: Protected
156 // Description: This internal function is called by make_from_bam to
157 // read in all of the relevant data from the BamFile for
158 // the new AmbientLight.
159 ////////////////////////////////////////////////////////////////////
160 void AmbientLight::
161 fillin(DatagramIterator &scan, BamReader *manager) {
162  LightNode::fillin(scan, manager);
163 }
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: lightNode.cxx:95
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A derivative of Light and of PandaNode.
Definition: lightNode.h:29
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual int get_class_priority() const
Returns the relative priority associated with all lights of this class.
A light source that seems to illuminate all points in space at once.
Definition: ambientLight.h:29
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is some other kind of light. ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
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.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
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:213
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. ...
const LColor & get_color() const
Returns the basic color of the light.
Definition: light.I:70
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
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
static void register_with_read_factory()
Tells the BamReader how to create objects of type AmbientLight.