Panda3D
stTransform.I
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.I
10  * @author drose
11  * @date 2010-10-06
12  */
13 
14 /**
15  * The default constructor creates an identity transform.
16  */
17 INLINE STTransform::
19  _pos(0.0f, 0.0f, 0.0f),
20  _rotate(0.0f),
21  _scale(1.0f)
22 {
23 }
24 
25 /**
26  * Construct a transform with componentwise inputs.
27  */
28 INLINE STTransform::
29 STTransform(const LPoint3 &pos, PN_stdfloat rotate, PN_stdfloat scale) :
30  _pos(pos),
31  _rotate(rotate),
32  _scale(scale)
33 {
34 }
35 
36 /**
37  * Construct a transform with componentwise inputs.
38  */
39 INLINE STTransform::
40 STTransform(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat rotate, PN_stdfloat scale) :
41  _pos(x, y, z),
42  _rotate(rotate),
43  _scale(scale)
44 {
45 }
46 
47 /**
48  *
49  */
50 INLINE STTransform::
51 STTransform(const STTransform &copy) :
52  _pos(copy._pos),
53  _rotate(copy._rotate),
54  _scale(copy._scale)
55 {
56 }
57 
58 /**
59  *
60  */
61 INLINE void STTransform::
62 operator = (const STTransform &copy) {
63  _pos = copy._pos;
64  _rotate = copy._rotate;
65  _scale = copy._scale;
66 }
67 
68 /**
69  * This is used internally to construct an STTransform from a
70  * SpeedTree::CInstance object.
71  */
72 INLINE STTransform::
73 STTransform(const SpeedTree::CInstance &instance) {
74  const SpeedTree::Vec3 &pos = instance.GetPos();
75  _pos.set(pos[0], pos[1], pos[2]);
76  _rotate = rad_2_deg(instance.GetRotationAngle());
77  _scale = instance.GetScale();
78 }
79 
80 /**
81  * This is used internally to convert an STTransform into a
82  * SpeedTree::CInstance object.
83  */
84 INLINE STTransform::
85 operator SpeedTree::CInstance () const {
86  SpeedTree::CInstance instance;
87  instance.SetPos(SpeedTree::Vec3(_pos[0], _pos[1], _pos[2]));
88  instance.SetRotation(deg_2_rad(_rotate));
89  instance.SetScale(_scale);
90  return instance;
91 }
92 
93 /**
94  * This is used internally to convert an STTransform into a TransformState
95  * pointer.
96  */
97 INLINE STTransform::
98 operator CPT(TransformState) () const {
99  return TransformState::make_pos_hpr_scale(_pos,
100  LVecBase3(_rotate, 0.0f, 0.0f),
101  LVecBase3(_scale, _scale, _scale));
102 }
103 
104 /**
105  * Returns a global identity transform object.
106  */
107 INLINE const STTransform &STTransform::
109  return _ident_mat;
110 }
111 
112 /**
113  * Replaces the translation component.
114  */
115 INLINE void STTransform::
116 set_pos(const LPoint3 &pos) {
117  _pos = pos;
118 }
119 
120 /**
121  * Returns the translation component.
122  */
123 INLINE const LPoint3 &STTransform::
124 get_pos() const {
125  return _pos;
126 }
127 
128 /**
129  * Replaces the rotation component. Accepts a rotation in degrees counter-
130  * clockwise around the vertical axis.
131  */
132 INLINE void STTransform::
133 set_rotate(PN_stdfloat rotate) {
134  _rotate = rotate;
135 }
136 
137 /**
138  * Returns the rotation component, in degrees counter-clockwise around the
139  * vertical axis.
140  */
141 INLINE PN_stdfloat STTransform::
142 get_rotate() const {
143  return _rotate;
144 }
145 
146 /**
147  * Replaces the scale component. Accepts a uniform scale value.
148  */
149 INLINE void STTransform::
150 set_scale(PN_stdfloat scale) {
151  _scale = scale;
152 }
153 
154 /**
155  * Returns the scale component, as a uniform scale value.
156  */
157 INLINE PN_stdfloat STTransform::
158 get_scale() const {
159  return _scale;
160 }
161 
162 /**
163  * Composes these transforms and stores the result in-place.
164  */
165 INLINE void STTransform::
166 operator *= (const STTransform &other) {
167  LQuaternion quat;
168  quat.set_hpr(LVecBase3(_rotate, 0.0f, 0.0f));
169  _pos += quat.xform(other.get_pos()) * _scale;
170  _rotate += other._rotate;
171  _scale *= other._scale;
172 }
173 
174 /**
175  * Composes these transforms and returns the result
176  */
178 operator * (const STTransform &other) const {
179  STTransform result = *this;
180  result *= other;
181  return result;
182 }
Indicates a coordinate-system transform on vertices.
void set_scale(PN_stdfloat scale)
Replaces the scale component.
Definition: stTransform.I:150
const LPoint3 & get_pos() const
Returns the translation component.
Definition: stTransform.I:124
void operator *=(const STTransform &other)
Composes these transforms and stores the result in-place.
Definition: stTransform.I:166
STTransform()
The default constructor creates an identity transform.
Definition: stTransform.I:18
void set_rotate(PN_stdfloat rotate)
Replaces the rotation component.
Definition: stTransform.I:133
STTransform operator *(const STTransform &other) const
Composes these transforms and returns the result.
Definition: stTransform.I:178
PN_stdfloat get_scale() const
Returns the scale component, as a uniform scale value.
Definition: stTransform.I:158
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:26
void set_pos(const LPoint3 &pos)
Replaces the translation component.
Definition: stTransform.I:116
static const STTransform & ident_mat()
Returns a global identity transform object.
Definition: stTransform.I:108
PN_stdfloat get_rotate() const
Returns the rotation component, in degrees counter-clockwise around the vertical axis.
Definition: stTransform.I:142