Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/directionalLight.cxx

Go to the documentation of this file.
00001 // Filename: directionalLight.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 "directionalLight.h"
00020 #include "graphicsStateGuardianBase.h"
00021 #include "bamWriter.h"
00022 #include "bamReader.h"
00023 #include "datagram.h"
00024 #include "datagramIterator.h"
00025 
00026 TypeHandle DirectionalLight::_type_handle;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: DirectionalLight::CData::make_copy
00030 //       Access: Public, Virtual
00031 //  Description:
00032 ////////////////////////////////////////////////////////////////////
00033 CycleData *DirectionalLight::CData::
00034 make_copy() const {
00035   return new CData(*this);
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: DirectionalLight::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 DirectionalLight::CData::
00045 write_datagram(BamWriter *, Datagram &dg) const {
00046   _specular_color.write_datagram(dg);
00047   _point.write_datagram(dg);
00048   _direction.write_datagram(dg);
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: DirectionalLight::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 DirectionalLight::CData::
00059 fillin(DatagramIterator &scan, BamReader *) {
00060   _specular_color.read_datagram(scan);
00061   _point.read_datagram(scan);
00062   _direction.read_datagram(scan);
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: DirectionalLight::Constructor
00067 //       Access: Published
00068 //  Description:
00069 ////////////////////////////////////////////////////////////////////
00070 DirectionalLight::
00071 DirectionalLight(const string &name) : 
00072   LightNode(name) 
00073 {
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: DirectionalLight::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 DirectionalLight::
00084 DirectionalLight(const DirectionalLight &copy) :
00085   LightNode(copy),
00086   _cycler(copy._cycler)
00087 {
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: DirectionalLight::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 *DirectionalLight::
00100 make_copy() const {
00101   return new DirectionalLight(*this);
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: DirectionalLight::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 DirectionalLight::
00112 xform(const LMatrix4f &mat) {
00113   LightNode::xform(mat);
00114   CDWriter cdata(_cycler);
00115   cdata->_point = cdata->_point * mat;
00116   cdata->_direction = cdata->_direction * mat;
00117   mark_viz_stale();
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: DirectionalLight::write
00122 //       Access: Public, Virtual
00123 //  Description:
00124 ////////////////////////////////////////////////////////////////////
00125 void DirectionalLight::
00126 write(ostream &out, int indent_level) const {
00127   indent(out, indent_level) << *this << ":\n";
00128   indent(out, indent_level + 2)
00129     << "color " << get_color() << "\n";
00130   indent(out, indent_level + 2)
00131     << "specular color " << get_specular_color() << "\n";
00132   indent(out, indent_level + 2)
00133     << "direction " << get_direction() << "\n";
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: DirectionalLight::bind
00138 //       Access: Public, Virtual
00139 //  Description:
00140 ////////////////////////////////////////////////////////////////////
00141 void DirectionalLight::
00142 bind(GraphicsStateGuardianBase *gsg, int light_id) {
00143   gsg->bind_light(this, light_id);
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: DirectionalLight::register_with_read_factory
00148 //       Access: Public, Static
00149 //  Description: Tells the BamReader how to create objects of type
00150 //               DirectionalLight.
00151 ////////////////////////////////////////////////////////////////////
00152 void DirectionalLight::
00153 register_with_read_factory() {
00154   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: DirectionalLight::write_datagram
00159 //       Access: Public, Virtual
00160 //  Description: Writes the contents of this object to the datagram
00161 //               for shipping out to a Bam file.
00162 ////////////////////////////////////////////////////////////////////
00163 void DirectionalLight::
00164 write_datagram(BamWriter *manager, Datagram &dg) {
00165   LightNode::write_datagram(manager, dg);
00166   manager->write_cdata(dg, _cycler);
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: DirectionalLight::make_from_bam
00171 //       Access: Protected, Static
00172 //  Description: This function is called by the BamReader's factory
00173 //               when a new object of type DirectionalLight is encountered
00174 //               in the Bam file.  It should create the DirectionalLight
00175 //               and extract its information from the file.
00176 ////////////////////////////////////////////////////////////////////
00177 TypedWritable *DirectionalLight::
00178 make_from_bam(const FactoryParams &params) {
00179   DirectionalLight *node = new DirectionalLight("");
00180   DatagramIterator scan;
00181   BamReader *manager;
00182 
00183   parse_params(params, scan, manager);
00184   node->fillin(scan, manager);
00185 
00186   return node;
00187 }
00188 
00189 ////////////////////////////////////////////////////////////////////
00190 //     Function: DirectionalLight::fillin
00191 //       Access: Protected
00192 //  Description: This internal function is called by make_from_bam to
00193 //               read in all of the relevant data from the BamFile for
00194 //               the new DirectionalLight.
00195 ////////////////////////////////////////////////////////////////////
00196 void DirectionalLight::
00197 fillin(DatagramIterator &scan, BamReader *manager) {
00198   LightNode::fillin(scan, manager);
00199   manager->read_cdata(scan, _cycler);
00200 }

Generated on Fri May 2 00:41:34 2003 for Panda by doxygen1.3