| 1 | #include <osg/AutoTransform> |
|---|
| 2 | #include <osg/io_utils> |
|---|
| 3 | |
|---|
| 4 | #include <osgDB/Registry> |
|---|
| 5 | #include <osgDB/Input> |
|---|
| 6 | #include <osgDB/Output> |
|---|
| 7 | |
|---|
| 8 | using namespace osg; |
|---|
| 9 | using namespace osgDB; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | bool AutoTransform_readLocalData(Object& obj, Input& fr); |
|---|
| 13 | bool AutoTransform_writeLocalData(const Object& obj, Output& fw); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | REGISTER_DOTOSGWRAPPER(AutoTransform) |
|---|
| 17 | ( |
|---|
| 18 | new osg::AutoTransform, |
|---|
| 19 | "AutoTransform", |
|---|
| 20 | "Object Node Transform AutoTransform Group", |
|---|
| 21 | &AutoTransform_readLocalData, |
|---|
| 22 | &AutoTransform_writeLocalData, |
|---|
| 23 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 24 | ); |
|---|
| 25 | |
|---|
| 26 | bool AutoTransform_readLocalData(Object& obj, Input& fr) |
|---|
| 27 | { |
|---|
| 28 | bool iteratorAdvanced = false; |
|---|
| 29 | |
|---|
| 30 | AutoTransform& transform = static_cast<AutoTransform&>(obj); |
|---|
| 31 | |
|---|
| 32 | if (fr.matchSequence("position %f %f %f")) |
|---|
| 33 | { |
|---|
| 34 | osg::Vec3 pos; |
|---|
| 35 | fr[1].getFloat(pos[0]); |
|---|
| 36 | fr[2].getFloat(pos[1]); |
|---|
| 37 | fr[3].getFloat(pos[2]); |
|---|
| 38 | |
|---|
| 39 | transform.setPosition(pos); |
|---|
| 40 | |
|---|
| 41 | fr += 4; |
|---|
| 42 | iteratorAdvanced = true; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | if (fr.matchSequence("rotation %f %f %f %f")) |
|---|
| 46 | { |
|---|
| 47 | osg::Quat att; |
|---|
| 48 | fr[1].getFloat(att[0]); |
|---|
| 49 | fr[2].getFloat(att[1]); |
|---|
| 50 | fr[3].getFloat(att[2]); |
|---|
| 51 | fr[4].getFloat(att[3]); |
|---|
| 52 | |
|---|
| 53 | transform.setRotation(att); |
|---|
| 54 | |
|---|
| 55 | fr += 5; |
|---|
| 56 | iteratorAdvanced = true; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if (fr.matchSequence("scale %f %f %f")) |
|---|
| 60 | { |
|---|
| 61 | osg::Vec3 scale; |
|---|
| 62 | fr[1].getFloat(scale[0]); |
|---|
| 63 | fr[2].getFloat(scale[1]); |
|---|
| 64 | fr[3].getFloat(scale[2]); |
|---|
| 65 | |
|---|
| 66 | transform.setScale(scale); |
|---|
| 67 | |
|---|
| 68 | fr += 4; |
|---|
| 69 | iteratorAdvanced = true; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if (fr.matchSequence("minimumScale %f")) |
|---|
| 73 | { |
|---|
| 74 | float scale; |
|---|
| 75 | fr[1].getFloat(scale); |
|---|
| 76 | |
|---|
| 77 | transform.setMinimumScale(scale); |
|---|
| 78 | |
|---|
| 79 | fr += 2; |
|---|
| 80 | iteratorAdvanced = true; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if (fr.matchSequence("maximumScale %f")) |
|---|
| 84 | { |
|---|
| 85 | float scale; |
|---|
| 86 | fr[1].getFloat(scale); |
|---|
| 87 | |
|---|
| 88 | transform.setMaximumScale(scale); |
|---|
| 89 | |
|---|
| 90 | fr += 2; |
|---|
| 91 | iteratorAdvanced = true; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | if (fr.matchSequence("pivotPoint %f %f %f")) |
|---|
| 95 | { |
|---|
| 96 | osg::Vec3 pivot; |
|---|
| 97 | fr[1].getFloat(pivot[0]); |
|---|
| 98 | fr[2].getFloat(pivot[1]); |
|---|
| 99 | fr[3].getFloat(pivot[2]); |
|---|
| 100 | |
|---|
| 101 | transform.setPivotPoint(pivot); |
|---|
| 102 | |
|---|
| 103 | fr += 4; |
|---|
| 104 | iteratorAdvanced = true; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | if (fr.matchSequence("autoUpdateEyeMovementTolerance %f")) |
|---|
| 108 | { |
|---|
| 109 | float f; |
|---|
| 110 | fr[1].getFloat(f); |
|---|
| 111 | transform.setAutoUpdateEyeMovementTolerance(f); |
|---|
| 112 | fr += 2; |
|---|
| 113 | iteratorAdvanced = true; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | if (fr.matchSequence("autoRotateToScreen %w")) |
|---|
| 117 | { |
|---|
| 118 | std::string w(fr[1].getStr()); |
|---|
| 119 | transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION); |
|---|
| 120 | fr += 2; |
|---|
| 121 | iteratorAdvanced = true; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | if (fr.matchSequence("autoRotateMode %w")) |
|---|
| 125 | { |
|---|
| 126 | std::string w(fr[1].getStr()); |
|---|
| 127 | if (w=="ROTATE_TO_SCREEN") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN); |
|---|
| 128 | else if (w=="ROTATE_TO_CAMERA") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_CAMERA); |
|---|
| 129 | else if (w=="NO_ROTATION") transform.setAutoRotateMode(osg::AutoTransform::NO_ROTATION); |
|---|
| 130 | |
|---|
| 131 | fr += 2; |
|---|
| 132 | iteratorAdvanced = true; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | if (fr.matchSequence("autoScaleToScreen %w")) |
|---|
| 136 | { |
|---|
| 137 | std::string w(fr[1].getStr()); |
|---|
| 138 | transform.setAutoScaleToScreen(w == "TRUE"); |
|---|
| 139 | fr += 2; |
|---|
| 140 | iteratorAdvanced = true; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | if (fr.matchSequence("autoScaleTransistionWidthRatio %f") || |
|---|
| 144 | fr.matchSequence("autoScaleTransitionWidthRatio %f")) |
|---|
| 145 | { |
|---|
| 146 | float ratio; |
|---|
| 147 | fr[1].getFloat(ratio); |
|---|
| 148 | |
|---|
| 149 | transform.setAutoScaleTransitionWidthRatio(ratio); |
|---|
| 150 | |
|---|
| 151 | fr += 2; |
|---|
| 152 | iteratorAdvanced = true; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | return iteratorAdvanced; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | bool AutoTransform_writeLocalData(const Object& obj, Output& fw) |
|---|
| 161 | { |
|---|
| 162 | const AutoTransform& transform = static_cast<const AutoTransform&>(obj); |
|---|
| 163 | |
|---|
| 164 | fw.indent()<<"position "<<transform.getPosition()<<std::endl; |
|---|
| 165 | fw.indent()<<"rotation "<<transform.getRotation()<<std::endl; |
|---|
| 166 | fw.indent()<<"scale "<<transform.getScale()<<std::endl; |
|---|
| 167 | |
|---|
| 168 | if (transform.getMinimumScale()>0.0) fw.indent()<<"minimumScale "<<transform.getMinimumScale()<<std::endl; |
|---|
| 169 | if (transform.getMaximumScale()<FLT_MAX) fw.indent()<<"maximumScale "<<transform.getMaximumScale()<<std::endl; |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | fw.indent()<<"pivotPoint "<<transform.getPivotPoint()<<std::endl; |
|---|
| 173 | fw.indent()<<"autoUpdateEyeMovementTolerance "<<transform.getAutoUpdateEyeMovementTolerance()<<std::endl; |
|---|
| 174 | fw.indent()<<"autoRotateMode "; |
|---|
| 175 | switch(transform.getAutoRotateMode()) |
|---|
| 176 | { |
|---|
| 177 | case(osg::AutoTransform::ROTATE_TO_SCREEN): fw<<"ROTATE_TO_SCREEN"<<std::endl; break; |
|---|
| 178 | case(osg::AutoTransform::ROTATE_TO_CAMERA): fw<<"ROTATE_TO_CAMERA"<<std::endl; break; |
|---|
| 179 | case(osg::AutoTransform::NO_ROTATION): |
|---|
| 180 | default: fw<<"NO_ROTATION"<<std::endl; break; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | fw.indent()<<"autoScaleToScreen "<<(transform.getAutoScaleToScreen()?"TRUE":"FALSE")<<std::endl; |
|---|
| 184 | |
|---|
| 185 | if (transform.getAutoScaleTransitionWidthRatio()!=0.25) |
|---|
| 186 | { |
|---|
| 187 | fw.indent()<<"autoScaleTransitionWidthRatio "<<transform.getAutoScaleTransitionWidthRatio()<<std::endl; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | return true; |
|---|
| 191 | } |
|---|