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

panda/src/pgraph/texMatrixAttrib.cxx

Go to the documentation of this file.
00001 // Filename: texMatrixAttrib.cxx
00002 // Created by:  drose (14Mar02)
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 "texMatrixAttrib.h"
00020 #include "graphicsStateGuardianBase.h"
00021 #include "dcast.h"
00022 #include "bamReader.h"
00023 #include "bamWriter.h"
00024 #include "datagram.h"
00025 #include "datagramIterator.h"
00026 
00027 TypeHandle TexMatrixAttrib::_type_handle;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: TexMatrixAttrib::make
00031 //       Access: Published, Static
00032 //  Description: Constructs a new TexMatrixAttrib object that indicates
00033 //               geometry should be scaled by the indicated factor.
00034 ////////////////////////////////////////////////////////////////////
00035 CPT(RenderAttrib) TexMatrixAttrib::
00036 make(const LMatrix4f &mat) {
00037   TexMatrixAttrib *attrib = new TexMatrixAttrib(mat);
00038   return return_new(attrib);
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: TexMatrixAttrib::issue
00043 //       Access: Public, Virtual
00044 //  Description: Calls the appropriate method on the indicated GSG
00045 //               to issue the graphics commands appropriate to the
00046 //               given attribute.  This is normally called
00047 //               (indirectly) only from
00048 //               GraphicsStateGuardian::set_state() or modify_state().
00049 ////////////////////////////////////////////////////////////////////
00050 void TexMatrixAttrib::
00051 issue(GraphicsStateGuardianBase *gsg) const {
00052   gsg->issue_tex_matrix(this);
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: TexMatrixAttrib::output
00057 //       Access: Public, Virtual
00058 //  Description: 
00059 ////////////////////////////////////////////////////////////////////
00060 void TexMatrixAttrib::
00061 output(ostream &out) const {
00062   out << get_type() << ":(" << get_mat() << ")";
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: TexMatrixAttrib::compare_to_impl
00067 //       Access: Protected, Virtual
00068 //  Description: Intended to be overridden by derived TexMatrixAttrib
00069 //               types to return a unique number indicating whether
00070 //               this TexMatrixAttrib is equivalent to the other one.
00071 //
00072 //               This should return 0 if the two TexMatrixAttrib objects
00073 //               are equivalent, a number less than zero if this one
00074 //               should be sorted before the other one, and a number
00075 //               greater than zero otherwise.
00076 //
00077 //               This will only be called with two TexMatrixAttrib
00078 //               objects whose get_type() functions return the same.
00079 ////////////////////////////////////////////////////////////////////
00080 int TexMatrixAttrib::
00081 compare_to_impl(const RenderAttrib *other) const {
00082   const TexMatrixAttrib *ta;
00083   DCAST_INTO_R(ta, other, 0);
00084   return _mat.compare_to(ta->_mat);
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: TexMatrixAttrib::compose_impl
00089 //       Access: Protected, Virtual
00090 //  Description: Intended to be overridden by derived RenderAttrib
00091 //               types to specify how two consecutive RenderAttrib
00092 //               objects of the same type interact.
00093 //
00094 //               This should return the result of applying the other
00095 //               RenderAttrib to a node in the scene graph below this
00096 //               RenderAttrib, which was already applied.  In most
00097 //               cases, the result is the same as the other
00098 //               RenderAttrib (that is, a subsequent RenderAttrib
00099 //               completely replaces the preceding one).  On the other
00100 //               hand, some kinds of RenderAttrib (for instance,
00101 //               ColorTransformAttrib) might combine in meaningful
00102 //               ways.
00103 ////////////////////////////////////////////////////////////////////
00104 CPT(RenderAttrib) TexMatrixAttrib::
00105 compose_impl(const RenderAttrib *other) const {
00106   const TexMatrixAttrib *ta;
00107   DCAST_INTO_R(ta, other, 0);
00108   LMatrix4f new_mat = ta->_mat * _mat;
00109 
00110   TexMatrixAttrib *attrib = new TexMatrixAttrib(new_mat);
00111   return return_new(attrib);
00112 }
00113 
00114 ////////////////////////////////////////////////////////////////////
00115 //     Function: TexMatrixAttrib::invert_compose_impl
00116 //       Access: Protected, Virtual
00117 //  Description: Intended to be overridden by derived RenderAttrib
00118 //               types to specify how two consecutive RenderAttrib
00119 //               objects of the same type interact.
00120 //
00121 //               See invert_compose() and compose_impl().
00122 ////////////////////////////////////////////////////////////////////
00123 CPT(RenderAttrib) TexMatrixAttrib::
00124 invert_compose_impl(const RenderAttrib *other) const {
00125   const TexMatrixAttrib *ta;
00126   DCAST_INTO_R(ta, other, 0);
00127   LMatrix4f new_mat;
00128   new_mat.invert_from(_mat);
00129   new_mat = ta->_mat * new_mat;
00130 
00131   TexMatrixAttrib *attrib = new TexMatrixAttrib(new_mat);
00132   return return_new(attrib);
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: TexMatrixAttrib::make_default_impl
00137 //       Access: Protected, Virtual
00138 //  Description: Intended to be overridden by derived TexMatrixAttrib
00139 //               types to specify what the default property for a
00140 //               TexMatrixAttrib of this type should be.
00141 //
00142 //               This should return a newly-allocated TexMatrixAttrib of
00143 //               the same type that corresponds to whatever the
00144 //               standard default for this kind of TexMatrixAttrib is.
00145 ////////////////////////////////////////////////////////////////////
00146 RenderAttrib *TexMatrixAttrib::
00147 make_default_impl() const {
00148   return new TexMatrixAttrib(LMatrix4f::ident_mat());
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: TexMatrixAttrib::register_with_read_factory
00153 //       Access: Public, Static
00154 //  Description: Tells the BamReader how to create objects of type
00155 //               TexMatrixAttrib.
00156 ////////////////////////////////////////////////////////////////////
00157 void TexMatrixAttrib::
00158 register_with_read_factory() {
00159   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: TexMatrixAttrib::write_datagram
00164 //       Access: Public, Virtual
00165 //  Description: Writes the contents of this object to the datagram
00166 //               for shipping out to a Bam file.
00167 ////////////////////////////////////////////////////////////////////
00168 void TexMatrixAttrib::
00169 write_datagram(BamWriter *manager, Datagram &dg) {
00170   RenderAttrib::write_datagram(manager, dg);
00171 
00172   _mat.write_datagram(dg);
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: TexMatrixAttrib::make_from_bam
00177 //       Access: Protected, Static
00178 //  Description: This function is called by the BamReader's factory
00179 //               when a new object of type TexMatrixAttrib is encountered
00180 //               in the Bam file.  It should create the TexMatrixAttrib
00181 //               and extract its information from the file.
00182 ////////////////////////////////////////////////////////////////////
00183 TypedWritable *TexMatrixAttrib::
00184 make_from_bam(const FactoryParams &params) {
00185   TexMatrixAttrib *attrib = new TexMatrixAttrib(LMatrix4f::ident_mat());
00186   DatagramIterator scan;
00187   BamReader *manager;
00188 
00189   parse_params(params, scan, manager);
00190   attrib->fillin(scan, manager);
00191 
00192   return attrib;
00193 }
00194 
00195 ////////////////////////////////////////////////////////////////////
00196 //     Function: TexMatrixAttrib::fillin
00197 //       Access: Protected
00198 //  Description: This internal function is called by make_from_bam to
00199 //               read in all of the relevant data from the BamFile for
00200 //               the new TexMatrixAttrib.
00201 ////////////////////////////////////////////////////////////////////
00202 void TexMatrixAttrib::
00203 fillin(DatagramIterator &scan, BamReader *manager) {
00204   RenderAttrib::fillin(scan, manager);
00205 
00206   _mat.read_datagram(scan);
00207 }

Generated on Fri May 2 00:42:26 2003 for Panda by doxygen1.3