Panda3D
fltCurve.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fltCurve.cxx
10  * @author drose
11  * @date 2001-02-28
12  */
13 
14 #include "fltCurve.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 #include "fltHeader.h"
18 #include "fltMaterial.h"
19 
20 TypeHandle FltCurve::_type_handle;
21 
22 /**
23  *
24  */
25 FltCurve::
26 FltCurve(FltHeader *header) : FltBeadID(header) {
27  _curve_type = CT_b_spline;
28 }
29 
30 /**
31  * Fills in the information in this bead based on the information given in the
32  * indicated datagram, whose opcode has already been read. Returns true on
33  * success, false if the datagram is invalid.
34  */
35 bool FltCurve::
36 extract_record(FltRecordReader &reader) {
37  if (!FltBeadID::extract_record(reader)) {
38  return false;
39  }
40 
41  nassertr(reader.get_opcode() == FO_curve, false);
42  DatagramIterator &iterator = reader.get_iterator();
43 
44  iterator.skip_bytes(4);
45  _curve_type = (CurveType)iterator.get_be_int32();
46 
47  int num_control_points = iterator.get_be_int32();
48  iterator.skip_bytes(8);
49  for (int i = 0; i < num_control_points; i++) {
50  double x = iterator.get_be_float64();
51  double y = iterator.get_be_float64();
52  double z = iterator.get_be_float64();
53  _control_points.push_back(LPoint3d(x, y, z));
54  }
55 
56  check_remaining_size(iterator);
57  return true;
58 }
59 
60 /**
61  * Fills up the current record on the FltRecordWriter with data for this
62  * record, but does not advance the writer. Returns true on success, false if
63  * there is some error.
64  */
65 bool FltCurve::
66 build_record(FltRecordWriter &writer) const {
67  if (!FltBeadID::build_record(writer)) {
68  return false;
69  }
70 
71  writer.set_opcode(FO_curve);
72  Datagram &datagram = writer.update_datagram();
73 
74  datagram.pad_bytes(4);
75  datagram.add_be_int32(_curve_type);
76  datagram.add_be_int32(_control_points.size());
77  datagram.pad_bytes(8);
78 
79  ControlPoints::const_iterator ci;
80  for (ci = _control_points.begin(); ci != _control_points.end(); ++ci) {
81  const LPoint3d &p = (*ci);
82  datagram.add_be_float64(p[0]);
83  datagram.add_be_float64(p[1]);
84  datagram.add_be_float64(p[2]);
85  }
86 
87  return true;
88 }
A class to retrieve the individual data elements previously stored in a Datagram.
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
int32_t get_be_int32()
Extracts a signed 32-bit big-endian integer.
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
void add_be_int32(int32_t value)
Adds a signed 32-bit big-endian integer to the datagram.
Definition: datagram.I:154
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:209
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:99
A base class for any of a broad family of flt beads that include an ID.
Definition: fltBeadID.h:24
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
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.
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Definition: fltRecord.cxx:254
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.