Panda3D
sphereLight.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 sphereLight.cxx
10  * @author rdb
11  * @date 2016-04-15
12  */
13 
14 #include "sphereLight.h"
16 #include "bamWriter.h"
17 #include "bamReader.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 TypeHandle SphereLight::_type_handle;
22 
23 /**
24  *
25  */
26 CycleData *SphereLight::CData::
27 make_copy() const {
28  return new CData(*this);
29 }
30 
31 /**
32  * Writes the contents of this object to the datagram for shipping out to a
33  * Bam file.
34  */
35 void SphereLight::CData::
36 write_datagram(BamWriter *manager, Datagram &dg) const {
37  dg.add_stdfloat(_radius);
38 }
39 
40 /**
41  * This internal function is called by make_from_bam to read in all of the
42  * relevant data from the BamFile for the new Light.
43  */
44 void SphereLight::CData::
45 fillin(DatagramIterator &scan, BamReader *manager) {
46  _radius = scan.get_stdfloat();
47 }
48 
49 /**
50  *
51  */
52 SphereLight::
53 SphereLight(const std::string &name) :
54  PointLight(name)
55 {
56 }
57 
58 /**
59  * Do not call the copy constructor directly; instead, use make_copy() or
60  * copy_subgraph() to make a copy of a node.
61  */
62 SphereLight::
63 SphereLight(const SphereLight &copy) :
64  PointLight(copy),
65  _cycler(copy._cycler)
66 {
67 }
68 
69 /**
70  * Returns a newly-allocated PandaNode that is a shallow copy of this one. It
71  * will be a different pointer, but its internal data may or may not be shared
72  * with that of the original PandaNode. No children will be copied.
73  */
75 make_copy() const {
76  return new SphereLight(*this);
77 }
78 
79 /**
80  * Transforms the contents of this PandaNode by the indicated matrix, if it
81  * means anything to do so. For most kinds of PandaNodes, this does nothing.
82  */
83 void SphereLight::
84 xform(const LMatrix4 &mat) {
85  PointLight::xform(mat);
86  CDWriter cdata(_cycler);
87  cdata->_radius = mat.xform_vec(LVector3(0, 0, cdata->_radius)).length();
88  mark_viz_stale();
89 }
90 
91 /**
92  *
93  */
94 void SphereLight::
95 write(std::ostream &out, int indent_level) const {
96  PointLight::write(out, indent_level);
97  indent(out, indent_level) << *this << ":\n";
98  indent(out, indent_level + 2)
99  << "radius " << get_radius() << "\n";
100 }
101 
102 /**
103  * Tells the BamReader how to create objects of type SphereLight.
104  */
105 void SphereLight::
107  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
108 }
109 
110 /**
111  * Writes the contents of this object to the datagram for shipping out to a
112  * Bam file.
113  */
114 void SphereLight::
116  PointLight::write_datagram(manager, dg);
117  manager->write_cdata(dg, _cycler);
118 }
119 
120 /**
121  * This function is called by the BamReader's factory when a new object of
122  * type SphereLight is encountered in the Bam file. It should create the
123  * SphereLight and extract its information from the file.
124  */
125 TypedWritable *SphereLight::
126 make_from_bam(const FactoryParams &params) {
127  SphereLight *node = new SphereLight("");
128  DatagramIterator scan;
129  BamReader *manager;
130 
131  parse_params(params, scan, manager);
132  node->fillin(scan, manager);
133 
134  return node;
135 }
136 
137 /**
138  * This internal function is called by make_from_bam to read in all of the
139  * relevant data from the BamFile for the new SphereLight.
140  */
141 void SphereLight::
142 fillin(DatagramIterator &scan, BamReader *manager) {
143  PointLight::fillin(scan, manager);
144 
145  manager->read_cdata(scan, _cycler);
146 }
static void register_with_read_factory()
Tells the BamReader how to create objects of type SphereLight.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
Definition: pointLight.cxx:119
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.
Definition: pointLight.cxx:230
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
Definition: bamReader.cxx:695
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
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 write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
Definition: bamWriter.cxx:425
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
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:133
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
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
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
A light originating from a single point in space, and shining in all directions.
Definition: pointLight.h:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A sphere light is like a point light, except that it represents a sphere with a radius,...
Definition: sphereLight.h:28
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: sphereLight.cxx:75
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
Definition: sphereLight.cxx:84