Panda3D
fltVectorRecord.cxx
1 // Filename: fltVectorRecord.cxx
2 // Created by: drose (30Aug02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "fltVectorRecord.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 TypeHandle FltVectorRecord::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltVectorRecord::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltVectorRecord::
27 FltVectorRecord(FltHeader *header) : FltRecord(header) {
28  _vector.set(0.0f, 0.0f, 0.0f);
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: FltVectorRecord::get_vector
33 // Access: Public
34 // Description: Returns the vector value.
35 ////////////////////////////////////////////////////////////////////
37 get_vector() const {
38  return _vector;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: FltVectorRecord::extract_record
43 // Access: Protected, Virtual
44 // Description: Fills in the information in this record based on the
45 // information given in the indicated datagram, whose
46 // opcode has already been read. Returns true on
47 // success, false if the datagram is invalid.
48 ////////////////////////////////////////////////////////////////////
49 bool FltVectorRecord::
50 extract_record(FltRecordReader &reader) {
51  if (!FltRecord::extract_record(reader)) {
52  return false;
53  }
54 
55  nassertr(reader.get_opcode() == FO_vector, false);
56  DatagramIterator &iterator = reader.get_iterator();
57 
58  _vector[0] = iterator.get_be_float32();
59  _vector[1] = iterator.get_be_float32();
60  _vector[2] = iterator.get_be_float32();
61 
62  check_remaining_size(iterator);
63  return true;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: FltVectorRecord::build_record
68 // Access: Protected, Virtual
69 // Description: Fills up the current record on the FltRecordWriter with
70 // data for this record, but does not advance the
71 // writer. Returns true on success, false if there is
72 // some error.
73 ////////////////////////////////////////////////////////////////////
74 bool FltVectorRecord::
75 build_record(FltRecordWriter &writer) const {
76  if (!FltRecord::build_record(writer)) {
77  return false;
78  }
79 
80  writer.set_opcode(FO_vector);
81  Datagram &datagram = writer.update_datagram();
82 
83  datagram.add_be_float32(_vector[0]);
84  datagram.add_be_float32(_vector[1]);
85  datagram.add_be_float32(_vector[2]);
86 
87  return true;
88 }
89 
const LVector3 & get_vector() const
Returns the vector value.
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
void check_remaining_size(const DatagramIterator &di, const string &name=string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record...
Definition: fltRecord.cxx:313
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
Definition: datagram.I:327
The base class for all kinds of records in a MultiGen OpenFlight file.
Definition: fltRecord.h:40
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43