00001 // Filename: fltVectorRecord.cxx 00002 // Created by: drose (30Aug02) 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 "fltVectorRecord.h" 00020 #include "fltRecordReader.h" 00021 #include "fltRecordWriter.h" 00022 00023 TypeHandle FltVectorRecord::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: FltVectorRecord::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 FltVectorRecord:: 00031 FltVectorRecord(FltHeader *header) : FltRecord(header) { 00032 _vector.set(0.0f, 0.0f, 0.0f); 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: FltVectorRecord::get_vector 00037 // Access: Public 00038 // Description: Returns the vector value. 00039 //////////////////////////////////////////////////////////////////// 00040 const LVector3f &FltVectorRecord:: 00041 get_vector() const { 00042 return _vector; 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: FltVectorRecord::extract_record 00047 // Access: Protected, Virtual 00048 // Description: Fills in the information in this record based on the 00049 // information given in the indicated datagram, whose 00050 // opcode has already been read. Returns true on 00051 // success, false if the datagram is invalid. 00052 //////////////////////////////////////////////////////////////////// 00053 bool FltVectorRecord:: 00054 extract_record(FltRecordReader &reader) { 00055 if (!FltRecord::extract_record(reader)) { 00056 return false; 00057 } 00058 00059 nassertr(reader.get_opcode() == FO_vector, false); 00060 DatagramIterator &iterator = reader.get_iterator(); 00061 00062 _vector[0] = iterator.get_be_float32(); 00063 _vector[1] = iterator.get_be_float32(); 00064 _vector[2] = iterator.get_be_float32(); 00065 00066 check_remaining_size(iterator); 00067 return true; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: FltVectorRecord::build_record 00072 // Access: Protected, Virtual 00073 // Description: Fills up the current record on the FltRecordWriter with 00074 // data for this record, but does not advance the 00075 // writer. Returns true on success, false if there is 00076 // some error. 00077 //////////////////////////////////////////////////////////////////// 00078 bool FltVectorRecord:: 00079 build_record(FltRecordWriter &writer) const { 00080 if (!FltRecord::build_record(writer)) { 00081 return false; 00082 } 00083 00084 writer.set_opcode(FO_vector); 00085 Datagram &datagram = writer.update_datagram(); 00086 00087 datagram.add_be_float32(_vector[0]); 00088 datagram.add_be_float32(_vector[1]); 00089 datagram.add_be_float32(_vector[2]); 00090 00091 return true; 00092 } 00093