Panda3D
|
00001 // Filename: modelNode.cxx 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "uvScrollNode.h" 00016 00017 #include "bamReader.h" 00018 #include "datagram.h" 00019 #include "datagramIterator.h" 00020 #include "luse.h" 00021 #include "renderState.h" 00022 #include "texMatrixAttrib.h" 00023 #include "textureStage.h" 00024 #include "transformState.h" 00025 00026 TypeHandle UvScrollNode::_type_handle; 00027 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: UvScrollNode::make_copy 00031 // Access: Public, Virtual 00032 // Description: Returns a newly-allocated Node that is a shallow copy 00033 // of this one. It will be a different Node pointer, 00034 // but its internal data may or may not be shared with 00035 // that of the original Node. 00036 //////////////////////////////////////////////////////////////////// 00037 PandaNode *UvScrollNode:: 00038 make_copy() const { 00039 return new UvScrollNode(*this); 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: UvSctrollNode::register_with_read_factory 00044 // Access: Public, Static 00045 // Description: Tells the BamReader how to create objects of type 00046 // UvScrollNode. 00047 //////////////////////////////////////////////////////////////////// 00048 void UvScrollNode:: 00049 register_with_read_factory() { 00050 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: UvSctrollNode::write_datagram 00055 // Access: Public, Virtual 00056 // Description: Writes the contents of this object to the datagram 00057 // for shipping out to a Bam file. 00058 //////////////////////////////////////////////////////////////////// 00059 void UvScrollNode:: 00060 write_datagram(BamWriter *manager, Datagram &dg) { 00061 PandaNode::write_datagram(manager, dg); 00062 dg.add_stdfloat(_u_speed); 00063 dg.add_stdfloat(_v_speed); 00064 dg.add_stdfloat(_r_speed); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: ModelNode::make_from_bam 00069 // Access: Protected, Static 00070 // Description: This function is called by the BamReader's factory 00071 // when a new object of type ModelNode is encountered 00072 // in the Bam file. It should create the ModelNode 00073 // and extract its information from the file. 00074 //////////////////////////////////////////////////////////////////// 00075 TypedWritable *UvScrollNode:: 00076 make_from_bam(const FactoryParams ¶ms) { 00077 UvScrollNode *node = new UvScrollNode(""); 00078 DatagramIterator scan; 00079 BamReader *manager; 00080 00081 parse_params(params, scan, manager); 00082 node->fillin(scan, manager); 00083 00084 return node; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: ModelNode::fillin 00089 // Access: Protected 00090 // Description: This internal function is called by make_from_bam to 00091 // read in all of the relevant data from the BamFile for 00092 // the new ModelNode. 00093 //////////////////////////////////////////////////////////////////// 00094 void UvScrollNode:: 00095 fillin(DatagramIterator &scan, BamReader *manager) { 00096 PandaNode::fillin(scan, manager); 00097 00098 _u_speed = scan.get_stdfloat(); 00099 _v_speed = scan.get_stdfloat(); 00100 if(manager->get_file_minor_ver() >=22) { 00101 _r_speed = scan.get_stdfloat(); 00102 } 00103 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: SequenceNode::cull_callback 00108 // Access: Public, Virtual 00109 // Description: This function will be called during the cull 00110 // traversal to perform any additional operations that 00111 // should be performed at cull time. This may include 00112 // additional manipulation of render state or additional 00113 // visible/invisible decisions, or any other arbitrary 00114 // operation. 00115 // 00116 // Note that this function will *not* be called unless 00117 // set_cull_callback() is called in the constructor of 00118 // the derived class. It is necessary to call 00119 // set_cull_callback() to indicated that we require 00120 // cull_callback() to be called. 00121 // 00122 // By the time this function is called, the node has 00123 // already passed the bounding-volume test for the 00124 // viewing frustum, and the node's transform and state 00125 // have already been applied to the indicated 00126 // CullTraverserData object. 00127 // 00128 // The return value is \true if this node should be 00129 // visible, or false if it should be culled. 00130 //////////////////////////////////////////////////////////////////// 00131 bool UvScrollNode:: 00132 cull_callback(CullTraverser * trav, CullTraverserData &data) { 00133 double elapsed = ClockObject::get_global_clock()->get_frame_time() - _start_time; 00134 CPT(TransformState) ts = TransformState::make_pos_hpr( 00135 LVecBase3(cmod(elapsed*_u_speed,1.0)/1.0, cmod(elapsed*_v_speed,1.0)/1.0,0), 00136 LVecBase3((cmod(elapsed*_r_speed,1.0)/1.0)*360,0,0)); 00137 00138 CPT(RenderAttrib) tm = TexMatrixAttrib::make(TextureStage::get_default(), ts); 00139 CPT(RenderState) rs = RenderState::make_empty()->set_attrib(tm); 00140 data._state = data._state->compose(rs); 00141 00142 return true; 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: UvScrollNode::safe_to_flatten 00147 // Access: Public, Virtual 00148 // Description: Returns true if it is generally safe to flatten out 00149 // this particular kind of PandaNode by duplicating 00150 // instances (by calling dupe_for_flatten()), false 00151 // otherwise (for instance, a Camera cannot be safely 00152 // flattened, because the Camera pointer itself is 00153 // meaningful). 00154 //////////////////////////////////////////////////////////////////// 00155 bool UvScrollNode:: 00156 safe_to_flatten() const { 00157 return false; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: UvScrollNode::safe_to_combine 00162 // Access: Public, Virtual 00163 // Description: Returns true if it is generally safe to combine this 00164 // with other nodes, which it isn't, so don't. Ever. 00165 //////////////////////////////////////////////////////////////////// 00166 bool UvScrollNode:: 00167 safe_to_combine() const { 00168 return false; 00169 }