| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "LightPointNode.h" |
|---|
| 16 | #include "LightPoint.h" |
|---|
| 17 | #include "Node.h" |
|---|
| 18 | |
|---|
| 19 | using namespace ive; |
|---|
| 20 | |
|---|
| 21 | void LightPointNode::write(DataOutputStream* out){ |
|---|
| 22 | |
|---|
| 23 | out->writeInt(IVELIGHTPOINTNODE); |
|---|
| 24 | |
|---|
| 25 | osg::Node* node = dynamic_cast<osg::Node*>(this); |
|---|
| 26 | if(node){ |
|---|
| 27 | ((ive::Node*)(node))->write(out); |
|---|
| 28 | } |
|---|
| 29 | else |
|---|
| 30 | out_THROW_EXCEPTION("LightPointNode::write(): Could not cast this osgSim::LightPointNode to an osg::Node."); |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | out->writeFloat(getMinPixelSize()); |
|---|
| 34 | out->writeFloat(getMaxPixelSize()); |
|---|
| 35 | out->writeFloat(getMaxVisibleDistance2()); |
|---|
| 36 | |
|---|
| 37 | if (out->getVersion() >= VERSION_0024) |
|---|
| 38 | { |
|---|
| 39 | out->writeBool(getPointSprite()); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | unsigned int size = getNumLightPoints(); |
|---|
| 44 | out->writeUInt(size); |
|---|
| 45 | for(unsigned int i=0; i<size; i++){ |
|---|
| 46 | ((ive::LightPoint*)(&getLightPoint(i)))->write(out); |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | void LightPointNode::read(DataInputStream* in){ |
|---|
| 51 | |
|---|
| 52 | int id = in->peekInt(); |
|---|
| 53 | if(id == IVELIGHTPOINTNODE){ |
|---|
| 54 | |
|---|
| 55 | id = in->readInt(); |
|---|
| 56 | |
|---|
| 57 | osg::Node* node = dynamic_cast<osg::Node*>(this); |
|---|
| 58 | if(node){ |
|---|
| 59 | ((ive::Node*)(node))->read(in); |
|---|
| 60 | } |
|---|
| 61 | else |
|---|
| 62 | in_THROW_EXCEPTION("LightPointNode::read(): Could not cast this osgSim::LightPointNode to an osg::Object."); |
|---|
| 63 | |
|---|
| 64 | setMinPixelSize(in->readFloat()); |
|---|
| 65 | setMaxPixelSize(in->readFloat()); |
|---|
| 66 | setMaxVisibleDistance2(in->readFloat()); |
|---|
| 67 | |
|---|
| 68 | if (in->getVersion() >= VERSION_0024) |
|---|
| 69 | { |
|---|
| 70 | setPointSprite(in->readBool()); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | unsigned int size = in->readUInt(); |
|---|
| 75 | for(unsigned int i=0; i<size; i++ ){ |
|---|
| 76 | osgSim::LightPoint lightPoint; |
|---|
| 77 | ((ive::LightPoint*)(&lightPoint))->read(in); |
|---|
| 78 | addLightPoint(lightPoint); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | else{ |
|---|
| 82 | in_THROW_EXCEPTION("LightPointNode::read(): Expected LightPointNode identification."); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|