Panda3D
 All Classes Functions Variables Enumerations
light.cxx
1 // Filename: light.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 "light.h"
16 #include "bamWriter.h"
17 #include "bamReader.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 UpdateSeq Light::_sort_seq;
22 
23 TypeHandle Light::_type_handle;
24 
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: Light::CData::make_copy
28 // Access: Public, Virtual
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 CycleData *Light::CData::
32 make_copy() const {
33  return new CData(*this);
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: Light::CData::write_datagram
38 // Access: Public, Virtual
39 // Description: Writes the contents of this object to the datagram
40 // for shipping out to a Bam file.
41 ////////////////////////////////////////////////////////////////////
42 void Light::CData::
43 write_datagram(BamWriter *, Datagram &dg) const {
44  _color.write_datagram(dg);
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: Light::CData::fillin
49 // Access: Public, Virtual
50 // Description: This internal function is called by make_from_bam to
51 // read in all of the relevant data from the BamFile for
52 // the new Light.
53 ////////////////////////////////////////////////////////////////////
54 void Light::CData::
55 fillin(DatagramIterator &scan, BamReader *) {
56  _color.read_datagram(scan);
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: Light::Destructor
61 // Access: Published, Virtual
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 Light::
65 ~Light() {
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: Light::is_ambient_light
70 // Access: Published, Virtual
71 // Description: Returns true if this is an AmbientLight, false if it
72 // is some other kind of light.
73 ////////////////////////////////////////////////////////////////////
74 bool Light::
76  return false;
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: Light::get_exponent
81 // Access: Public, Virtual
82 // Description: For spotlights, returns the exponent that controls
83 // the amount of light falloff from the center of the
84 // spotlight. For other kinds of lights, returns 0.
85 ////////////////////////////////////////////////////////////////////
86 PN_stdfloat Light::
87 get_exponent() const {
88  return 0;
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: Light::get_specular_color
93 // Access: Public, Virtual
94 // Description: Returns the color of specular highlights generated
95 // by the light. This value is meaningless for ambient
96 // lights.
97 ////////////////////////////////////////////////////////////////////
98 const LColor &Light::
100  static const LColor white(1, 1, 1, 1);
101  return white;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: Light::get_attenuation
106 // Access: Public, Virtual
107 // Description: Returns the terms of the attenuation equation for the
108 // light. These are, in order, the constant, linear,
109 // and quadratic terms based on the distance from the
110 // point to the vertex.
111 ////////////////////////////////////////////////////////////////////
112 const LVecBase3 &Light::
114  static const LVecBase3 no_atten(1, 0, 0);
115  return no_atten;
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: Light::get_vector_to_light
120 // Access: Public, Virtual
121 // Description: Computes the vector from a particular vertex to this
122 // light. The exact vector depends on the type of light
123 // (e.g. point lights return a different result than
124 // directional lights).
125 //
126 // The input parameters are the vertex position in
127 // question, expressed in object space, and the matrix
128 // which converts from light space to object space. The
129 // result is expressed in object space.
130 //
131 // The return value is true if the result is successful,
132 // or false if it cannot be computed (e.g. for an
133 // ambient light).
134 ////////////////////////////////////////////////////////////////////
135 bool Light::
137  return false;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: Light::get_viz
142 // Access: Public
143 // Description: Returns a GeomNode that may be rendered to visualize
144 // the Light. This is used during the cull traversal to
145 // render the Lights that have been made visible.
146 ////////////////////////////////////////////////////////////////////
149  CDLockedReader cdata(_cycler);
150  if (cdata->_viz_geom_stale) {
151  CDWriter cdata_w(_cycler, cdata);
152 
153  cdata_w->_viz_geom = new GeomNode("viz");
154  fill_viz_geom(cdata_w->_viz_geom);
155  cdata_w->_viz_geom_stale = false;
156  }
157  return cdata->_viz_geom;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: Light::fill_viz_geom
162 // Access: Protected, Virtual
163 // Description: Fills the indicated GeomNode up with Geoms suitable
164 // for rendering this light.
165 ////////////////////////////////////////////////////////////////////
166 void Light::
167 fill_viz_geom(GeomNode *) {
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: Light::write_datagram
172 // Access: Protected
173 // Description: Writes the contents of this object to the datagram
174 // for shipping out to a Bam file.
175 ////////////////////////////////////////////////////////////////////
176 void Light::
177 write_datagram(BamWriter *manager, Datagram &dg) {
178  manager->write_cdata(dg, _cycler);
179  dg.add_int32(_priority);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: Light::fillin
184 // Access: Protected
185 // Description: This internal function is called by make_from_bam to
186 // read in all of the relevant data from the BamFile for
187 // the new Light.
188 ////////////////////////////////////////////////////////////////////
189 void Light::
190 fillin(DatagramIterator &scan, BamReader *manager) {
191  manager->read_cdata(scan, _cycler);
192  _priority = scan.get_int32();
193 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
Definition: bamReader.cxx:747
virtual PN_stdfloat get_exponent() const
For spotlights, returns the exponent that controls the amount of light falloff from the center of the...
Definition: light.cxx:87
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
void write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
Definition: bamWriter.cxx:398
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
PN_int32 get_int32()
Extracts a signed 32-bit integer.
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is some other kind of light. ...
Definition: light.cxx:75
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
virtual bool get_vector_to_light(LVector3 &result, const LPoint3 &from_object_point, const LMatrix4 &to_object_space)
Computes the vector from a particular vertex to this light.
Definition: light.cxx:136
GeomNode * get_viz()
Returns a GeomNode that may be rendered to visualize the Light.
Definition: light.cxx:148
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
virtual const LColor & get_specular_color() const
Returns the color of specular highlights generated by the light.
Definition: light.cxx:99
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
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:85
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
virtual const LVecBase3 & get_attenuation() const
Returns the terms of the attenuation equation for the light.
Definition: light.cxx:113