00001 // Filename: lensNode.cxx 00002 // Created by: drose (26Feb02) 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 "lensNode.h" 00020 #include "geometricBoundingVolume.h" 00021 #include "bamWriter.h" 00022 #include "bamReader.h" 00023 #include "datagram.h" 00024 #include "datagramIterator.h" 00025 00026 TypeHandle LensNode::_type_handle; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: LensNode::Constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 LensNode:: 00034 LensNode(const string &name) : 00035 PandaNode(name) 00036 { 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: LensNode::Copy Constructor 00041 // Access: Protected 00042 // Description: 00043 //////////////////////////////////////////////////////////////////// 00044 LensNode:: 00045 LensNode(const LensNode ©) : 00046 PandaNode(copy), 00047 _lens(copy._lens) 00048 { 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: LensNode::xform 00053 // Access: Public, Virtual 00054 // Description: Transforms the contents of this PandaNode by the 00055 // indicated matrix, if it means anything to do so. For 00056 // most kinds of PandaNodes, this does nothing. 00057 //////////////////////////////////////////////////////////////////// 00058 void LensNode:: 00059 xform(const LMatrix4f &mat) { 00060 PandaNode::xform(mat); 00061 // We need to actually transform the lens here. 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: LensNode::make_copy 00066 // Access: Public, Virtual 00067 // Description: Returns a newly-allocated Node that is a shallow copy 00068 // of this one. It will be a different Node pointer, 00069 // but its internal data may or may not be shared with 00070 // that of the original Node. 00071 //////////////////////////////////////////////////////////////////// 00072 PandaNode *LensNode:: 00073 make_copy() const { 00074 return new LensNode(*this); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: LensNode::is_in_view 00079 // Access: Public 00080 // Description: Returns true if the given point is within the bounds 00081 // of the lens of the LensNode (i.e. if the camera can 00082 // see the point). 00083 //////////////////////////////////////////////////////////////////// 00084 bool LensNode:: 00085 is_in_view(const LPoint3f &pos) { 00086 PT(BoundingVolume) bv = _lens->make_bounds(); 00087 if (bv == (BoundingVolume *)NULL) { 00088 return false; 00089 } 00090 GeometricBoundingVolume *gbv = DCAST(GeometricBoundingVolume, bv); 00091 int ret = gbv->contains(pos); 00092 return (ret != 0); 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: LensNode::output 00097 // Access: Public, Virtual 00098 // Description: 00099 //////////////////////////////////////////////////////////////////// 00100 void LensNode:: 00101 output(ostream &out) const { 00102 PandaNode::output(out); 00103 if (_lens != (Lens *)NULL) { 00104 out << " ("; 00105 _lens->output(out); 00106 out << ")"; 00107 } 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: LensNode::write 00112 // Access: Public, Virtual 00113 // Description: 00114 //////////////////////////////////////////////////////////////////// 00115 void LensNode:: 00116 write(ostream &out, int indent_level) const { 00117 PandaNode::write(out, indent_level); 00118 if (_lens != (Lens *)NULL) { 00119 _lens->write(out, indent_level + 2); 00120 } 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: LensNode::register_with_read_factory 00125 // Access: Public, Static 00126 // Description: Tells the BamReader how to create objects of type 00127 // LensNode. 00128 //////////////////////////////////////////////////////////////////// 00129 void LensNode:: 00130 register_with_read_factory() { 00131 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: LensNode::write_datagram 00136 // Access: Public, Virtual 00137 // Description: Writes the contents of this object to the datagram 00138 // for shipping out to a Bam file. 00139 //////////////////////////////////////////////////////////////////// 00140 void LensNode:: 00141 write_datagram(BamWriter *manager, Datagram &dg) { 00142 PandaNode::write_datagram(manager, dg); 00143 00144 // We should actually write out the lens. Easy to do, but not 00145 // immediately pressing; I hope no one gets burned by the omission. 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: LensNode::complete_pointers 00150 // Access: Public, Virtual 00151 // Description: Receives an array of pointers, one for each time 00152 // manager->read_pointer() was called in fillin(). 00153 // Returns the number of pointers processed. 00154 //////////////////////////////////////////////////////////////////// 00155 int LensNode:: 00156 complete_pointers(TypedWritable **p_list, BamReader *manager) { 00157 int pi = PandaNode::complete_pointers(p_list, manager); 00158 00159 return pi; 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: LensNode::make_from_bam 00164 // Access: Protected, Static 00165 // Description: This function is called by the BamReader's factory 00166 // when a new object of type LensNode is encountered 00167 // in the Bam file. It should create the LensNode 00168 // and extract its information from the file. 00169 //////////////////////////////////////////////////////////////////// 00170 TypedWritable *LensNode:: 00171 make_from_bam(const FactoryParams ¶ms) { 00172 LensNode *node = new LensNode(""); 00173 DatagramIterator scan; 00174 BamReader *manager; 00175 00176 parse_params(params, scan, manager); 00177 node->fillin(scan, manager); 00178 00179 return node; 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: LensNode::fillin 00184 // Access: Protected 00185 // Description: This internal function is called by make_from_bam to 00186 // read in all of the relevant data from the BamFile for 00187 // the new LensNode. 00188 //////////////////////////////////////////////////////////////////// 00189 void LensNode:: 00190 fillin(DatagramIterator &scan, BamReader *manager) { 00191 PandaNode::fillin(scan, manager); 00192 }