Panda3D

stTransform.cxx

00001 // Filename: stTransform.cxx
00002 // Created by:  drose (06Oct10)
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 "stTransform.h"
00016 
00017 STTransform STTransform::_ident_mat;
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: STTransform::Constructor
00021 //       Access: Published
00022 //  Description: This constructor accepts a Panda TransformState, for
00023 //               instance as extracted from the scene graph.
00024 ////////////////////////////////////////////////////////////////////
00025 STTransform::
00026 STTransform(const TransformState *trans) {
00027 #ifndef NDEBUG
00028   // Ensure these are initialized to reasonable values in case we fail
00029   // an assertion below.
00030   _pos.set(0.0f, 0.0f, 0.0f);
00031   _rotate = 0.0f;
00032   _scale = 1.0f;
00033 #endif
00034 
00035   nassertv(trans->has_components());
00036   _pos = trans->get_pos();
00037 
00038   const LVecBase3 &hpr = trans->get_hpr();
00039   nassertv(IS_NEARLY_ZERO(hpr[1]) && IS_NEARLY_ZERO(hpr[2]));
00040   _rotate = hpr[0];
00041 
00042   nassertv(trans->has_uniform_scale());
00043   _scale = trans->get_uniform_scale();
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: STTransform::output
00048 //       Access: Published
00049 //  Description: 
00050 ////////////////////////////////////////////////////////////////////
00051 void STTransform::
00052 output(ostream &out) const {
00053   out << "STTransform(" << _pos << ", " << _rotate << ", " << _scale << ")";
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: STTransform::write_datagram
00058 //       Access: Public
00059 //  Description: Writes the contents of this object to the datagram
00060 //               for shipping out to a Bam file.
00061 ////////////////////////////////////////////////////////////////////
00062 void STTransform::
00063 write_datagram(BamWriter *manager, Datagram &dg) {
00064   _pos.write_datagram(dg);
00065   dg.add_stdfloat(_rotate);
00066   dg.add_stdfloat(_scale);
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: STTransform::fillin
00071 //       Access: Public
00072 //  Description: This internal function is called by make_from_bam to
00073 //               read in all of the relevant data from the BamFile for
00074 //               the new SpeedTreeNode.
00075 ////////////////////////////////////////////////////////////////////
00076 void STTransform::
00077 fillin(DatagramIterator &scan, BamReader *manager) {
00078   _pos.read_datagram(scan);
00079   _rotate = scan.get_stdfloat();
00080   _scale = scan.get_stdfloat();
00081 }
 All Classes Functions Variables Enumerations