Panda3D
|
00001 // Filename: stTransform.I 00002 // Created by: drose (06Oct10) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: STTransform::Default Constructor 00018 // Access: Published 00019 // Description: The default constructor creates an identity transform. 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE STTransform:: 00022 STTransform() : 00023 _pos(0.0f, 0.0f, 0.0f), 00024 _rotate(0.0f), 00025 _scale(1.0f) 00026 { 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: STTransform::Constructor 00031 // Access: Published 00032 // Description: Construct a transform with componentwise inputs. 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE STTransform:: 00035 STTransform(const LPoint3 &pos, PN_stdfloat rotate, PN_stdfloat scale) : 00036 _pos(pos), 00037 _rotate(rotate), 00038 _scale(scale) 00039 { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: STTransform::Constructor 00044 // Access: Published 00045 // Description: Construct a transform with componentwise inputs. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE STTransform:: 00048 STTransform(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat rotate, PN_stdfloat scale) : 00049 _pos(x, y, z), 00050 _rotate(rotate), 00051 _scale(scale) 00052 { 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: STTransform::Copy Constructor 00057 // Access: Published 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE STTransform:: 00061 STTransform(const STTransform ©) : 00062 _pos(copy._pos), 00063 _rotate(copy._rotate), 00064 _scale(copy._scale) 00065 { 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: STTransform::Copy Assignment Operator 00070 // Access: Published 00071 // Description: 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE void STTransform:: 00074 operator = (const STTransform ©) { 00075 _pos = copy._pos; 00076 _rotate = copy._rotate; 00077 _scale = copy._scale; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: STTransform::CInstance constructor 00082 // Access: Public 00083 // Description: This is used internally to construct an STTransform 00084 // from a SpeedTree::CInstance object. 00085 //////////////////////////////////////////////////////////////////// 00086 INLINE STTransform:: 00087 STTransform(const SpeedTree::CInstance &instance) { 00088 const SpeedTree::Vec3 &pos = instance.GetPos(); 00089 _pos.set(pos[0], pos[1], pos[2]); 00090 _rotate = rad_2_deg(instance.GetRotationAngle()); 00091 _scale = instance.GetScale(); 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: STTransform::CInstance operator 00096 // Access: Public 00097 // Description: This is used internally to convert an STTransform 00098 // into a SpeedTree::CInstance object. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE STTransform:: 00101 operator SpeedTree::CInstance () const { 00102 SpeedTree::CInstance instance; 00103 instance.SetPos(SpeedTree::Vec3(_pos[0], _pos[1], _pos[2])); 00104 instance.SetRotation(deg_2_rad(_rotate)); 00105 instance.SetScale(_scale); 00106 return instance; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: STTransform::TransformState operator 00111 // Access: Public 00112 // Description: This is used internally to convert an STTransform 00113 // into a TransformState pointer. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE STTransform:: 00116 operator CPT(TransformState) () const { 00117 return TransformState::make_pos_hpr_scale(_pos, 00118 LVecBase3(_rotate, 0.0f, 0.0f), 00119 LVecBase3(_scale, _scale, _scale)); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: STTransform::ident_mat 00124 // Access: Published, Static 00125 // Description: Returns a global identity transform object. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE const STTransform &STTransform:: 00128 ident_mat() { 00129 return _ident_mat; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: STTransform::set_pos 00134 // Access: Published 00135 // Description: Replaces the translation component. 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE void STTransform:: 00138 set_pos(const LPoint3 &pos) { 00139 _pos = pos; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: STTransform::get_pos 00144 // Access: Published 00145 // Description: Returns the translation component. 00146 //////////////////////////////////////////////////////////////////// 00147 INLINE const LPoint3 &STTransform:: 00148 get_pos() const { 00149 return _pos; 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: STTransform::set_rotate 00154 // Access: Published 00155 // Description: Replaces the rotation component. Accepts a rotation 00156 // in degrees counter-clockwise around the vertical 00157 // axis. 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE void STTransform:: 00160 set_rotate(PN_stdfloat rotate) { 00161 _rotate = rotate; 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: STTransform::get_rotate 00166 // Access: Published 00167 // Description: Returns the rotation component, in degrees 00168 // counter-clockwise around the vertical axis. 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE PN_stdfloat STTransform:: 00171 get_rotate() const { 00172 return _rotate; 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function: STTransform::set_scale 00177 // Access: Published 00178 // Description: Replaces the scale component. Accepts a uniform 00179 // scale value. 00180 //////////////////////////////////////////////////////////////////// 00181 INLINE void STTransform:: 00182 set_scale(PN_stdfloat scale) { 00183 _scale = scale; 00184 } 00185 00186 //////////////////////////////////////////////////////////////////// 00187 // Function: STTransform::get_scale 00188 // Access: Published 00189 // Description: Returns the scale component, as a uniform scale 00190 // value. 00191 //////////////////////////////////////////////////////////////////// 00192 INLINE PN_stdfloat STTransform:: 00193 get_scale() const { 00194 return _scale; 00195 } 00196 00197 //////////////////////////////////////////////////////////////////// 00198 // Function: STTransform::operator *= 00199 // Access: Published 00200 // Description: Composes these transforms and stores the result 00201 // in-place. 00202 //////////////////////////////////////////////////////////////////// 00203 INLINE void STTransform:: 00204 operator *= (const STTransform &other) { 00205 LQuaternion quat; 00206 quat.set_hpr(LVecBase3(_rotate, 0.0f, 0.0f)); 00207 _pos += quat.xform(other.get_pos()) * _scale; 00208 _rotate += other._rotate; 00209 _scale *= other._scale; 00210 } 00211 00212 //////////////////////////////////////////////////////////////////// 00213 // Function: STTransform::operator * 00214 // Access: Published 00215 // Description: Composes these transforms and returns the result/ 00216 //////////////////////////////////////////////////////////////////// 00217 INLINE STTransform STTransform:: 00218 operator * (const STTransform &other) const { 00219 STTransform result = *this; 00220 result *= other; 00221 return result; 00222 }