Panda3D
|
00001 // Filename: transformBlend.I 00002 // Created by: drose (24Mar05) 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: TransformBlend::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE TransformBlend:: 00022 TransformBlend() { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: TransformBlend::Constructor 00027 // Access: Published 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE TransformBlend:: 00031 TransformBlend(const VertexTransform *transform0, float) { 00032 add_transform(transform0, 1.0f); 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: TransformBlend::Constructor 00037 // Access: Published 00038 // Description: 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE TransformBlend:: 00041 TransformBlend(const VertexTransform *transform0, float weight0, 00042 const VertexTransform *transform1, float weight1) { 00043 add_transform(transform0, weight0); 00044 add_transform(transform1, weight1); 00045 normalize_weights(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: TransformBlend::Constructor 00050 // Access: Published 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE TransformBlend:: 00054 TransformBlend(const VertexTransform *transform0, float weight0, 00055 const VertexTransform *transform1, float weight1, 00056 const VertexTransform *transform2, float weight2) { 00057 add_transform(transform0, weight0); 00058 add_transform(transform1, weight1); 00059 add_transform(transform2, weight2); 00060 normalize_weights(); 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: TransformBlend::Constructor 00065 // Access: Published 00066 // Description: 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE TransformBlend:: 00069 TransformBlend(const VertexTransform *transform0, float weight0, 00070 const VertexTransform *transform1, float weight1, 00071 const VertexTransform *transform2, float weight2, 00072 const VertexTransform *transform3, float weight3) { 00073 add_transform(transform0, weight0); 00074 add_transform(transform1, weight1); 00075 add_transform(transform2, weight2); 00076 add_transform(transform3, weight3); 00077 normalize_weights(); 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: TransformBlend::Copy Constructor 00082 // Access: Published 00083 // Description: 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE TransformBlend:: 00086 TransformBlend(const TransformBlend ©) : 00087 _entries(copy._entries) 00088 { 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: TransformBlend::Copy Assignment Operator 00093 // Access: Published 00094 // Description: 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE void TransformBlend:: 00097 operator = (const TransformBlend ©) { 00098 _entries = copy._entries; 00099 Thread *current_thread = Thread::get_current_thread(); 00100 clear_result(current_thread); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: TransformBlend::Destructor 00105 // Access: Published 00106 // Description: 00107 //////////////////////////////////////////////////////////////////// 00108 INLINE TransformBlend:: 00109 ~TransformBlend() { 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: TransformBlend::operator < 00114 // Access: Published 00115 // Description: 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE bool TransformBlend:: 00118 operator < (const TransformBlend &other) const { 00119 return compare_to(other) < 0; 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: TransformBlend::operator == 00124 // Access: Published 00125 // Description: 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE bool TransformBlend:: 00128 operator == (const TransformBlend &other) const { 00129 return compare_to(other) == 0; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: TransformBlend::operator != 00134 // Access: Published 00135 // Description: 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE bool TransformBlend:: 00138 operator != (const TransformBlend &other) const { 00139 return compare_to(other) != 0; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: TransformBlend::get_num_transforms 00144 // Access: Published 00145 // Description: Returns the number of transforms stored in the blend 00146 // object. 00147 //////////////////////////////////////////////////////////////////// 00148 INLINE int TransformBlend:: 00149 get_num_transforms() const { 00150 return _entries.size(); 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: TransformBlend::get_transform 00155 // Access: Published 00156 // Description: Returns the nth transform stored in the blend 00157 // object. 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE const VertexTransform *TransformBlend:: 00160 get_transform(int n) const { 00161 nassertr(n >= 0 && n < (int)_entries.size(), NULL); 00162 return _entries[n]._transform; 00163 } 00164 00165 //////////////////////////////////////////////////////////////////// 00166 // Function: TransformBlend::get_weight 00167 // Access: Published 00168 // Description: Returns the weight associated with the nth transform 00169 // stored in the blend object. 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE float TransformBlend:: 00172 get_weight(int n) const { 00173 nassertr(n >= 0 && n < (int)_entries.size(), 0.0f); 00174 return _entries[n]._weight; 00175 } 00176 00177 //////////////////////////////////////////////////////////////////// 00178 // Function: TransformBlend::set_transform 00179 // Access: Published 00180 // Description: Replaces the nth transform stored in the blend 00181 // object. 00182 //////////////////////////////////////////////////////////////////// 00183 INLINE void TransformBlend:: 00184 set_transform(int n, const VertexTransform *transform) { 00185 nassertv(n >= 0 && n < (int)_entries.size()); 00186 _entries[n]._transform = transform; 00187 } 00188 00189 //////////////////////////////////////////////////////////////////// 00190 // Function: TransformBlend::set_weight 00191 // Access: Published 00192 // Description: Replaces the weight associated with the nth transform 00193 // stored in the blend object. 00194 //////////////////////////////////////////////////////////////////// 00195 INLINE void TransformBlend:: 00196 set_weight(int n, float weight) { 00197 nassertv(n >= 0 && n < (int)_entries.size()); 00198 _entries[n]._weight = weight; 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function: TransformBlend::update_blend 00203 // Access: Published 00204 // Description: Recomputes the internal representation of the blend 00205 // value, if necessary. You should call this before 00206 // calling get_blend() or transform_point(). 00207 //////////////////////////////////////////////////////////////////// 00208 INLINE void TransformBlend:: 00209 update_blend(Thread *current_thread) const { 00210 CDLockedReader cdata(_cycler, current_thread); 00211 if (cdata->_global_modified != VertexTransform::get_global_modified(current_thread)) { 00212 CDWriter cdataw(((TransformBlend *)this)->_cycler, cdata, false); 00213 ((TransformBlend *)this)->recompute_result(cdataw, current_thread); 00214 } 00215 } 00216 00217 //////////////////////////////////////////////////////////////////// 00218 // Function: TransformBlend::get_blend 00219 // Access: Published 00220 // Description: Returns the current value of the blend, based on the 00221 // current value of all of the nested transform objects 00222 // and their associated weights. 00223 // 00224 // You should call update_blend() to ensure that the 00225 // cache is up-to-date before calling this. 00226 //////////////////////////////////////////////////////////////////// 00227 INLINE void TransformBlend:: 00228 get_blend(LMatrix4f &result, Thread *current_thread) const { 00229 CDReader cdata(_cycler, current_thread); 00230 result = cdata->_result; 00231 } 00232 00233 //////////////////////////////////////////////////////////////////// 00234 // Function: TransformBlend::transform_point 00235 // Access: Published 00236 // Description: Transforms the indicated point by the blend matrix. 00237 // 00238 // You should call update_blend() to ensure that the 00239 // cache is up-to-date before calling this. 00240 //////////////////////////////////////////////////////////////////// 00241 INLINE void TransformBlend:: 00242 transform_point(LPoint4f &point, Thread *current_thread) const { 00243 if (!_entries.empty()) { 00244 CDReader cdata(_cycler, current_thread); 00245 point = point * cdata->_result; 00246 } 00247 } 00248 00249 //////////////////////////////////////////////////////////////////// 00250 // Function: TransformBlend::transform_point 00251 // Access: Published 00252 // Description: Transforms the indicated point by the blend matrix. 00253 // 00254 // You should call update_blend() to ensure that the 00255 // cache is up-to-date before calling this. 00256 //////////////////////////////////////////////////////////////////// 00257 INLINE void TransformBlend:: 00258 transform_point(LPoint3f &point, Thread *current_thread) const { 00259 if (!_entries.empty()) { 00260 CDReader cdata(_cycler, current_thread); 00261 point = point * cdata->_result; 00262 } 00263 } 00264 00265 //////////////////////////////////////////////////////////////////// 00266 // Function: TransformBlend::transform_vector 00267 // Access: Published 00268 // Description: Transforms the indicated vector by the blend matrix. 00269 // 00270 // You should call update_blend() to ensure that the 00271 // cache is up-to-date before calling this. 00272 //////////////////////////////////////////////////////////////////// 00273 INLINE void TransformBlend:: 00274 transform_vector(LVector3f &vector, Thread *current_thread) const { 00275 if (!_entries.empty()) { 00276 CDReader cdata(_cycler, current_thread); 00277 vector = vector * cdata->_result; 00278 } 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: TransformBlend::get_modified 00283 // Access: Published 00284 // Description: Returns a counter which is guaranteed to increment at 00285 // least as often as the result of get_blend() changes. 00286 //////////////////////////////////////////////////////////////////// 00287 INLINE UpdateSeq TransformBlend:: 00288 get_modified(Thread *current_thread) const { 00289 CDLockedReader cdata(_cycler, current_thread); 00290 if (cdata->_global_modified != VertexTransform::get_global_modified(current_thread)) { 00291 CDWriter cdataw(((TransformBlend *)this)->_cycler, cdata, false); 00292 ((TransformBlend *)this)->recompute_result(cdataw, current_thread); 00293 return cdataw->_modified; 00294 } else { 00295 return cdata->_modified; 00296 } 00297 } 00298 00299 //////////////////////////////////////////////////////////////////// 00300 // Function: TransformBlend::TransformEntry::operator < 00301 // Access: Public 00302 // Description: Provides an ordering of TransformEntries by the 00303 // VertexTransform pointer only, so we can easily look 00304 // up in the set to see if a particular transform 00305 // exists. 00306 //////////////////////////////////////////////////////////////////// 00307 INLINE bool TransformBlend::TransformEntry:: 00308 operator < (const TransformBlend::TransformEntry &other) const { 00309 return _transform < other._transform; 00310 } 00311 00312 //////////////////////////////////////////////////////////////////// 00313 // Function: TransformBlend::CData::Constructor 00314 // Access: Public 00315 // Description: 00316 //////////////////////////////////////////////////////////////////// 00317 INLINE TransformBlend::CData:: 00318 CData() : 00319 _result(LMatrix4f::ident_mat()) 00320 { 00321 } 00322 00323 //////////////////////////////////////////////////////////////////// 00324 // Function: TransformBlend::CData::Copy Constructor 00325 // Access: Public 00326 // Description: 00327 //////////////////////////////////////////////////////////////////// 00328 INLINE TransformBlend::CData:: 00329 CData(const TransformBlend::CData ©) : 00330 _result(copy._result), 00331 _modified(copy._modified), 00332 _global_modified(copy._global_modified) 00333 { 00334 } 00335 00336 INLINE ostream & 00337 operator << (ostream &out, const TransformBlend &obj) { 00338 obj.output(out); 00339 return out; 00340 }