Panda3D
 All Classes Functions Variables Enumerations
stTransform.I
1 // Filename: stTransform.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: STTransform::Default Constructor
18 // Access: Published
19 // Description: The default constructor creates an identity transform.
20 ////////////////////////////////////////////////////////////////////
21 INLINE STTransform::
23  _pos(0.0f, 0.0f, 0.0f),
24  _rotate(0.0f),
25  _scale(1.0f)
26 {
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: STTransform::Constructor
31 // Access: Published
32 // Description: Construct a transform with componentwise inputs.
33 ////////////////////////////////////////////////////////////////////
34 INLINE STTransform::
35 STTransform(const LPoint3 &pos, PN_stdfloat rotate, PN_stdfloat scale) :
36  _pos(pos),
37  _rotate(rotate),
38  _scale(scale)
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: STTransform::Constructor
44 // Access: Published
45 // Description: Construct a transform with componentwise inputs.
46 ////////////////////////////////////////////////////////////////////
47 INLINE STTransform::
48 STTransform(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat rotate, PN_stdfloat scale) :
49  _pos(x, y, z),
50  _rotate(rotate),
51  _scale(scale)
52 {
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: STTransform::Copy Constructor
57 // Access: Published
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 INLINE STTransform::
61 STTransform(const STTransform &copy) :
62  _pos(copy._pos),
63  _rotate(copy._rotate),
64  _scale(copy._scale)
65 {
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: STTransform::Copy Assignment Operator
70 // Access: Published
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 INLINE void STTransform::
74 operator = (const STTransform &copy) {
75  _pos = copy._pos;
76  _rotate = copy._rotate;
77  _scale = copy._scale;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: STTransform::CInstance constructor
82 // Access: Public
83 // Description: This is used internally to construct an STTransform
84 // from a SpeedTree::CInstance object.
85 ////////////////////////////////////////////////////////////////////
86 INLINE STTransform::
87 STTransform(const SpeedTree::CInstance &instance) {
88  const SpeedTree::Vec3 &pos = instance.GetPos();
89  _pos.set(pos[0], pos[1], pos[2]);
90  _rotate = rad_2_deg(instance.GetRotationAngle());
91  _scale = instance.GetScale();
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: STTransform::CInstance operator
96 // Access: Public
97 // Description: This is used internally to convert an STTransform
98 // into a SpeedTree::CInstance object.
99 ////////////////////////////////////////////////////////////////////
100 INLINE STTransform::
101 operator SpeedTree::CInstance () const {
102  SpeedTree::CInstance instance;
103  instance.SetPos(SpeedTree::Vec3(_pos[0], _pos[1], _pos[2]));
104  instance.SetRotation(deg_2_rad(_rotate));
105  instance.SetScale(_scale);
106  return instance;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: STTransform::TransformState operator
111 // Access: Public
112 // Description: This is used internally to convert an STTransform
113 // into a TransformState pointer.
114 ////////////////////////////////////////////////////////////////////
115 INLINE STTransform::
116 operator CPT(TransformState) () const {
117  return TransformState::make_pos_hpr_scale(_pos,
118  LVecBase3(_rotate, 0.0f, 0.0f),
119  LVecBase3(_scale, _scale, _scale));
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: STTransform::ident_mat
124 // Access: Published, Static
125 // Description: Returns a global identity transform object.
126 ////////////////////////////////////////////////////////////////////
127 INLINE const STTransform &STTransform::
129  return _ident_mat;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: STTransform::set_pos
134 // Access: Published
135 // Description: Replaces the translation component.
136 ////////////////////////////////////////////////////////////////////
137 INLINE void STTransform::
138 set_pos(const LPoint3 &pos) {
139  _pos = pos;
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: STTransform::get_pos
144 // Access: Published
145 // Description: Returns the translation component.
146 ////////////////////////////////////////////////////////////////////
147 INLINE const LPoint3 &STTransform::
148 get_pos() const {
149  return _pos;
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: STTransform::set_rotate
154 // Access: Published
155 // Description: Replaces the rotation component. Accepts a rotation
156 // in degrees counter-clockwise around the vertical
157 // axis.
158 ////////////////////////////////////////////////////////////////////
159 INLINE void STTransform::
160 set_rotate(PN_stdfloat rotate) {
161  _rotate = rotate;
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: STTransform::get_rotate
166 // Access: Published
167 // Description: Returns the rotation component, in degrees
168 // counter-clockwise around the vertical axis.
169 ////////////////////////////////////////////////////////////////////
170 INLINE PN_stdfloat STTransform::
171 get_rotate() const {
172  return _rotate;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: STTransform::set_scale
177 // Access: Published
178 // Description: Replaces the scale component. Accepts a uniform
179 // scale value.
180 ////////////////////////////////////////////////////////////////////
181 INLINE void STTransform::
182 set_scale(PN_stdfloat scale) {
183  _scale = scale;
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: STTransform::get_scale
188 // Access: Published
189 // Description: Returns the scale component, as a uniform scale
190 // value.
191 ////////////////////////////////////////////////////////////////////
192 INLINE PN_stdfloat STTransform::
193 get_scale() const {
194  return _scale;
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: STTransform::operator *=
199 // Access: Published
200 // Description: Composes these transforms and stores the result
201 // in-place.
202 ////////////////////////////////////////////////////////////////////
203 INLINE void STTransform::
204 operator *= (const STTransform &other) {
205  LQuaternion quat;
206  quat.set_hpr(LVecBase3(_rotate, 0.0f, 0.0f));
207  _pos += quat.xform(other.get_pos()) * _scale;
208  _rotate += other._rotate;
209  _scale *= other._scale;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: STTransform::operator *
214 // Access: Published
215 // Description: Composes these transforms and returns the result/
216 ////////////////////////////////////////////////////////////////////
218 operator * (const STTransform &other) const {
219  STTransform result = *this;
220  result *= other;
221  return result;
222 }
PN_stdfloat get_rotate() const
Returns the rotation component, in degrees counter-clockwise around the vertical axis.
Definition: stTransform.I:171
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
const LPoint3 & get_pos() const
Returns the translation component.
Definition: stTransform.I:148
void set_scale(PN_stdfloat scale)
Replaces the scale component.
Definition: stTransform.I:182
void operator*=(const STTransform &other)
Composes these transforms and stores the result in-place.
Definition: stTransform.I:204
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
STTransform()
The default constructor creates an identity transform.
Definition: stTransform.I:22
void set_rotate(PN_stdfloat rotate)
Replaces the rotation component.
Definition: stTransform.I:160
LVecBase3f xform(const LVecBase3f &v) const
Transforms a 3-d vector by the indicated rotation.
Definition: lquaternion.h:280
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:29
void set_pos(const LPoint3 &pos)
Replaces the translation component.
Definition: stTransform.I:138
This is the base quaternion class.
Definition: lquaternion.h:96
static const STTransform & ident_mat()
Returns a global identity transform object.
Definition: stTransform.I:128
PN_stdfloat get_scale() const
Returns the scale component, as a uniform scale value.
Definition: stTransform.I:193
STTransform operator*(const STTransform &other) const
Composes these transforms and returns the result/.
Definition: stTransform.I:218