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, PN_stdfloat) { 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, PN_stdfloat weight0, 00042 const VertexTransform *transform1, PN_stdfloat 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, PN_stdfloat weight0, 00055 const VertexTransform *transform1, PN_stdfloat weight1, 00056 const VertexTransform *transform2, PN_stdfloat 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, PN_stdfloat weight0, 00070 const VertexTransform *transform1, PN_stdfloat weight1, 00071 const VertexTransform *transform2, PN_stdfloat weight2, 00072 const VertexTransform *transform3, PN_stdfloat 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 PN_stdfloat 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, PN_stdfloat 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(LMatrix4 &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(LPoint4 &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(LPoint3 &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(LVector3 &vector, Thread *current_thread) const { 00275 if (!_entries.empty()) { 00276 CDReader cdata(_cycler, current_thread); 00277 vector = vector * cdata->_result; 00278 } 00279 } 00280 00281 #ifndef STDFLOAT_DOUBLE 00282 //////////////////////////////////////////////////////////////////// 00283 // Function: TransformBlend::transform_point (double) 00284 // Access: Published 00285 // Description: Transforms the indicated point by the blend matrix. 00286 // 00287 // You should call update_blend() to ensure that the 00288 // cache is up-to-date before calling this. 00289 //////////////////////////////////////////////////////////////////// 00290 INLINE void TransformBlend:: 00291 transform_point(LPoint4d &point, Thread *current_thread) const { 00292 if (!_entries.empty()) { 00293 CDReader cdata(_cycler, current_thread); 00294 point = point * LCAST(double, cdata->_result); 00295 } 00296 } 00297 #else // STDFLOAT_DOUBLE 00298 //////////////////////////////////////////////////////////////////// 00299 // Function: TransformBlend::transform_point (float) 00300 // Access: Published 00301 // Description: Transforms the indicated point by the blend matrix. 00302 // 00303 // You should call update_blend() to ensure that the 00304 // cache is up-to-date before calling this. 00305 //////////////////////////////////////////////////////////////////// 00306 INLINE void TransformBlend:: 00307 transform_point(LPoint4f &point, Thread *current_thread) const { 00308 if (!_entries.empty()) { 00309 CDReader cdata(_cycler, current_thread); 00310 point = point * LCAST(float, cdata->_result); 00311 } 00312 } 00313 #endif // STDFLOAT_DOUBLE 00314 00315 #ifndef STDFLOAT_DOUBLE 00316 //////////////////////////////////////////////////////////////////// 00317 // Function: TransformBlend::transform_point (double) 00318 // Access: Published 00319 // Description: Transforms the indicated point by the blend matrix. 00320 // 00321 // You should call update_blend() to ensure that the 00322 // cache is up-to-date before calling this. 00323 //////////////////////////////////////////////////////////////////// 00324 INLINE void TransformBlend:: 00325 transform_point(LPoint3d &point, Thread *current_thread) const { 00326 if (!_entries.empty()) { 00327 CDReader cdata(_cycler, current_thread); 00328 point = point * LCAST(double, cdata->_result); 00329 } 00330 } 00331 #else // STDFLOAT_DOUBLE 00332 //////////////////////////////////////////////////////////////////// 00333 // Function: TransformBlend::transform_point (float) 00334 // Access: Published 00335 // Description: Transforms the indicated point by the blend matrix. 00336 // 00337 // You should call update_blend() to ensure that the 00338 // cache is up-to-date before calling this. 00339 //////////////////////////////////////////////////////////////////// 00340 INLINE void TransformBlend:: 00341 transform_point(LPoint3f &point, Thread *current_thread) const { 00342 if (!_entries.empty()) { 00343 CDReader cdata(_cycler, current_thread); 00344 point = point * LCAST(float, cdata->_result); 00345 } 00346 } 00347 #endif // STDFLOAT_DOUBLE 00348 00349 #ifndef STDFLOAT_DOUBLE 00350 //////////////////////////////////////////////////////////////////// 00351 // Function: TransformBlend::transform_vector (double) 00352 // Access: Published 00353 // Description: Transforms the indicated vector by the blend matrix. 00354 // 00355 // You should call update_blend() to ensure that the 00356 // cache is up-to-date before calling this. 00357 //////////////////////////////////////////////////////////////////// 00358 INLINE void TransformBlend:: 00359 transform_vector(LVector3d &vector, Thread *current_thread) const { 00360 if (!_entries.empty()) { 00361 CDReader cdata(_cycler, current_thread); 00362 vector = vector * LCAST(double, cdata->_result); 00363 } 00364 } 00365 #else // STDFLOAT_DOUBLE 00366 //////////////////////////////////////////////////////////////////// 00367 // Function: TransformBlend::transform_vector (float) 00368 // Access: Published 00369 // Description: Transforms the indicated vector by the blend matrix. 00370 // 00371 // You should call update_blend() to ensure that the 00372 // cache is up-to-date before calling this. 00373 //////////////////////////////////////////////////////////////////// 00374 INLINE void TransformBlend:: 00375 transform_vector(LVector3f &vector, Thread *current_thread) const { 00376 if (!_entries.empty()) { 00377 CDReader cdata(_cycler, current_thread); 00378 vector = vector * LCAST(float, cdata->_result); 00379 } 00380 } 00381 #endif // STDFLOAT_DOUBLE 00382 00383 //////////////////////////////////////////////////////////////////// 00384 // Function: TransformBlend::get_modified 00385 // Access: Published 00386 // Description: Returns a counter which is guaranteed to increment at 00387 // least as often as the result of get_blend() changes. 00388 //////////////////////////////////////////////////////////////////// 00389 INLINE UpdateSeq TransformBlend:: 00390 get_modified(Thread *current_thread) const { 00391 CDLockedReader cdata(_cycler, current_thread); 00392 if (cdata->_global_modified != VertexTransform::get_global_modified(current_thread)) { 00393 CDWriter cdataw(((TransformBlend *)this)->_cycler, cdata, false); 00394 ((TransformBlend *)this)->recompute_result(cdataw, current_thread); 00395 return cdataw->_modified; 00396 } else { 00397 return cdata->_modified; 00398 } 00399 } 00400 00401 //////////////////////////////////////////////////////////////////// 00402 // Function: TransformBlend::TransformEntry::operator < 00403 // Access: Public 00404 // Description: Provides an ordering of TransformEntries by the 00405 // VertexTransform pointer only, so we can easily look 00406 // up in the set to see if a particular transform 00407 // exists. 00408 //////////////////////////////////////////////////////////////////// 00409 INLINE bool TransformBlend::TransformEntry:: 00410 operator < (const TransformBlend::TransformEntry &other) const { 00411 return _transform < other._transform; 00412 } 00413 00414 //////////////////////////////////////////////////////////////////// 00415 // Function: TransformBlend::CData::Constructor 00416 // Access: Public 00417 // Description: 00418 //////////////////////////////////////////////////////////////////// 00419 INLINE TransformBlend::CData:: 00420 CData() : 00421 _result(LMatrix4::ident_mat()) 00422 { 00423 } 00424 00425 //////////////////////////////////////////////////////////////////// 00426 // Function: TransformBlend::CData::Copy Constructor 00427 // Access: Public 00428 // Description: 00429 //////////////////////////////////////////////////////////////////// 00430 INLINE TransformBlend::CData:: 00431 CData(const TransformBlend::CData ©) : 00432 _result(copy._result), 00433 _modified(copy._modified), 00434 _global_modified(copy._global_modified) 00435 { 00436 } 00437 00438 INLINE ostream & 00439 operator << (ostream &out, const TransformBlend &obj) { 00440 obj.output(out); 00441 return out; 00442 }