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
20TypeHandle AmbientLight::_type_handle;
21
22/**
23 *
24 */
25AmbientLight::
26AmbientLight(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 */
35AmbientLight::
36AmbientLight(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 */
48get_class_priority() const {
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 */
58make_copy() const {
59 return new AmbientLight(*this);
60}
61
62/**
63 *
64 */
65void AmbientLight::
66write(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 */
77is_ambient_light() const {
78 return true;
79}
80
81/**
82 *
83 */
84void AmbientLight::
85bind(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 */
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 */
104write_datagram(BamWriter *manager, Datagram &dg) {
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 */
113TypedWritable *AmbientLight::
114make_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 */
129void AmbientLight::
130fillin(DatagramIterator &scan, BamReader *manager) {
131 LightNode::fillin(scan, manager);
132}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
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
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
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 AmbientLight.
virtual bool is_ambient_light() const final
Returns true if this is an AmbientLight, false if it is some other kind of light.
virtual int get_class_priority() const
Returns the relative priority associated with all lights of this class.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
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
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A derivative of Light and of PandaNode.
Definition: lightNode.h:27
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
get_color
Returns the basic color of the light.
Definition: light.h:49
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20