Panda3D
fltTransformGeneralMatrix.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 fltTransformGeneralMatrix.cxx
10  * @author drose
11  * @date 2000-08-24
12  */
13 
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 
18 TypeHandle FltTransformGeneralMatrix::_type_handle;
19 
20 /**
21  *
22  */
23 FltTransformGeneralMatrix::
24 FltTransformGeneralMatrix(FltHeader *header) : FltTransformRecord(header) {
25 }
26 
27 /**
28  * Directly sets the general matrix.
29  */
31 set_matrix(const LMatrix4d &matrix) {
32  _matrix = matrix;
33 }
34 
35 /**
36  * Directly sets the general matrix.
37  */
39 set_matrix(const LMatrix4f &matrix) {
40  _matrix = LCAST(double, matrix);
41 }
42 
43 /**
44  * Fills in the information in this record based on the information given in
45  * the indicated datagram, whose opcode has already been read. Returns true
46  * on success, false if the datagram is invalid.
47  */
48 bool FltTransformGeneralMatrix::
49 extract_record(FltRecordReader &reader) {
50  if (!FltTransformRecord::extract_record(reader)) {
51  return false;
52  }
53 
54  nassertr(reader.get_opcode() == FO_general_matrix, false);
55  DatagramIterator &iterator = reader.get_iterator();
56 
57  for (int r = 0; r < 4; r++) {
58  for (int c = 0; c < 4; c++) {
59  _matrix(r, c) = iterator.get_be_float32();
60  }
61  }
62 
63  check_remaining_size(iterator);
64  return true;
65 }
66 
67 /**
68  * Fills up the current record on the FltRecordWriter with data for this
69  * record, but does not advance the writer. Returns true on success, false if
70  * there is some error.
71  */
72 bool FltTransformGeneralMatrix::
73 build_record(FltRecordWriter &writer) const {
74  if (!FltTransformRecord::build_record(writer)) {
75  return false;
76  }
77 
78  writer.set_opcode(FO_general_matrix);
79  Datagram &datagram = writer.update_datagram();
80 
81  for (int r = 0; r < 4; r++) {
82  for (int c = 0; c < 4; c++) {
83  datagram.add_be_float32(_matrix(r, c));
84  }
85  }
86 
87  return true;
88 }
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
PN_float32 get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
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:44
void set_matrix(const LMatrix4d &matrix)
Directly sets the general matrix.
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
Definition: datagram.I:200
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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