| 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 | 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 | out->writeQuat(getRotation()); |
|---|
| 41 | out->writeVec3(getScale()); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void AutoTransform::read(DataInputStream* in){ |
|---|
| 45 | |
|---|
| 46 | int id = in->peekInt(); |
|---|
| 47 | if(id == IVEAUTOTRANSFORM){ |
|---|
| 48 | |
|---|
| 49 | id = in->readInt(); |
|---|
| 50 | |
|---|
| 51 | osg::Transform* trans = dynamic_cast<osg::Transform*>(this); |
|---|
| 52 | if(trans){ |
|---|
| 53 | ((ive::Transform*)(trans))->read(in); |
|---|
| 54 | } |
|---|
| 55 | else |
|---|
| 56 | throw Exception("AutoTransform::read(): Could not cast this osg::AutoTransform to an osg::Transform."); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | setPosition(in->readVec3()); |
|---|
| 60 | setPivotPoint(in->readVec3()); |
|---|
| 61 | setAutoUpdateEyeMovementTolerance(in->readFloat()); |
|---|
| 62 | |
|---|
| 63 | setAutoRotateMode(osg::AutoTransform::AutoRotateMode(in->readInt())); |
|---|
| 64 | |
|---|
| 65 | setAutoScaleToScreen(in->readBool()); |
|---|
| 66 | |
|---|
| 67 | setRotation(in->readQuat()); |
|---|
| 68 | setScale(in->readVec3()); |
|---|
| 69 | } |
|---|
| 70 | else{ |
|---|
| 71 | throw Exception("AutoTransform::read(): Expected AutoTransform identification."); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|