Panda3D

fltTransformTranslate.cxx

00001 // Filename: fltTransformTranslate.cxx
00002 // Created by:  drose (30Aug00)
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 "fltTransformTranslate.h"
00016 #include "fltRecordReader.h"
00017 #include "fltRecordWriter.h"
00018 
00019 TypeHandle FltTransformTranslate::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: FltTransformTranslate::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 FltTransformTranslate::
00027 FltTransformTranslate(FltHeader *header) : FltTransformRecord(header) {
00028   _from.set(0.0, 0.0, 0.0);
00029   _delta.set(0.0, 0.0, 0.0);
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: FltTransformTranslate::set
00034 //       Access: Public
00035 //  Description: Defines the translation.  The "from" point seems to
00036 //               be pretty much ignored.
00037 ////////////////////////////////////////////////////////////////////
00038 void FltTransformTranslate::
00039 set(const LPoint3d &from, const LVector3d &delta) {
00040   _from = from;
00041   _delta = delta;
00042 
00043   recompute_matrix();
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: FltTransformTranslate::get_from
00048 //       Access: Public
00049 //  Description: Returns the reference point of the translation.  This
00050 //               is largely meaningless.
00051 ////////////////////////////////////////////////////////////////////
00052 const LPoint3d &FltTransformTranslate::
00053 get_from() const {
00054   return _from;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: FltTransformTranslate::get_delta
00059 //       Access: Public
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 const LVector3d &FltTransformTranslate::
00063 get_delta() const {
00064   return _delta;
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: FltTransformTranslate::recompute_matrix
00069 //       Access: Private
00070 //  Description:
00071 ////////////////////////////////////////////////////////////////////
00072 void FltTransformTranslate::
00073 recompute_matrix() {
00074   _matrix = LMatrix4d::translate_mat(_delta);
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: FltTransformTranslate::extract_record
00079 //       Access: Protected, Virtual
00080 //  Description: Fills in the information in this record based on the
00081 //               information given in the indicated datagram, whose
00082 //               opcode has already been read.  Returns true on
00083 //               success, false if the datagram is invalid.
00084 ////////////////////////////////////////////////////////////////////
00085 bool FltTransformTranslate::
00086 extract_record(FltRecordReader &reader) {
00087   if (!FltTransformRecord::extract_record(reader)) {
00088     return false;
00089   }
00090 
00091   nassertr(reader.get_opcode() == FO_translate, false);
00092   DatagramIterator &iterator = reader.get_iterator();
00093 
00094   iterator.skip_bytes(4);   // Undocumented additional padding.
00095 
00096   _from[0] = iterator.get_be_float64();
00097   _from[1] = iterator.get_be_float64();
00098   _from[2] = iterator.get_be_float64();
00099   _delta[0] = iterator.get_be_float64();
00100   _delta[1] = iterator.get_be_float64();
00101   _delta[2] = iterator.get_be_float64();
00102 
00103   //  iterator.skip_bytes(4);   // Undocumented additional padding.
00104 
00105   recompute_matrix();
00106 
00107   check_remaining_size(iterator);
00108   return true;
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: FltTransformTranslate::build_record
00113 //       Access: Protected, Virtual
00114 //  Description: Fills up the current record on the FltRecordWriter with
00115 //               data for this record, but does not advance the
00116 //               writer.  Returns true on success, false if there is
00117 //               some error.
00118 ////////////////////////////////////////////////////////////////////
00119 bool FltTransformTranslate::
00120 build_record(FltRecordWriter &writer) const {
00121   if (!FltTransformRecord::build_record(writer)) {
00122     return false;
00123   }
00124 
00125   writer.set_opcode(FO_translate);
00126   Datagram &datagram = writer.update_datagram();
00127 
00128   datagram.pad_bytes(4);   // Undocumented additional padding.
00129 
00130   datagram.add_be_float64(_from[0]);
00131   datagram.add_be_float64(_from[1]);
00132   datagram.add_be_float64(_from[2]);
00133   datagram.add_be_float64(_delta[0]);
00134   datagram.add_be_float64(_delta[1]);
00135   datagram.add_be_float64(_delta[2]);
00136 
00137   //  datagram.pad_bytes(4);   // Undocumented additional padding.
00138 
00139   return true;
00140 }
00141 
 All Classes Functions Variables Enumerations