| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/PositionAttitudeTransform> |
|---|
| 14 | |
|---|
| 15 | using namespace osg; |
|---|
| 16 | |
|---|
| 17 | PositionAttitudeTransform::PositionAttitudeTransform(): |
|---|
| 18 | _scale(1.0,1.0,1.0) |
|---|
| 19 | { |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | bool PositionAttitudeTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const |
|---|
| 23 | { |
|---|
| 24 | if (_referenceFrame==RELATIVE_RF) |
|---|
| 25 | { |
|---|
| 26 | matrix.preMultTranslate(_position); |
|---|
| 27 | matrix.preMultRotate(_attitude); |
|---|
| 28 | matrix.preMultScale(_scale); |
|---|
| 29 | matrix.preMultTranslate(-_pivotPoint); |
|---|
| 30 | } |
|---|
| 31 | else |
|---|
| 32 | { |
|---|
| 33 | matrix.makeRotate(_attitude); |
|---|
| 34 | matrix.postMultTranslate(_position); |
|---|
| 35 | matrix.preMultScale(_scale); |
|---|
| 36 | matrix.preMultTranslate(-_pivotPoint); |
|---|
| 37 | } |
|---|
| 38 | return true; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | bool PositionAttitudeTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const |
|---|
| 43 | { |
|---|
| 44 | if (_scale.x() == 0.0 || _scale.y() == 0.0 || _scale.z() == 0.0) |
|---|
| 45 | return false; |
|---|
| 46 | |
|---|
| 47 | if (_referenceFrame==RELATIVE_RF) |
|---|
| 48 | { |
|---|
| 49 | matrix.postMultTranslate(-_position); |
|---|
| 50 | matrix.postMultRotate(_attitude.inverse()); |
|---|
| 51 | matrix.postMultScale(Vec3d(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z())); |
|---|
| 52 | matrix.postMultTranslate(_pivotPoint); |
|---|
| 53 | } |
|---|
| 54 | else |
|---|
| 55 | { |
|---|
| 56 | matrix.makeRotate(_attitude.inverse()); |
|---|
| 57 | matrix.preMultTranslate(-_position); |
|---|
| 58 | matrix.postMultScale(Vec3d(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z())); |
|---|
| 59 | matrix.postMultTranslate(_pivotPoint); |
|---|
| 60 | } |
|---|
| 61 | return true; |
|---|
| 62 | } |
|---|