| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "BlinkSequence.h" |
|---|
| 16 | #include "Object.h" |
|---|
| 17 | |
|---|
| 18 | using namespace ive; |
|---|
| 19 | |
|---|
| 20 | void BlinkSequence::write(DataOutputStream* out){ |
|---|
| 21 | |
|---|
| 22 | out->writeInt(IVEBLINKSEQUENCE); |
|---|
| 23 | |
|---|
| 24 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 25 | if(obj){ |
|---|
| 26 | ((ive::Object*)(obj))->write(out); |
|---|
| 27 | } |
|---|
| 28 | else |
|---|
| 29 | out_THROW_EXCEPTION("BlinkSequence::write(): Could not cast this osgSim::BlinkSequence to an osg::Object."); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | unsigned int size = getNumPulses(); |
|---|
| 35 | out->writeInt(size); |
|---|
| 36 | for(unsigned int i=0; i<size; i++){ |
|---|
| 37 | double length; |
|---|
| 38 | osg::Vec4 color; |
|---|
| 39 | getPulse(i, length, color); |
|---|
| 40 | out->writeDouble(length); |
|---|
| 41 | out->writeVec4(color); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | out->writeDouble(getPhaseShift()); |
|---|
| 45 | |
|---|
| 46 | if( getSequenceGroup() ) |
|---|
| 47 | out->writeDouble(getSequenceGroup()->_baseTime); |
|---|
| 48 | else |
|---|
| 49 | out->writeDouble( 0.0 ); |
|---|
| 50 | |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void BlinkSequence::read(DataInputStream* in){ |
|---|
| 54 | |
|---|
| 55 | int id = in->peekInt(); |
|---|
| 56 | if(id == IVEBLINKSEQUENCE){ |
|---|
| 57 | |
|---|
| 58 | id = in->readInt(); |
|---|
| 59 | |
|---|
| 60 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 61 | if(obj){ |
|---|
| 62 | ((ive::Object*)(obj))->read(in); |
|---|
| 63 | } |
|---|
| 64 | else |
|---|
| 65 | in_THROW_EXCEPTION("BlinkSequence::read(): Could not cast this osgSim::BlinkSequence to an osg::Object."); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | unsigned int size = in->readInt(); |
|---|
| 70 | for(unsigned int i=0; i<size; i++){ |
|---|
| 71 | double length = in->readDouble(); |
|---|
| 72 | osg::Vec4 color = in->readVec4(); |
|---|
| 73 | addPulse(length,color); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | setPhaseShift(in->readDouble()); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | double baseTime = in->readDouble(); |
|---|
| 80 | if (baseTime!=0.0) setSequenceGroup(new osgSim::SequenceGroup(baseTime)); |
|---|
| 81 | |
|---|
| 82 | } |
|---|
| 83 | else{ |
|---|
| 84 | in_THROW_EXCEPTION("BlinkSequence::read(): Expected BlinkSequence identification."); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|