| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "AutoTransform.h" |
|---|
| 16 | #include "Transform.h" |
|---|
| 17 | |
|---|
| 18 | using namespace ive; |
|---|
| 19 | |
|---|
| 20 | void AutoTransform::write(DataOutputStream* out){ |
|---|
| 21 | |
|---|
| 22 | out->writeInt(IVEAUTOTRANSFORM); |
|---|
| 23 | |
|---|
| 24 | osg::Transform* trans = dynamic_cast<osg::Transform*>(this); |
|---|
| 25 | if(trans){ |
|---|
| 26 | ((ive::Transform*)(trans))->write(out); |
|---|
| 27 | } |
|---|
| 28 | else |
|---|
| 29 | out_THROW_EXCEPTION("AutoTransform::write(): Could not cast this osg::AutoTransform to an osg::Transform."); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | out->writeVec3(getPosition()); |
|---|
| 33 | out->writeVec3(getPivotPoint()); |
|---|
| 34 | out->writeFloat(getAutoUpdateEyeMovementTolerance()); |
|---|
| 35 | |
|---|
| 36 | out->writeInt(getAutoRotateMode()); |
|---|
| 37 | |
|---|
| 38 | out->writeBool(getAutoScaleToScreen()); |
|---|
| 39 | |
|---|
| 40 | if ( out->getVersion() >= VERSION_0025 ) |
|---|
| 41 | { |
|---|
| 42 | out->writeFloat(getMinimumScale()); |
|---|
| 43 | out->writeFloat(getMaximumScale()); |
|---|
| 44 | out->writeFloat(getAutoScaleTransitionWidthRatio()); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | out->writeQuat(getRotation()); |
|---|
| 48 | out->writeVec3(getScale()); |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | void AutoTransform::read(DataInputStream* in){ |
|---|
| 53 | |
|---|
| 54 | int id = in->peekInt(); |
|---|
| 55 | if(id == IVEAUTOTRANSFORM){ |
|---|
| 56 | |
|---|
| 57 | id = in->readInt(); |
|---|
| 58 | |
|---|
| 59 | osg::Transform* trans = dynamic_cast<osg::Transform*>(this); |
|---|
| 60 | if(trans){ |
|---|
| 61 | ((ive::Transform*)(trans))->read(in); |
|---|
| 62 | } |
|---|
| 63 | else |
|---|
| 64 | in_THROW_EXCEPTION("AutoTransform::read(): Could not cast this osg::AutoTransform to an osg::Transform."); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | setPosition(in->readVec3()); |
|---|
| 68 | setPivotPoint(in->readVec3()); |
|---|
| 69 | setAutoUpdateEyeMovementTolerance(in->readFloat()); |
|---|
| 70 | |
|---|
| 71 | setAutoRotateMode(osg::AutoTransform::AutoRotateMode(in->readInt())); |
|---|
| 72 | |
|---|
| 73 | setAutoScaleToScreen(in->readBool()); |
|---|
| 74 | |
|---|
| 75 | if ( in->getVersion() >= VERSION_0025 ) |
|---|
| 76 | { |
|---|
| 77 | setMinimumScale(in->readFloat()); |
|---|
| 78 | setMaximumScale(in->readFloat()); |
|---|
| 79 | setAutoScaleTransitionWidthRatio(in->readFloat()); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | setRotation(in->readQuat()); |
|---|
| 83 | setScale(in->readVec3()); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | } |
|---|
| 87 | else{ |
|---|
| 88 | in_THROW_EXCEPTION("AutoTransform::read(): Expected AutoTransform identification."); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|