Panda3D
 All Classes Functions Variables Enumerations
fltCurve.cxx
1 // Filename: fltCurve.cxx
2 // Created by: drose (28Feb01)
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 "fltCurve.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 #include "fltHeader.h"
19 #include "fltMaterial.h"
20 
21 TypeHandle FltCurve::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: FltCurve::Constructor
25 // Access: Public
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 FltCurve::
29 FltCurve(FltHeader *header) : FltBeadID(header) {
30  _curve_type = CT_b_spline;
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: FltCurve::extract_record
35 // Access: Protected, Virtual
36 // Description: Fills in the information in this bead based on the
37 // information given in the indicated datagram, whose
38 // opcode has already been read. Returns true on
39 // success, false if the datagram is invalid.
40 ////////////////////////////////////////////////////////////////////
41 bool FltCurve::
42 extract_record(FltRecordReader &reader) {
43  if (!FltBeadID::extract_record(reader)) {
44  return false;
45  }
46 
47  nassertr(reader.get_opcode() == FO_curve, false);
48  DatagramIterator &iterator = reader.get_iterator();
49 
50  iterator.skip_bytes(4);
51  _curve_type = (CurveType)iterator.get_be_int32();
52 
53  int num_control_points = iterator.get_be_int32();
54  iterator.skip_bytes(8);
55  for (int i = 0; i < num_control_points; i++) {
56  double x = iterator.get_be_float64();
57  double y = iterator.get_be_float64();
58  double z = iterator.get_be_float64();
59  _control_points.push_back(LPoint3d(x, y, z));
60  }
61 
62  check_remaining_size(iterator);
63  return true;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: FltCurve::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 FltCurve::
75 build_record(FltRecordWriter &writer) const {
76  if (!FltBeadID::build_record(writer)) {
77  return false;
78  }
79 
80  writer.set_opcode(FO_curve);
81  Datagram &datagram = writer.update_datagram();
82 
83  datagram.pad_bytes(4);
84  datagram.add_be_int32(_curve_type);
85  datagram.add_be_int32(_control_points.size());
86  datagram.pad_bytes(8);
87 
88  ControlPoints::const_iterator ci;
89  for (ci = _control_points.begin(); ci != _control_points.end(); ++ci) {
90  const LPoint3d &p = (*ci);
91  datagram.add_be_float64(p[0]);
92  datagram.add_be_float64(p[1]);
93  datagram.add_be_float64(p[2]);
94  }
95 
96  return true;
97 }
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
A base class for any of a broad family of flt beads that include an ID.
Definition: fltBeadID.h:27
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:111
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_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:339
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
void add_be_int32(PN_int32 value)
Adds a signed 32-bit big-endian integer to the datagram.
Definition: datagram.I:267
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 point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:531
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