00001 // Filename: pointLight.cxx 00002 // Created by: mike (09Jan97) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "pointLight.h" 00020 #include "graphicsStateGuardianBase.h" 00021 #include "bamWriter.h" 00022 #include "bamReader.h" 00023 #include "datagram.h" 00024 #include "datagramIterator.h" 00025 00026 TypeHandle PointLight::_type_handle; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: PointLight::CData::make_copy 00030 // Access: Public, Virtual 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 CycleData *PointLight::CData:: 00034 make_copy() const { 00035 return new CData(*this); 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: PointLight::CData::write_datagram 00040 // Access: Public, Virtual 00041 // Description: Writes the contents of this object to the datagram 00042 // for shipping out to a Bam file. 00043 //////////////////////////////////////////////////////////////////// 00044 void PointLight::CData:: 00045 write_datagram(BamWriter *, Datagram &dg) const { 00046 _specular_color.write_datagram(dg); 00047 _attenuation.write_datagram(dg); 00048 _point.write_datagram(dg); 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PointLight::CData::fillin 00053 // Access: Public, Virtual 00054 // Description: This internal function is called by make_from_bam to 00055 // read in all of the relevant data from the BamFile for 00056 // the new Light. 00057 //////////////////////////////////////////////////////////////////// 00058 void PointLight::CData:: 00059 fillin(DatagramIterator &scan, BamReader *) { 00060 _specular_color.read_datagram(scan); 00061 _attenuation.read_datagram(scan); 00062 _point.read_datagram(scan); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: PointLight::Constructor 00067 // Access: Published 00068 // Description: 00069 //////////////////////////////////////////////////////////////////// 00070 PointLight:: 00071 PointLight(const string &name) : 00072 LightNode(name) 00073 { 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: PointLight::Copy Constructor 00078 // Access: Protected 00079 // Description: Do not call the copy constructor directly; instead, 00080 // use make_copy() or copy_subgraph() to make a copy of 00081 // a node. 00082 //////////////////////////////////////////////////////////////////// 00083 PointLight:: 00084 PointLight(const PointLight ©) : 00085 LightNode(copy), 00086 _cycler(copy._cycler) 00087 { 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: PointLight::make_copy 00092 // Access: Public, Virtual 00093 // Description: Returns a newly-allocated PandaNode that is a shallow 00094 // copy of this one. It will be a different pointer, 00095 // but its internal data may or may not be shared with 00096 // that of the original PandaNode. No children will be 00097 // copied. 00098 //////////////////////////////////////////////////////////////////// 00099 PandaNode *PointLight:: 00100 make_copy() const { 00101 return new PointLight(*this); 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: PointLight::xform 00106 // Access: Public, Virtual 00107 // Description: Transforms the contents of this PandaNode by the 00108 // indicated matrix, if it means anything to do so. For 00109 // most kinds of PandaNodes, this does nothing. 00110 //////////////////////////////////////////////////////////////////// 00111 void PointLight:: 00112 xform(const LMatrix4f &mat) { 00113 LightNode::xform(mat); 00114 CDWriter cdata(_cycler); 00115 cdata->_point = cdata->_point * mat; 00116 mark_viz_stale(); 00117 } 00118 00119 //////////////////////////////////////////////////////////////////// 00120 // Function: PointLight::write 00121 // Access: Public, Virtual 00122 // Description: 00123 //////////////////////////////////////////////////////////////////// 00124 void PointLight:: 00125 write(ostream &out, int indent_level) const { 00126 indent(out, indent_level) << *this << ":\n"; 00127 indent(out, indent_level + 2) 00128 << "color " << get_color() << "\n"; 00129 indent(out, indent_level + 2) 00130 << "specular color " << get_specular_color() << "\n"; 00131 indent(out, indent_level + 2) 00132 << "attenuation " << get_attenuation() << "\n"; 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: PointLight::bind 00137 // Access: Public, Virtual 00138 // Description: 00139 //////////////////////////////////////////////////////////////////// 00140 void PointLight:: 00141 bind(GraphicsStateGuardianBase *gsg, int light_id) { 00142 gsg->bind_light(this, light_id); 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: PointLight::register_with_read_factory 00147 // Access: Public, Static 00148 // Description: Tells the BamReader how to create objects of type 00149 // PointLight. 00150 //////////////////////////////////////////////////////////////////// 00151 void PointLight:: 00152 register_with_read_factory() { 00153 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: PointLight::write_datagram 00158 // Access: Public, Virtual 00159 // Description: Writes the contents of this object to the datagram 00160 // for shipping out to a Bam file. 00161 //////////////////////////////////////////////////////////////////// 00162 void PointLight:: 00163 write_datagram(BamWriter *manager, Datagram &dg) { 00164 LightNode::write_datagram(manager, dg); 00165 manager->write_cdata(dg, _cycler); 00166 } 00167 00168 //////////////////////////////////////////////////////////////////// 00169 // Function: PointLight::make_from_bam 00170 // Access: Protected, Static 00171 // Description: This function is called by the BamReader's factory 00172 // when a new object of type PointLight is encountered 00173 // in the Bam file. It should create the PointLight 00174 // and extract its information from the file. 00175 //////////////////////////////////////////////////////////////////// 00176 TypedWritable *PointLight:: 00177 make_from_bam(const FactoryParams ¶ms) { 00178 PointLight *node = new PointLight(""); 00179 DatagramIterator scan; 00180 BamReader *manager; 00181 00182 parse_params(params, scan, manager); 00183 node->fillin(scan, manager); 00184 00185 return node; 00186 } 00187 00188 //////////////////////////////////////////////////////////////////// 00189 // Function: PointLight::fillin 00190 // Access: Protected 00191 // Description: This internal function is called by make_from_bam to 00192 // read in all of the relevant data from the BamFile for 00193 // the new PointLight. 00194 //////////////////////////////////////////////////////////////////// 00195 void PointLight:: 00196 fillin(DatagramIterator &scan, BamReader *manager) { 00197 LightNode::fillin(scan, manager); 00198 manager->read_cdata(scan, _cycler); 00199 }