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(LMatrix4f &result, const LMatrix4f &previous) const {
00059   nassertv(&result != &previous);
00060   LMatrix4f 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(LMatrix4f &accum, float weight) const {
00075   LMatrix4f me;
00076   get_matrix(me);
00077   
00078   accum._m.m._00 += me._m.m._00 * weight;
00079   accum._m.m._01 += me._m.m._01 * weight;
00080   accum._m.m._02 += me._m.m._02 * weight;
00081   accum._m.m._03 += me._m.m._03 * weight;
00082   
00083   accum._m.m._10 += me._m.m._10 * weight;
00084   accum._m.m._11 += me._m.m._11 * weight;
00085   accum._m.m._12 += me._m.m._12 * weight;
00086   accum._m.m._13 += me._m.m._13 * weight;
00087   
00088   accum._m.m._20 += me._m.m._20 * weight;
00089   accum._m.m._21 += me._m.m._21 * weight;
00090   accum._m.m._22 += me._m.m._22 * weight;
00091   accum._m.m._23 += me._m.m._23 * weight;
00092   
00093   accum._m.m._30 += me._m.m._30 * weight;
00094   accum._m.m._31 += me._m.m._31 * weight;
00095   accum._m.m._32 += me._m.m._32 * weight;
00096   accum._m.m._33 += me._m.m._33 * weight;
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: VertexTransform::output
00101 //       Access: Published, Virtual
00102 //  Description: 
00103 ////////////////////////////////////////////////////////////////////
00104 void VertexTransform::
00105 output(ostream &out) const {
00106   out << get_type();
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: VertexTransform::write
00111 //       Access: Published, Virtual
00112 //  Description: 
00113 ////////////////////////////////////////////////////////////////////
00114 void VertexTransform::
00115 write(ostream &out, int indent_level) const {
00116   indent(out, indent_level) 
00117     << *this << ":\n";
00118   LMatrix4f mat;
00119   get_matrix(mat);
00120   mat.write(out, indent_level + 2);
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: VertexTransform::get_next_modified
00125 //       Access: Public, Static
00126 //  Description: Returns a monotonically increasing sequence.  Each
00127 //               time this is called, a new sequence number is
00128 //               returned, higher than the previous value.
00129 //
00130 //               This is used to ensure that all
00131 //               VertexTransform::get_modified() calls return an
00132 //               increasing number in the same space, so that
00133 //               TransformBlend::get_modified() is easy to determine.
00134 //               It is similar to Geom::get_modified(), but it is in a
00135 //               different space.
00136 ////////////////////////////////////////////////////////////////////
00137 UpdateSeq VertexTransform::
00138 get_next_modified(Thread *current_thread) {
00139   CDWriter cdatag(_global_cycler, true, current_thread);
00140   ++_next_modified;
00141   cdatag->_modified = _next_modified;
00142 
00143   return _next_modified;
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: VertexTransform::mark_modified
00148 //       Access: Protected
00149 //  Description: Intended to be called by a derived class whenever the
00150 //               reported transform might have changed.  Without
00151 //               calling this method, changes to get_matrix() may not
00152 //               be propagated through the system.
00153 ////////////////////////////////////////////////////////////////////
00154 void VertexTransform::
00155 mark_modified(Thread *current_thread) {
00156   CDWriter cdata(_cycler, true, current_thread);
00157   cdata->_modified = get_next_modified(current_thread);
00158   
00159   Palettes::iterator pi;
00160   for (pi = _tables.begin(); pi != _tables.end(); ++pi) {
00161     (*pi)->update_modified(cdata->_modified, current_thread);
00162   }
00163 }
00164 
00165 ////////////////////////////////////////////////////////////////////
00166 //     Function: VertexTransform::write_datagram
00167 //       Access: Public, Virtual
00168 //  Description: Writes the contents of this object to the datagram
00169 //               for shipping out to a Bam file.
00170 ////////////////////////////////////////////////////////////////////
00171 void VertexTransform::
00172 write_datagram(BamWriter *manager, Datagram &dg) {
00173   TypedWritable::write_datagram(manager, dg);
00174 }
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: VertexTransform::fillin
00178 //       Access: Protected
00179 //  Description: This internal function is called by make_from_bam to
00180 //               read in all of the relevant data from the BamFile for
00181 //               the new VertexTransform.
00182 ////////////////////////////////////////////////////////////////////
00183 void VertexTransform::
00184 fillin(DatagramIterator &scan, BamReader *manager) {
00185   TypedWritable::fillin(scan, manager);
00186 }
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: VertexTransform::CData::make_copy
00190 //       Access: Public, Virtual
00191 //  Description:
00192 ////////////////////////////////////////////////////////////////////
00193 CycleData *VertexTransform::CData::
00194 make_copy() const {
00195   return new CData(*this);
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: VertexTransform::CData::write_datagram
00200 //       Access: Public, Virtual
00201 //  Description: Writes the contents of this object to the datagram
00202 //               for shipping out to a Bam file.
00203 ////////////////////////////////////////////////////////////////////
00204 void VertexTransform::CData::
00205 write_datagram(BamWriter *manager, Datagram &dg) const {
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: VertexTransform::CData::complete_pointers
00210 //       Access: Public, Virtual
00211 //  Description: Receives an array of pointers, one for each time
00212 //               manager->read_pointer() was called in fillin().
00213 //               Returns the number of pointers processed.
00214 ////////////////////////////////////////////////////////////////////
00215 int VertexTransform::CData::
00216 complete_pointers(TypedWritable **p_list, BamReader *manager) {
00217   int pi = CycleData::complete_pointers(p_list, manager);
00218 
00219   return pi;
00220 }
00221 
00222 ////////////////////////////////////////////////////////////////////
00223 //     Function: VertexTransform::CData::fillin
00224 //       Access: Public, Virtual
00225 //  Description: This internal function is called by make_from_bam to
00226 //               read in all of the relevant data from the BamFile for
00227 //               the new VertexTransform.
00228 ////////////////////////////////////////////////////////////////////
00229 void VertexTransform::CData::
00230 fillin(DatagramIterator &scan, BamReader *manager) {
00231 }
 All Classes Functions Variables Enumerations