Panda3D
fltTransformRotateAboutEdge.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 fltTransformRotateAboutEdge.cxx
10  * @author drose
11  * @date 2000-08-30
12  */
13 
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 
18 TypeHandle FltTransformRotateAboutEdge::_type_handle;
19 
20 /**
21  *
22  */
23 FltTransformRotateAboutEdge::
24 FltTransformRotateAboutEdge(FltHeader *header) : FltTransformRecord(header) {
25  _point_a.set(0.0, 0.0, 0.0);
26  _point_b.set(1.0, 0.0, 0.0);
27  _angle = 0.0;
28 }
29 
30 /**
31  * Defines the rotation. The angle is given in degrees, counterclockwise
32  * about the axis as seen from point a.
33  */
35 set(const LPoint3d &point_a, const LPoint3d &point_b, PN_stdfloat angle) {
36  _point_a = point_a;
37  _point_b = point_b;
38  _angle = angle;
39 
40  recompute_matrix();
41 }
42 
43 /**
44  *
45  */
46 const LPoint3d &FltTransformRotateAboutEdge::
47 get_point_a() const {
48  return _point_a;
49 }
50 
51 /**
52  *
53  */
54 const LPoint3d &FltTransformRotateAboutEdge::
55 get_point_b() const {
56  return _point_b;
57 }
58 
59 /**
60  * Returns the angle of rotation, in degrees counterclockwise about the axis
61  * as seen from point a.
62  */
64 get_angle() const {
65  return _angle;
66 }
67 
68 /**
69  *
70  */
71 void FltTransformRotateAboutEdge::
72 recompute_matrix() {
73  if (_point_a == _point_b) {
74  // Degenerate case.
75  _matrix = LMatrix4d::ident_mat();
76  } else {
77  LVector3d axis = _point_b - _point_a;
78  _matrix =
79  LMatrix4d::translate_mat(-_point_a) *
80  LMatrix4d::rotate_mat(_angle, normalize(axis), CS_zup_right) *
81  LMatrix4d::translate_mat(_point_a);
82  }
83 }
84 
85 /**
86  * Fills in the information in this record based on the information given in
87  * the indicated datagram, whose opcode has already been read. Returns true
88  * on success, false if the datagram is invalid.
89  */
90 bool FltTransformRotateAboutEdge::
91 extract_record(FltRecordReader &reader) {
92  if (!FltTransformRecord::extract_record(reader)) {
93  return false;
94  }
95 
96  nassertr(reader.get_opcode() == FO_rotate_about_edge, false);
97  DatagramIterator &iterator = reader.get_iterator();
98 
99  iterator.skip_bytes(4); // Undocumented additional padding.
100 
101  _point_a[0] = iterator.get_be_float64();
102  _point_a[1] = iterator.get_be_float64();
103  _point_a[2] = iterator.get_be_float64();
104  _point_b[0] = iterator.get_be_float64();
105  _point_b[1] = iterator.get_be_float64();
106  _point_b[2] = iterator.get_be_float64();
107  _angle = iterator.get_be_float32();
108 
109  iterator.skip_bytes(4); // Undocumented additional padding.
110 
111  recompute_matrix();
112 
113  check_remaining_size(iterator);
114  return true;
115 }
116 
117 /**
118  * Fills up the current record on the FltRecordWriter with data for this
119  * record, but does not advance the writer. Returns true on success, false if
120  * there is some error.
121  */
122 bool FltTransformRotateAboutEdge::
123 build_record(FltRecordWriter &writer) const {
124  if (!FltTransformRecord::build_record(writer)) {
125  return false;
126  }
127 
128  writer.set_opcode(FO_rotate_about_edge);
129  Datagram &datagram = writer.update_datagram();
130 
131  datagram.pad_bytes(4); // Undocumented additional padding.
132 
133  datagram.add_be_float64(_point_a[0]);
134  datagram.add_be_float64(_point_a[1]);
135  datagram.add_be_float64(_point_a[2]);
136  datagram.add_be_float64(_point_b[0]);
137  datagram.add_be_float64(_point_b[1]);
138  datagram.add_be_float64(_point_b[2]);
139  datagram.add_be_float32(_angle);
140 
141  datagram.pad_bytes(4); // Undocumented additional padding.
142 
143  return true;
144 }
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
void set(const LPoint3d &point_a, const LPoint3d &point_b, PN_stdfloat angle)
Defines the rotation.
PN_stdfloat get_angle() const
Returns the angle of rotation, in degrees counterclockwise about the axis as seen from point a.
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 add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
Definition: datagram.I:200
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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