15 #include "fltTransformRotateScale.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
19 #include "mathNumbers.h"
22 TypeHandle FltTransformRotateScale::_type_handle;
29 FltTransformRotateScale::
31 _center.set(0.0, 0.0, 0.0);
32 _reference_point.set(0.0, 0.0, 0.0);
33 _to_point.set(0.0, 0.0, 0.0);
53 const LPoint3d &to_point,
bool axis_scale) {
55 _reference_point = reference_point;
58 LVector3d v1 = _reference_point - _center;
62 acos(dot(normalize(v1), normalize(v2))) * 180.0 / MathNumbers::pi;
65 _axis_scale = length(v1);
68 _overall_scale = length(v1);
80 const LPoint3d &FltTransformRotateScale::
90 const LPoint3d &FltTransformRotateScale::
91 get_reference_point()
const {
92 return _reference_point;
100 const LPoint3d &FltTransformRotateScale::
101 get_to_point()
const {
112 return _overall_scale;
141 void FltTransformRotateScale::
143 LVector3d v1 = _reference_point - _center;
145 LVector3d rotate_axis = normalize(cross(v1, v2));
151 look_at(r1, v1, rotate_axis, CS_zup_right);
171 bool FltTransformRotateScale::
173 if (!FltTransformRecord::extract_record(reader)) {
177 nassertr(reader.
get_opcode() == FO_rotate_and_scale,
false);
182 _center[0] = iterator.get_be_float64();
183 _center[1] = iterator.get_be_float64();
184 _center[2] = iterator.get_be_float64();
185 _reference_point[0] = iterator.get_be_float64();
186 _reference_point[1] = iterator.get_be_float64();
187 _reference_point[2] = iterator.get_be_float64();
188 _to_point[0] = iterator.get_be_float64();
189 _to_point[1] = iterator.get_be_float64();
190 _to_point[2] = iterator.get_be_float64();
191 _overall_scale = iterator.get_be_float32();
192 _axis_scale = iterator.get_be_float32();
193 _angle = iterator.get_be_float32();
195 iterator.skip_bytes(4);
211 bool FltTransformRotateScale::
213 if (!FltTransformRecord::build_record(writer)) {
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
This is a 4-by-4 transform matrix.
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
static LMatrix4d rotate_mat(double angle, const LVecBase3d &axis, CoordinateSystem cs=CS_default)
Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vect...
static LMatrix4d scale_mat(const LVecBase3d &scale)
Returns a matrix that applies the indicated scale in each of the three axes.
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.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
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 ...
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...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
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 ...