Panda3D
 All Classes Functions Variables Enumerations
fltTransformTranslate.cxx
1 // Filename: fltTransformTranslate.cxx
2 // Created by: drose (30Aug00)
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 "fltTransformTranslate.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 TypeHandle FltTransformTranslate::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltTransformTranslate::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltTransformTranslate::
27 FltTransformTranslate(FltHeader *header) : FltTransformRecord(header) {
28  _from.set(0.0, 0.0, 0.0);
29  _delta.set(0.0, 0.0, 0.0);
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: FltTransformTranslate::set
34 // Access: Public
35 // Description: Defines the translation. The "from" point seems to
36 // be pretty much ignored.
37 ////////////////////////////////////////////////////////////////////
39 set(const LPoint3d &from, const LVector3d &delta) {
40  _from = from;
41  _delta = delta;
42 
43  recompute_matrix();
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: FltTransformTranslate::get_from
48 // Access: Public
49 // Description: Returns the reference point of the translation. This
50 // is largely meaningless.
51 ////////////////////////////////////////////////////////////////////
53 get_from() const {
54  return _from;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: FltTransformTranslate::get_delta
59 // Access: Public
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 const LVector3d &FltTransformTranslate::
63 get_delta() const {
64  return _delta;
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: FltTransformTranslate::recompute_matrix
69 // Access: Private
70 // Description:
71 ////////////////////////////////////////////////////////////////////
72 void FltTransformTranslate::
73 recompute_matrix() {
74  _matrix = LMatrix4d::translate_mat(_delta);
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: FltTransformTranslate::extract_record
79 // Access: Protected, Virtual
80 // Description: Fills in the information in this record based on the
81 // information given in the indicated datagram, whose
82 // opcode has already been read. Returns true on
83 // success, false if the datagram is invalid.
84 ////////////////////////////////////////////////////////////////////
85 bool FltTransformTranslate::
86 extract_record(FltRecordReader &reader) {
87  if (!FltTransformRecord::extract_record(reader)) {
88  return false;
89  }
90 
91  nassertr(reader.get_opcode() == FO_translate, false);
92  DatagramIterator &iterator = reader.get_iterator();
93 
94  iterator.skip_bytes(4); // Undocumented additional padding.
95 
96  _from[0] = iterator.get_be_float64();
97  _from[1] = iterator.get_be_float64();
98  _from[2] = iterator.get_be_float64();
99  _delta[0] = iterator.get_be_float64();
100  _delta[1] = iterator.get_be_float64();
101  _delta[2] = iterator.get_be_float64();
102 
103  // iterator.skip_bytes(4); // Undocumented additional padding.
104 
105  recompute_matrix();
106 
107  check_remaining_size(iterator);
108  return true;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: FltTransformTranslate::build_record
113 // Access: Protected, Virtual
114 // Description: Fills up the current record on the FltRecordWriter with
115 // data for this record, but does not advance the
116 // writer. Returns true on success, false if there is
117 // some error.
118 ////////////////////////////////////////////////////////////////////
119 bool FltTransformTranslate::
120 build_record(FltRecordWriter &writer) const {
121  if (!FltTransformRecord::build_record(writer)) {
122  return false;
123  }
124 
125  writer.set_opcode(FO_translate);
126  Datagram &datagram = writer.update_datagram();
127 
128  datagram.pad_bytes(4); // Undocumented additional padding.
129 
130  datagram.add_be_float64(_from[0]);
131  datagram.add_be_float64(_from[1]);
132  datagram.add_be_float64(_from[2]);
133  datagram.add_be_float64(_delta[0]);
134  datagram.add_be_float64(_delta[1]);
135  datagram.add_be_float64(_delta[2]);
136 
137  // datagram.pad_bytes(4); // Undocumented additional padding.
138 
139  return true;
140 }
141 
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...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
static LMatrix4d translate_mat(const LVecBase3d &trans)
Returns a matrix that applies the indicated translation.
Definition: lmatrix.h:6662
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
const LPoint3d & get_from() const
Returns the reference point of the translation.
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:746
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 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: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
void set(const LPoint3d &from, const LVector3d &delta)
Defines the translation.