Panda3D
stTransform.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 stTransform.cxx
10  * @author drose
11  * @date 2010-10-06
12  */
13 
14 #include "stTransform.h"
15 
16 STTransform STTransform::_ident_mat;
17 
18 /**
19  * This constructor accepts a Panda TransformState, for instance as extracted
20  * from the scene graph.
21  */
23 STTransform(const TransformState *trans) {
24 #ifndef NDEBUG
25  // Ensure these are initialized to reasonable values in case we fail an
26  // assertion below.
27  _pos.set(0.0f, 0.0f, 0.0f);
28  _rotate = 0.0f;
29  _scale = 1.0f;
30 #endif
31 
32  nassertv(trans->has_components());
33  _pos = trans->get_pos();
34 
35  const LVecBase3 &hpr = trans->get_hpr();
36  nassertv(IS_NEARLY_ZERO(hpr[1]) && IS_NEARLY_ZERO(hpr[2]));
37  _rotate = hpr[0];
38 
39  nassertv(trans->has_uniform_scale());
40  _scale = trans->get_uniform_scale();
41 }
42 
43 /**
44  *
45  */
46 void STTransform::
47 output(std::ostream &out) const {
48  out << "STTransform(" << _pos << ", " << _rotate << ", " << _scale << ")";
49 }
50 
51 /**
52  * Writes the contents of this object to the datagram for shipping out to a
53  * Bam file.
54  */
55 void STTransform::
57  _pos.write_datagram(dg);
58  dg.add_stdfloat(_rotate);
59  dg.add_stdfloat(_scale);
60 }
61 
62 /**
63  * This internal function is called by make_from_bam to read in all of the
64  * relevant data from the BamFile for the new SpeedTreeNode.
65  */
66 void STTransform::
67 fillin(DatagramIterator &scan, BamReader *manager) {
68  _pos.read_datagram(scan);
69  _rotate = scan.get_stdfloat();
70  _scale = scan.get_stdfloat();
71 }
Indicates a coordinate-system transform on vertices.
bool has_components() const
Returns true if the transform can be described by separate pos, hpr, and scale components.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
STTransform()
The default constructor creates an identity transform.
Definition: stTransform.I:18
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:133
void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
Definition: stTransform.cxx:67
get_pos
Returns the pos component of the transform.
get_hpr
Returns the rotation component of the transform as a trio of Euler angles.
PN_stdfloat get_uniform_scale() const
Returns the scale component of the transform, as a single number.
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: stTransform.cxx:56
bool has_uniform_scale() const
Returns true if the scale is uniform across all three axes (and therefore can be expressed as a singl...