Panda3D
 All Classes Functions Variables Enumerations
stTransform.cxx
1 // Filename: stTransform.cxx
2 // Created by: drose (06Oct10)
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 "stTransform.h"
16 
17 STTransform STTransform::_ident_mat;
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: STTransform::Constructor
21 // Access: Published
22 // Description: This constructor accepts a Panda TransformState, for
23 // instance as extracted from the scene graph.
24 ////////////////////////////////////////////////////////////////////
26 STTransform(const TransformState *trans) {
27 #ifndef NDEBUG
28  // Ensure these are initialized to reasonable values in case we fail
29  // an assertion below.
30  _pos.set(0.0f, 0.0f, 0.0f);
31  _rotate = 0.0f;
32  _scale = 1.0f;
33 #endif
34 
35  nassertv(trans->has_components());
36  _pos = trans->get_pos();
37 
38  const LVecBase3 &hpr = trans->get_hpr();
39  nassertv(IS_NEARLY_ZERO(hpr[1]) && IS_NEARLY_ZERO(hpr[2]));
40  _rotate = hpr[0];
41 
42  nassertv(trans->has_uniform_scale());
43  _scale = trans->get_uniform_scale();
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: STTransform::output
48 // Access: Published
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 void STTransform::
52 output(ostream &out) const {
53  out << "STTransform(" << _pos << ", " << _rotate << ", " << _scale << ")";
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: STTransform::write_datagram
58 // Access: Public
59 // Description: Writes the contents of this object to the datagram
60 // for shipping out to a Bam file.
61 ////////////////////////////////////////////////////////////////////
62 void STTransform::
64  _pos.write_datagram(dg);
65  dg.add_stdfloat(_rotate);
66  dg.add_stdfloat(_scale);
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: STTransform::fillin
71 // Access: Public
72 // Description: This internal function is called by make_from_bam to
73 // read in all of the relevant data from the BamFile for
74 // the new SpeedTreeNode.
75 ////////////////////////////////////////////////////////////////////
76 void STTransform::
77 fillin(DatagramIterator &scan, BamReader *manager) {
78  _pos.read_datagram(scan);
79  _rotate = scan.get_stdfloat();
80  _scale = scan.get_stdfloat();
81 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
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:122
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
Definition: lvecBase3.h:1373
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
STTransform()
The default constructor creates an identity transform.
Definition: stTransform.I:22
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:240
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:77
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:29
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:43
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
Definition: lvecBase3.h:1355
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:63