Panda3D

vertexTransform.cxx

00001 // Filename: vertexTransform.cxx
00002 // Created by:  drose (23Mar05)
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 "vertexTransform.h"
00016 #include "bamReader.h"
00017 #include "bamWriter.h"
00018 #include "indent.h"
00019 #include "transformTable.h"
00020 
00021 PipelineCycler<VertexTransform::CData> VertexTransform::_global_cycler;
00022 UpdateSeq VertexTransform::_next_modified;
00023 
00024 TypeHandle VertexTransform::_type_handle;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: VertexTransform::Constructor
00028 //       Access: Published
00029 //  Description: 
00030 ////////////////////////////////////////////////////////////////////
00031 VertexTransform::
00032 VertexTransform() {
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: VertexTransform::Destructor
00037 //       Access: Published, Virtual
00038 //  Description: 
00039 ////////////////////////////////////////////////////////////////////
00040 VertexTransform::
00041 ~VertexTransform() {
00042   // We shouldn't destruct while any TransformTables are holding our
00043   // pointer.
00044   nassertv(_tables.empty());
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: VertexTransform::mult_matrix
00049 //       Access: Published, Virtual
00050 //  Description: Premultiplies this transform's matrix with the
00051 //               indicated previous matrix, so that the result is the
00052 //               net composition of the given transform with this
00053 //               transform.  The result is stored in the parameter
00054 //               "result", which should not be the same matrix as
00055 //               previous.
00056 ////////////////////////////////////////////////////////////////////
00057 void VertexTransform::
00058 mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const {
00059   nassertv(&result != &previous);
00060   LMatrix4 me;
00061   get_matrix(me);
00062   result.multiply(me, previous);
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: VertexTransform::accumulate_matrix
00067 //       Access: Published, Virtual
00068 //  Description: Adds the value of this transform's matrix, modified
00069 //               by the indicated weight, into the indicated
00070 //               accumulation matrix.  This is used to compute the
00071 //               result of several blended transforms.
00072 ////////////////////////////////////////////////////////////////////
00073 void VertexTransform::
00074 accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const {
00075   LMatrix4 me;
00076   get_matrix(me);
00077   accum.accumulate(me, weight);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: VertexTransform::output
00082 //       Access: Published, Virtual
00083 //  Description: 
00084 ////////////////////////////////////////////////////////////////////
00085 void VertexTransform::
00086 output(ostream &out) const {
00087   out << get_type();
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: VertexTransform::write
00092 //       Access: Published, Virtual
00093 //  Description: 
00094 ////////////////////////////////////////////////////////////////////
00095 void VertexTransform::
00096 write(ostream &out, int indent_level) const {
00097   indent(out, indent_level) 
00098     << *this << ":\n";
00099   LMatrix4 mat;
00100   get_matrix(mat);
00101   mat.write(out, indent_level + 2);
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: VertexTransform::get_next_modified
00106 //       Access: Public, Static
00107 //  Description: Returns a monotonically increasing sequence.  Each
00108 //               time this is called, a new sequence number is
00109 //               returned, higher than the previous value.
00110 //
00111 //               This is used to ensure that all
00112 //               VertexTransform::get_modified() calls return an
00113 //               increasing number in the same space, so that
00114 //               TransformBlend::get_modified() is easy to determine.
00115 //               It is similar to Geom::get_modified(), but it is in a
00116 //               different space.
00117 ////////////////////////////////////////////////////////////////////
00118 UpdateSeq VertexTransform::
00119 get_next_modified(Thread *current_thread) {
00120   CDWriter cdatag(_global_cycler, true, current_thread);
00121   ++_next_modified;
00122   cdatag->_modified = _next_modified;
00123 
00124   return _next_modified;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: VertexTransform::mark_modified
00129 //       Access: Protected
00130 //  Description: Intended to be called by a derived class whenever the
00131 //               reported transform might have changed.  Without
00132 //               calling this method, changes to get_matrix() may not
00133 //               be propagated through the system.
00134 ////////////////////////////////////////////////////////////////////
00135 void VertexTransform::
00136 mark_modified(Thread *current_thread) {
00137   CDWriter cdata(_cycler, true, current_thread);
00138   cdata->_modified = get_next_modified(current_thread);
00139   
00140   Palettes::iterator pi;
00141   for (pi = _tables.begin(); pi != _tables.end(); ++pi) {
00142     (*pi)->update_modified(cdata->_modified, current_thread);
00143   }
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: VertexTransform::write_datagram
00148 //       Access: Public, Virtual
00149 //  Description: Writes the contents of this object to the datagram
00150 //               for shipping out to a Bam file.
00151 ////////////////////////////////////////////////////////////////////
00152 void VertexTransform::
00153 write_datagram(BamWriter *manager, Datagram &dg) {
00154   TypedWritable::write_datagram(manager, dg);
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: VertexTransform::fillin
00159 //       Access: Protected
00160 //  Description: This internal function is called by make_from_bam to
00161 //               read in all of the relevant data from the BamFile for
00162 //               the new VertexTransform.
00163 ////////////////////////////////////////////////////////////////////
00164 void VertexTransform::
00165 fillin(DatagramIterator &scan, BamReader *manager) {
00166   TypedWritable::fillin(scan, manager);
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: VertexTransform::CData::make_copy
00171 //       Access: Public, Virtual
00172 //  Description:
00173 ////////////////////////////////////////////////////////////////////
00174 CycleData *VertexTransform::CData::
00175 make_copy() const {
00176   return new CData(*this);
00177 }
00178 
00179 ////////////////////////////////////////////////////////////////////
00180 //     Function: VertexTransform::CData::write_datagram
00181 //       Access: Public, Virtual
00182 //  Description: Writes the contents of this object to the datagram
00183 //               for shipping out to a Bam file.
00184 ////////////////////////////////////////////////////////////////////
00185 void VertexTransform::CData::
00186 write_datagram(BamWriter *manager, Datagram &dg) const {
00187 }
00188 
00189 ////////////////////////////////////////////////////////////////////
00190 //     Function: VertexTransform::CData::complete_pointers
00191 //       Access: Public, Virtual
00192 //  Description: Receives an array of pointers, one for each time
00193 //               manager->read_pointer() was called in fillin().
00194 //               Returns the number of pointers processed.
00195 ////////////////////////////////////////////////////////////////////
00196 int VertexTransform::CData::
00197 complete_pointers(TypedWritable **p_list, BamReader *manager) {
00198   int pi = CycleData::complete_pointers(p_list, manager);
00199 
00200   return pi;
00201 }
00202 
00203 ////////////////////////////////////////////////////////////////////
00204 //     Function: VertexTransform::CData::fillin
00205 //       Access: Public, Virtual
00206 //  Description: This internal function is called by make_from_bam to
00207 //               read in all of the relevant data from the BamFile for
00208 //               the new VertexTransform.
00209 ////////////////////////////////////////////////////////////////////
00210 void VertexTransform::CData::
00211 fillin(DatagramIterator &scan, BamReader *manager) {
00212 }
 All Classes Functions Variables Enumerations