Panda3D
fltTransformTranslate.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 fltTransformTranslate.cxx
10  * @author drose
11  * @date 2000-08-30
12  */
13 
14 #include "fltTransformTranslate.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 
18 TypeHandle FltTransformTranslate::_type_handle;
19 
20 /**
21  *
22  */
23 FltTransformTranslate::
24 FltTransformTranslate(FltHeader *header) : FltTransformRecord(header) {
25  _from.set(0.0, 0.0, 0.0);
26  _delta.set(0.0, 0.0, 0.0);
27 }
28 
29 /**
30  * Defines the translation. The "from" point seems to be pretty much ignored.
31  */
33 set(const LPoint3d &from, const LVector3d &delta) {
34  _from = from;
35  _delta = delta;
36 
37  recompute_matrix();
38 }
39 
40 /**
41  * Returns the reference point of the translation. This is largely
42  * meaningless.
43  */
44 const LPoint3d &FltTransformTranslate::
45 get_from() const {
46  return _from;
47 }
48 
49 /**
50  *
51  */
52 const LVector3d &FltTransformTranslate::
53 get_delta() const {
54  return _delta;
55 }
56 
57 /**
58  *
59  */
60 void FltTransformTranslate::
61 recompute_matrix() {
62  _matrix = LMatrix4d::translate_mat(_delta);
63 }
64 
65 /**
66  * Fills in the information in this record based on the information given in
67  * the indicated datagram, whose opcode has already been read. Returns true
68  * on success, false if the datagram is invalid.
69  */
70 bool FltTransformTranslate::
71 extract_record(FltRecordReader &reader) {
72  if (!FltTransformRecord::extract_record(reader)) {
73  return false;
74  }
75 
76  nassertr(reader.get_opcode() == FO_translate, false);
77  DatagramIterator &iterator = reader.get_iterator();
78 
79  iterator.skip_bytes(4); // Undocumented additional padding.
80 
81  _from[0] = iterator.get_be_float64();
82  _from[1] = iterator.get_be_float64();
83  _from[2] = iterator.get_be_float64();
84  _delta[0] = iterator.get_be_float64();
85  _delta[1] = iterator.get_be_float64();
86  _delta[2] = iterator.get_be_float64();
87 
88  // iterator.skip_bytes(4); Undocumented additional padding.
89 
90  recompute_matrix();
91 
92  check_remaining_size(iterator);
93  return true;
94 }
95 
96 /**
97  * Fills up the current record on the FltRecordWriter with data for this
98  * record, but does not advance the writer. Returns true on success, false if
99  * there is some error.
100  */
101 bool FltTransformTranslate::
102 build_record(FltRecordWriter &writer) const {
103  if (!FltTransformRecord::build_record(writer)) {
104  return false;
105  }
106 
107  writer.set_opcode(FO_translate);
108  Datagram &datagram = writer.update_datagram();
109 
110  datagram.pad_bytes(4); // Undocumented additional padding.
111 
112  datagram.add_be_float64(_from[0]);
113  datagram.add_be_float64(_from[1]);
114  datagram.add_be_float64(_from[2]);
115  datagram.add_be_float64(_delta[0]);
116  datagram.add_be_float64(_delta[1]);
117  datagram.add_be_float64(_delta[2]);
118 
119  // datagram.pad_bytes(4); Undocumented additional padding.
120 
121  return true;
122 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
const LPoint3d & get_from() const
Returns the reference point of the translation.
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:99
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:209
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A base class for a number of types of ancillary records that follow beads and indicate some kind of a...
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:81
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:38
void set(const LPoint3d &from, const LVector3d &delta)
Defines the translation.