Panda3D

Loading...
Searching...
No Matches
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 */
22 STTransform::
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::
47output(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::
56 write_datagram(BamWriter *manager, Datagram &dg) {
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}
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::get_stdfloat
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
Definition datagramIterator.I:242
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Datagram::add_stdfloat
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
STTransform
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition stTransform.h:26
STTransform::STTransform
STTransform()
The default constructor creates an identity transform.
Definition stTransform.I:18
STTransform::fillin
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
STTransform::write_datagram
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
TransformState::has_uniform_scale
bool has_uniform_scale() const
Returns true if the scale is uniform across all three axes (and therefore can be expressed as a singl...
Definition transformState.I:339
TransformState::get_hpr
get_hpr
Returns the rotation component of the transform as a trio of Euler angles.
Definition transformState.h:163
TransformState::has_components
bool has_components() const
Returns true if the transform can be described by separate pos, hpr, and scale components.
Definition transformState.I:246
TransformState::get_uniform_scale
PN_stdfloat get_uniform_scale() const
Returns the scale component of the transform, as a single number.
Definition transformState.I:439
TransformState::get_pos
get_pos
Returns the pos component of the transform.
Definition transformState.h:162
stTransform.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.