| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "LightPoint.h" |
|---|
| 16 | #include "BlinkSequence.h" |
|---|
| 17 | #include "AzimElevationSector.h" |
|---|
| 18 | #include "ElevationSector.h" |
|---|
| 19 | #include "AzimSector.h" |
|---|
| 20 | #include "ConeSector.h" |
|---|
| 21 | #include "DirectionalSector.h" |
|---|
| 22 | |
|---|
| 23 | using namespace ive; |
|---|
| 24 | |
|---|
| 25 | void LightPoint::write(DataOutputStream* out){ |
|---|
| 26 | |
|---|
| 27 | out->writeInt(IVELIGHTPOINT); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | out->writeBool(_on); |
|---|
| 31 | out->writeVec3(_position); |
|---|
| 32 | out->writeVec4(_color); |
|---|
| 33 | out->writeFloat(_intensity); |
|---|
| 34 | out->writeFloat(_radius); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | out->writeBool(_sector.valid()); |
|---|
| 38 | if(_sector.valid()){ |
|---|
| 39 | if(dynamic_cast<osgSim::AzimElevationSector*>(_sector.get())){ |
|---|
| 40 | ((ive::AzimElevationSector*)(_sector.get()))->write(out); |
|---|
| 41 | } |
|---|
| 42 | else if(dynamic_cast<osgSim::ElevationSector*>(_sector.get())){ |
|---|
| 43 | ((ive::ElevationSector*)(_sector.get()))->write(out); |
|---|
| 44 | } |
|---|
| 45 | else if(dynamic_cast<osgSim::AzimSector*>(_sector.get())){ |
|---|
| 46 | ((ive::AzimSector*)(_sector.get()))->write(out); |
|---|
| 47 | } |
|---|
| 48 | else if(dynamic_cast<osgSim::ConeSector*>(_sector.get())){ |
|---|
| 49 | ((ive::ConeSector*)(_sector.get()))->write(out); |
|---|
| 50 | } |
|---|
| 51 | else if(dynamic_cast<osgSim::DirectionalSector*>(_sector.get())){ |
|---|
| 52 | ((ive::DirectionalSector*)(_sector.get()))->write(out); |
|---|
| 53 | } |
|---|
| 54 | else |
|---|
| 55 | out_THROW_EXCEPTION("Unknown sector in LightPoint::write()"); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | out->writeBool(_blinkSequence.valid()); |
|---|
| 60 | if(_blinkSequence.valid()){ |
|---|
| 61 | ((ive::BlinkSequence*)(_blinkSequence.get()))->write(out); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | out->writeInt(_blendingMode); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void LightPoint::read(DataInputStream* in){ |
|---|
| 69 | |
|---|
| 70 | int id = in->peekInt(); |
|---|
| 71 | if(id == IVELIGHTPOINT){ |
|---|
| 72 | |
|---|
| 73 | id = in->readInt(); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | _on = in->readBool(); |
|---|
| 77 | _position = in->readVec3(); |
|---|
| 78 | _color = in->readVec4(); |
|---|
| 79 | _intensity = in->readFloat(); |
|---|
| 80 | _radius = in->readFloat(); |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | if(in->readBool()){ |
|---|
| 84 | osgSim::Sector* sector; |
|---|
| 85 | int attributeID = in->peekInt(); |
|---|
| 86 | if(attributeID == IVEAZIMELEVATIONSECTOR){ |
|---|
| 87 | sector = new osgSim::AzimElevationSector(); |
|---|
| 88 | ((ive::AzimElevationSector*)(sector))->read(in); |
|---|
| 89 | _sector = sector; |
|---|
| 90 | } |
|---|
| 91 | else if(attributeID == IVEELEVATIONSECTOR){ |
|---|
| 92 | sector = new osgSim::ElevationSector(); |
|---|
| 93 | ((ive::ElevationSector*)(sector))->read(in); |
|---|
| 94 | _sector = sector; |
|---|
| 95 | } |
|---|
| 96 | else if(attributeID == IVEAZIMSECTOR){ |
|---|
| 97 | sector = new osgSim::AzimSector(); |
|---|
| 98 | ((ive::AzimSector*)(sector))->read(in); |
|---|
| 99 | _sector = sector; |
|---|
| 100 | } |
|---|
| 101 | else if(attributeID == IVECONESECTOR){ |
|---|
| 102 | sector = new osgSim::ConeSector(); |
|---|
| 103 | ((ive::ConeSector*)(sector))->read(in); |
|---|
| 104 | _sector = sector; |
|---|
| 105 | } |
|---|
| 106 | else if(attributeID == IVEDIRECTIONALSECTOR){ |
|---|
| 107 | sector = new osgSim::DirectionalSector(); |
|---|
| 108 | ((ive::DirectionalSector*)(sector))->read(in); |
|---|
| 109 | _sector = sector; |
|---|
| 110 | } |
|---|
| 111 | else |
|---|
| 112 | in_THROW_EXCEPTION("Unknown sector in LightPoint::read()"); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | if(in->readBool()){ |
|---|
| 117 | osgSim::BlinkSequence* blinkSequence = new osgSim::BlinkSequence(); |
|---|
| 118 | ((ive::BlinkSequence*)(blinkSequence))->read(in); |
|---|
| 119 | _blinkSequence = blinkSequence; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | _blendingMode = (osgSim::LightPoint::BlendingMode)in->readInt(); |
|---|
| 124 | } |
|---|
| 125 | else{ |
|---|
| 126 | in_THROW_EXCEPTION("LightPoint::read(): Expected LightPoint identification."); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|