Panda3D
Loading...
Searching...
No Matches
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 */
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 */
29STTransform(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 */
40STTransform(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 */
50INLINE STTransform::
51STTransform(const STTransform &copy) :
52 _pos(copy._pos),
53 _rotate(copy._rotate),
54 _scale(copy._scale)
55{
56}
57
58/**
59 *
60 */
61INLINE void STTransform::
62operator = (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 */
73STTransform(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 */
84INLINE STTransform::
85operator 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 */
97INLINE STTransform::
98operator 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 */
108ident_mat() {
109 return _ident_mat;
110}
111
112/**
113 * Replaces the translation component.
114 */
115INLINE void STTransform::
116set_pos(const LPoint3 &pos) {
117 _pos = pos;
118}
119
120/**
121 * Returns the translation component.
122 */
123INLINE const LPoint3 &STTransform::
124get_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 */
132INLINE void STTransform::
133set_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 */
141INLINE PN_stdfloat STTransform::
142get_rotate() const {
143 return _rotate;
144}
145
146/**
147 * Replaces the scale component. Accepts a uniform scale value.
148 */
149INLINE void STTransform::
150set_scale(PN_stdfloat scale) {
151 _scale = scale;
152}
153
154/**
155 * Returns the scale component, as a uniform scale value.
156 */
157INLINE PN_stdfloat STTransform::
158get_scale() const {
159 return _scale;
160}
161
162/**
163 * Composes these transforms and stores the result in-place.
164 */
165INLINE void STTransform::
166operator *= (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 */
178operator * (const STTransform &other) const {
179 STTransform result = *this;
180 result *= other;
181 return result;
182}
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition stTransform.h:26
STTransform()
The default constructor creates an identity transform.
Definition stTransform.I:18
PN_stdfloat get_rotate() const
Returns the rotation component, in degrees counter-clockwise around the vertical axis.
void set_scale(PN_stdfloat scale)
Replaces the scale component.
const LPoint3 & get_pos() const
Returns the translation component.
void operator*=(const STTransform &other)
Composes these transforms and stores the result in-place.
static const STTransform & ident_mat()
Returns a global identity transform object.
PN_stdfloat get_scale() const
Returns the scale component, as a uniform scale value.
void set_pos(const LPoint3 &pos)
Replaces the translation component.
void set_rotate(PN_stdfloat rotate)
Replaces the rotation component.
STTransform operator*(const STTransform &other) const
Composes these transforms and returns the result.
Indicates a coordinate-system transform on vertices.