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