00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 INLINE bool TransformState::
00028 operator < (const TransformState &other) const {
00029 return sorts_less(other, uniquify_matrix);
00030 }
00031
00032
00033
00034
00035
00036
00037 INLINE size_t TransformState::
00038 get_hash() const {
00039 check_hash();
00040 return _hash;
00041 }
00042
00043
00044
00045
00046
00047
00048
00049 INLINE CPT(TransformState) TransformState::
00050 make_pos(const LVecBase3f &pos) {
00051 return make_pos_hpr_scale(pos,
00052 LVecBase3f(0.0f, 0.0f, 0.0f),
00053 LVecBase3f(1.0f, 1.0f, 1.0f));
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 INLINE CPT(TransformState) TransformState::
00063 make_hpr(const LVecBase3f &hpr) {
00064 return make_pos_hpr_scale(LVecBase3f(0.0f, 0.0f, 0.0f),
00065 hpr,
00066 LVecBase3f(1.0f, 1.0f, 1.0f));
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 INLINE CPT(TransformState) TransformState::
00076 make_quat(const LQuaternionf &quat) {
00077 return make_pos_quat_scale(LVecBase3f(0.0f, 0.0f, 0.0f),
00078 quat,
00079 LVecBase3f(1.0f, 1.0f, 1.0f));
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 INLINE CPT(TransformState) TransformState::
00089 make_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr) {
00090 return make_pos_hpr_scale(pos, hpr,
00091 LVecBase3f(1.0, 1.0f, 1.0f));
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 INLINE CPT(TransformState) TransformState::
00101 make_scale(float scale) {
00102
00103
00104 return make_scale2d(scale);
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 INLINE CPT(TransformState) TransformState::
00114 make_scale(const LVecBase3f &scale) {
00115 return make_pos_hpr_scale(LVecBase3f(0.0f, 0.0f, 0.0f),
00116 LVecBase3f(0.0f, 0.0f, 0.0f),
00117 scale);
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 INLINE CPT(TransformState) TransformState::
00127 make_shear(const LVecBase3f &shear) {
00128 return make_pos_hpr_scale_shear(LVecBase3f(0.0f, 0.0f, 0.0f),
00129 LVecBase3f(0.0f, 0.0f, 0.0f),
00130 LVecBase3f(1.0f, 1.0f, 1.0f),
00131 shear);
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 INLINE CPT(TransformState) TransformState::
00141 make_pos_hpr_scale(const LVecBase3f &pos, const LVecBase3f &hpr,
00142 const LVecBase3f &scale) {
00143 return make_pos_hpr_scale_shear(pos, hpr, scale, LVecBase3f::zero());
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 INLINE CPT(TransformState) TransformState::
00153 make_pos_quat_scale(const LVecBase3f &pos, const LQuaternionf &quat,
00154 const LVecBase3f &scale) {
00155 return make_pos_quat_scale_shear(pos, quat, scale, LVecBase3f::zero());
00156 }
00157
00158
00159
00160
00161
00162
00163
00164 INLINE CPT(TransformState) TransformState::
00165 make_pos2d(const LVecBase2f &pos) {
00166 return make_pos_rotate_scale2d(pos, 0.0f, LVecBase2f(1.0f, 1.0f));
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 INLINE CPT(TransformState) TransformState::
00176 make_rotate2d(float rotate) {
00177 return make_pos_rotate_scale2d(LVecBase2f(0.0f, 0.0f), rotate,
00178 LVecBase2f(1.0f, 1.0f));
00179 }
00180
00181
00182
00183
00184
00185
00186
00187 INLINE CPT(TransformState) TransformState::
00188 make_pos_rotate2d(const LVecBase2f &pos, float rotate) {
00189 return make_pos_rotate_scale2d(pos, rotate,
00190 LVecBase2f(1.0, 1.0f));
00191 }
00192
00193
00194
00195
00196
00197
00198
00199 INLINE CPT(TransformState) TransformState::
00200 make_scale2d(float scale) {
00201 return make_pos_rotate_scale2d(LVecBase2f(0.0f, 0.0f), 0.0f,
00202 LVecBase2f(scale, scale));
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 INLINE CPT(TransformState) TransformState::
00212 make_scale2d(const LVecBase2f &scale) {
00213 return make_pos_rotate_scale2d(LVecBase2f(0.0f, 0.0f), 0.0f, scale);
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 INLINE CPT(TransformState) TransformState::
00223 make_shear2d(float shear) {
00224 return make_pos_rotate_scale_shear2d(LVecBase2f(0.0f, 0.0f), 0.0f,
00225 LVecBase2f(1.0f, 1.0f), shear);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234 INLINE CPT(TransformState) TransformState::
00235 make_pos_rotate_scale2d(const LVecBase2f &pos, float rotate,
00236 const LVecBase2f &scale) {
00237 return make_pos_rotate_scale_shear2d(pos, rotate, scale, 0.0f);
00238 }
00239
00240
00241
00242
00243
00244
00245
00246 INLINE bool TransformState::
00247 is_identity() const {
00248 return ((_flags & F_is_identity) != 0);
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258 INLINE bool TransformState::
00259 is_invalid() const {
00260 return ((_flags & F_is_invalid) != 0);
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270 INLINE bool TransformState::
00271 is_singular() const {
00272 check_singular();
00273 return ((_flags & F_is_singular) != 0);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 INLINE bool TransformState::
00285 is_2d() const {
00286 return ((_flags & F_is_2d) != 0);
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 INLINE bool TransformState::
00309 has_components() const {
00310 check_components();
00311 return ((_flags & F_has_components) != 0);
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 INLINE bool TransformState::
00328 components_given() const {
00329 return ((_flags & F_components_given) != 0);
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 INLINE bool TransformState::
00341 hpr_given() const {
00342 return ((_flags & F_hpr_given) != 0);
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 INLINE bool TransformState::
00354 quat_given() const {
00355 return ((_flags & F_quat_given) != 0);
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 INLINE bool TransformState::
00367 has_pos() const {
00368 return !is_invalid();
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 INLINE bool TransformState::
00380 has_hpr() const {
00381 return has_components();
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 INLINE bool TransformState::
00393 has_quat() const {
00394 return has_components();
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404 INLINE bool TransformState::
00405 has_scale() const {
00406 return has_components();
00407 }
00408
00409
00410
00411
00412
00413
00414
00415 INLINE bool TransformState::
00416 has_identity_scale() const {
00417 check_components();
00418 return (_flags & F_identity_scale) != 0;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 INLINE bool TransformState::
00430 has_uniform_scale() const {
00431 check_components();
00432 return (_flags & F_uniform_scale) != 0;
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442 INLINE bool TransformState::
00443 has_shear() const {
00444 return has_components();
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454 INLINE bool TransformState::
00455 has_nonzero_shear() const {
00456 check_components();
00457 return (_flags & F_has_nonzero_shear) != 0;
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467 INLINE bool TransformState::
00468 has_mat() const {
00469 return !is_invalid();
00470 }
00471
00472
00473
00474
00475
00476
00477
00478 INLINE const LPoint3f &TransformState::
00479 get_pos() const {
00480 check_components();
00481 nassertr(has_pos(), _pos);
00482 return _pos;
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492 INLINE const LVecBase3f &TransformState::
00493 get_hpr() const {
00494 check_hpr();
00495 nassertr(!is_invalid(), _hpr);
00496 return _hpr;
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 INLINE const LQuaternionf &TransformState::
00514 get_quat() const {
00515 check_quat();
00516 nassertr(!is_invalid(), _quat);
00517 return _quat;
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 INLINE const LQuaternionf &TransformState::
00530 get_norm_quat() const {
00531 check_norm_quat();
00532 nassertr(!is_invalid(), _norm_quat);
00533 return _norm_quat;
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543 INLINE const LVecBase3f &TransformState::
00544 get_scale() const {
00545 check_components();
00546 nassertr(!is_invalid(), _scale);
00547 return _scale;
00548 }
00549
00550
00551
00552
00553
00554
00555
00556
00557 INLINE float TransformState::
00558 get_uniform_scale() const {
00559 check_components();
00560 nassertr(has_uniform_scale(), _scale[0]);
00561 return _scale[0];
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571 INLINE const LVecBase3f &TransformState::
00572 get_shear() const {
00573 check_components();
00574 nassertr(!is_invalid(), _shear);
00575 return _shear;
00576 }
00577
00578
00579
00580
00581
00582
00583 INLINE const LMatrix4f &TransformState::
00584 get_mat() const {
00585 nassertr(has_mat(), LMatrix4f::ident_mat());
00586 check_mat();
00587 return _mat;
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597 INLINE LVecBase2f TransformState::
00598 get_pos2d() const {
00599 check_components();
00600 nassertr(has_pos() && is_2d(), LVecBase2f::zero());
00601 return LVecBase2f(_pos[0], _pos[1]);
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 INLINE float TransformState::
00613 get_rotate2d() const {
00614 check_hpr();
00615 nassertr(!is_invalid() && is_2d(), 0);
00616 switch (get_default_coordinate_system()) {
00617 default:
00618 case CS_zup_right:
00619 return _hpr[0];
00620 case CS_zup_left:
00621 return -_hpr[0];
00622 case CS_yup_right:
00623 return -_hpr[2];
00624 case CS_yup_left:
00625 return _hpr[2];
00626 }
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636 INLINE LVecBase2f TransformState::
00637 get_scale2d() const {
00638 check_components();
00639 nassertr(!is_invalid() && is_2d(), LVecBase2f::zero());
00640 return LVecBase2f(_scale[0], _scale[1]);
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650 INLINE float TransformState::
00651 get_shear2d() const {
00652 check_components();
00653 nassertr(!is_invalid() && is_2d(), 0.0f);
00654 return _shear[0];
00655 }
00656
00657
00658
00659
00660
00661
00662
00663
00664 INLINE LMatrix3f TransformState::
00665 get_mat3() const {
00666 nassertr(has_mat() && is_2d(), LMatrix3f::ident_mat());
00667 check_mat();
00668 return LMatrix3f(_mat(0, 0), _mat(0, 1), _mat(0, 3),
00669 _mat(1, 0), _mat(1, 1), _mat(1, 3),
00670 _mat(3, 0), _mat(3, 1), _mat(3, 3));
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681 INLINE CPT(TransformState) TransformState::
00682 get_inverse() const {
00683 return invert_compose(TransformState::make_identity());
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 INLINE CPT(TransformState) TransformState::
00697 get_unique() const {
00698 return return_unique((TransformState *)this);
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 INLINE int TransformState::
00712 get_geom_rendering(int geom_rendering) const {
00713 if ((geom_rendering & GeomEnums::GR_point_perspective) != 0) {
00714 if (!has_identity_scale()) {
00715 geom_rendering |= GeomEnums::GR_point_scale;
00716 }
00717 }
00718
00719 return geom_rendering;
00720 }
00721
00722
00723
00724
00725
00726
00727 INLINE void TransformState::
00728 cache_ref() const {
00729 #ifdef DO_PSTATS
00730 int old_referenced_bits = get_referenced_bits();
00731 NodeCachedReferenceCount::cache_ref();
00732 consider_update_pstats(old_referenced_bits);
00733 #else // DO_PSTATS
00734 NodeCachedReferenceCount::cache_ref();
00735 #endif // DO_PSTATS
00736 }
00737
00738
00739
00740
00741
00742
00743 INLINE bool TransformState::
00744 cache_unref() const {
00745 #ifdef DO_PSTATS
00746 int old_referenced_bits = get_referenced_bits();
00747 bool result = do_cache_unref();
00748 consider_update_pstats(old_referenced_bits);
00749 return result;
00750 #else // DO_PSTATS
00751 return do_cache_unref();
00752 #endif // DO_PSTATS
00753 }
00754
00755
00756
00757
00758
00759
00760 INLINE void TransformState::
00761 node_ref() const {
00762 #ifdef DO_PSTATS
00763 int old_referenced_bits = get_referenced_bits();
00764 NodeCachedReferenceCount::node_ref();
00765 consider_update_pstats(old_referenced_bits);
00766 #else // DO_PSTATS
00767 NodeCachedReferenceCount::node_ref();
00768 #endif // DO_PSTATS
00769 }
00770
00771
00772
00773
00774
00775
00776 INLINE bool TransformState::
00777 node_unref() const {
00778 #ifdef DO_PSTATS
00779 int old_referenced_bits = get_referenced_bits();
00780 bool result = do_node_unref();
00781 consider_update_pstats(old_referenced_bits);
00782 return result;
00783 #else // DO_PSTATS
00784 return do_node_unref();
00785 #endif // DO_PSTATS
00786 }
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 INLINE int TransformState::
00798 get_composition_cache_num_entries() const {
00799 LightReMutexHolder holder(*_states_lock);
00800 return _composition_cache.get_num_entries();
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 INLINE int TransformState::
00813 get_invert_composition_cache_num_entries() const {
00814 LightReMutexHolder holder(*_states_lock);
00815 return _invert_composition_cache.get_num_entries();
00816 }
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 INLINE int TransformState::
00831 get_composition_cache_size() const {
00832 LightReMutexHolder holder(*_states_lock);
00833 return _composition_cache.get_size();
00834 }
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 INLINE const TransformState *TransformState::
00848 get_composition_cache_source(int n) const {
00849 LightReMutexHolder holder(*_states_lock);
00850 if (!_composition_cache.has_element(n)) {
00851 return NULL;
00852 }
00853 return _composition_cache.get_key(n);
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870 INLINE const TransformState *TransformState::
00871 get_composition_cache_result(int n) const {
00872 LightReMutexHolder holder(*_states_lock);
00873 if (!_composition_cache.has_element(n)) {
00874 return NULL;
00875 }
00876 return _composition_cache.get_data(n)._result;
00877 }
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 INLINE int TransformState::
00892 get_invert_composition_cache_size() const {
00893 LightReMutexHolder holder(*_states_lock);
00894 return _invert_composition_cache.get_size();
00895 }
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908 INLINE const TransformState *TransformState::
00909 get_invert_composition_cache_source(int n) const {
00910 LightReMutexHolder holder(*_states_lock);
00911 if (!_invert_composition_cache.has_element(n)) {
00912 return NULL;
00913 }
00914 return _invert_composition_cache.get_key(n);
00915 }
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 INLINE const TransformState *TransformState::
00933 get_invert_composition_cache_result(int n) const {
00934 LightReMutexHolder holder(*_states_lock);
00935 if (!_invert_composition_cache.has_element(n)) {
00936 return NULL;
00937 }
00938 return _invert_composition_cache.get_data(n)._result;
00939 }
00940
00941
00942
00943
00944
00945
00946 INLINE void TransformState::
00947 flush_level() {
00948 _node_counter.flush_level();
00949 _cache_counter.flush_level();
00950 }
00951
00952
00953
00954
00955
00956
00957
00958 INLINE bool TransformState::
00959 do_node_unref() const {
00960 node_unref_only();
00961 return unref();
00962 }
00963
00964
00965
00966
00967
00968
00969
00970
00971 INLINE bool TransformState::
00972 do_cache_unref() const {
00973 cache_unref_only();
00974 return unref();
00975 }
00976
00977
00978
00979
00980
00981
00982 INLINE void TransformState::
00983 check_hash() const {
00984
00985
00986 if ((_flags & F_hash_known) == 0) {
00987 ((TransformState *)this)->calc_hash();
00988 }
00989 }
00990
00991
00992
00993
00994
00995
00996 INLINE void TransformState::
00997 check_singular() const {
00998
00999
01000 if ((_flags & F_singular_known) == 0) {
01001 ((TransformState *)this)->calc_singular();
01002 }
01003 }
01004
01005
01006
01007
01008
01009
01010
01011 INLINE void TransformState::
01012 check_components() const {
01013
01014
01015 if ((_flags & F_components_known) == 0) {
01016 ((TransformState *)this)->calc_components();
01017 }
01018 }
01019
01020
01021
01022
01023
01024
01025
01026 INLINE void TransformState::
01027 check_hpr() const {
01028
01029
01030 if ((_flags & F_hpr_known) == 0) {
01031 ((TransformState *)this)->calc_hpr();
01032 }
01033 }
01034
01035
01036
01037
01038
01039
01040
01041 INLINE void TransformState::
01042 check_quat() const {
01043
01044
01045 if ((_flags & F_quat_known) == 0) {
01046 ((TransformState *)this)->calc_quat();
01047 }
01048 }
01049
01050
01051
01052
01053
01054
01055
01056 INLINE void TransformState::
01057 check_norm_quat() const {
01058
01059
01060 if ((_flags & F_norm_quat_known) == 0) {
01061 ((TransformState *)this)->calc_norm_quat();
01062 }
01063 }
01064
01065
01066
01067
01068
01069
01070 INLINE void TransformState::
01071 check_mat() const {
01072
01073
01074 if ((_flags & F_mat_known) == 0) {
01075 ((TransformState *)this)->calc_mat();
01076 }
01077 }
01078
01079
01080
01081
01082
01083
01084 INLINE void TransformState::
01085 calc_hash() {
01086 LightMutexHolder holder(_lock);
01087 do_calc_hash();
01088 }
01089
01090
01091
01092
01093
01094
01095 INLINE void TransformState::
01096 calc_components() {
01097 LightMutexHolder holder(_lock);
01098 do_calc_components();
01099 }
01100
01101
01102
01103
01104
01105
01106
01107 INLINE void TransformState::
01108 calc_hpr() {
01109 LightMutexHolder holder(_lock);
01110 do_calc_hpr();
01111 }
01112
01113
01114
01115
01116
01117
01118 INLINE void TransformState::
01119 calc_mat() {
01120 LightMutexHolder holder(_lock);
01121 do_calc_mat();
01122 }
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135 INLINE void TransformState::
01136 check_uniform_scale() {
01137 if (IS_NEARLY_EQUAL(_scale[0], _scale[1]) &&
01138 IS_NEARLY_EQUAL(_scale[0], _scale[2])) {
01139 _flags |= F_uniform_scale;
01140 if (IS_NEARLY_EQUAL(_scale[0], 1.0f)) {
01141 _flags |= F_identity_scale;
01142 }
01143 }
01144
01145 if (!_shear.almost_equal(LVecBase3f::zero())) {
01146 _flags |= F_has_nonzero_shear;
01147 }
01148 }
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161 INLINE void TransformState::
01162 check_uniform_scale2d() {
01163 if (IS_NEARLY_EQUAL(_scale[0], _scale[1])) {
01164 _scale[2] = _scale[0];
01165 _flags |= F_uniform_scale;
01166 if (IS_NEARLY_EQUAL(_scale[0], 1.0f)) {
01167 _flags |= F_identity_scale;
01168 }
01169 }
01170
01171 if (!_shear.almost_equal(LVecBase3f::zero())) {
01172 _flags |= F_has_nonzero_shear;
01173 }
01174 }
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185 INLINE void TransformState::
01186 set_destructing() {
01187 #ifndef NDEBUG
01188 _flags |= F_is_destructing;
01189 #endif
01190 }
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201 INLINE bool TransformState::
01202 is_destructing() const {
01203 #ifndef NDEBUG
01204 return (_flags & F_is_destructing) != 0;
01205 #else
01206 return false;
01207 #endif
01208 }
01209
01210
01211
01212
01213
01214
01215
01216 INLINE void TransformState::
01217 consider_update_pstats(int old_referenced_bits) const {
01218 #ifdef DO_PSTATS
01219 int new_referenced_bits = get_referenced_bits();
01220 if (old_referenced_bits != new_referenced_bits) {
01221 update_pstats(old_referenced_bits, new_referenced_bits);
01222 }
01223 #endif // DO_PSTATS
01224 }
01225
01226
01227
01228
01229
01230
01231 INLINE TransformState::Composition::
01232 Composition() {
01233 }
01234
01235
01236
01237
01238
01239
01240 INLINE TransformState::Composition::
01241 Composition(const TransformState::Composition ©) :
01242 _result(copy._result)
01243 {
01244 }
01245
01246
01247
01248
01249
01250
01251 INLINE TransformState::CompositionCycleDescEntry::
01252 CompositionCycleDescEntry(const TransformState *obj,
01253 const TransformState *result,
01254 bool inverted) :
01255 _obj(obj),
01256 _result(result),
01257 _inverted(inverted)
01258 {
01259 }