| 1 | #include <osg/ArgumentParser> |
|---|
| 2 | |
|---|
| 3 | #include <osg/LightModel> |
|---|
| 4 | #include <osg/Depth> |
|---|
| 5 | #include <osg/BlendFunc> |
|---|
| 6 | #include <osg/Camera> |
|---|
| 7 | #include <osg/Stencil> |
|---|
| 8 | #include <osg/StencilTwoSided> |
|---|
| 9 | #include <osg/CullFace> |
|---|
| 10 | #include <osg/Geometry> |
|---|
| 11 | #include <osg/Switch> |
|---|
| 12 | |
|---|
| 13 | #include <osgGA/TrackballManipulator> |
|---|
| 14 | #include <osgGA/FlightManipulator> |
|---|
| 15 | #include <osgGA/DriveManipulator> |
|---|
| 16 | #include <osgGA/KeySwitchMatrixManipulator> |
|---|
| 17 | #include <osgGA/AnimationPathManipulator> |
|---|
| 18 | #include <osgGA/TerrainManipulator> |
|---|
| 19 | #include <osgGA/AnimationPathManipulator> |
|---|
| 20 | #include <osgGA/StateSetManipulator> |
|---|
| 21 | |
|---|
| 22 | #include <osgViewer/Viewer> |
|---|
| 23 | #include <osgViewer/StatsHandler> |
|---|
| 24 | |
|---|
| 25 | #include <osgShadow/OccluderGeometry> |
|---|
| 26 | |
|---|
| 27 | #include <osgDB/ReadFile> |
|---|
| 28 | #include <osgDB/WriteFile> |
|---|
| 29 | |
|---|
| 30 | #include <iostream> |
|---|
| 31 | |
|---|
| 32 | class ComputeBoundingBoxVisitor : public osg::NodeVisitor |
|---|
| 33 | { |
|---|
| 34 | public: |
|---|
| 35 | ComputeBoundingBoxVisitor(): |
|---|
| 36 | osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) |
|---|
| 37 | { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | virtual void reset() |
|---|
| 41 | { |
|---|
| 42 | _matrixStack.clear(); |
|---|
| 43 | _bb.init(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | osg::BoundingBox& getBoundingBox() { return _bb; } |
|---|
| 47 | |
|---|
| 48 | void getPolytope(osg::Polytope& polytope, float margin=0.1) const |
|---|
| 49 | { |
|---|
| 50 | float delta = _bb.radius()*margin; |
|---|
| 51 | polytope.add( osg::Plane(0.0, 0.0, 1.0, -(_bb.zMin()-delta)) ); |
|---|
| 52 | polytope.add( osg::Plane(0.0, 0.0, -1.0, (_bb.zMax()+delta)) ); |
|---|
| 53 | |
|---|
| 54 | polytope.add( osg::Plane(1.0, 0.0, 0.0, -(_bb.xMin()-delta)) ); |
|---|
| 55 | polytope.add( osg::Plane(-1.0, 0.0, 0.0, (_bb.xMax()+delta)) ); |
|---|
| 56 | |
|---|
| 57 | polytope.add( osg::Plane(0.0, 1.0, 0.0, -(_bb.yMin()-delta)) ); |
|---|
| 58 | polytope.add( osg::Plane(0.0, -1.0, 0.0, (_bb.yMax()+delta)) ); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void getBase(osg::Polytope& polytope, float margin=0.1) const |
|---|
| 62 | { |
|---|
| 63 | float delta = _bb.radius()*margin; |
|---|
| 64 | polytope.add( osg::Plane(0.0, 0.0, 1.0, -(_bb.zMin()-delta)) ); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void apply(osg::Node& node) |
|---|
| 68 | { |
|---|
| 69 | traverse(node); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void apply(osg::Transform& transform) |
|---|
| 73 | { |
|---|
| 74 | osg::Matrix matrix; |
|---|
| 75 | if (!_matrixStack.empty()) matrix = _matrixStack.back(); |
|---|
| 76 | |
|---|
| 77 | transform.computeLocalToWorldMatrix(matrix,this); |
|---|
| 78 | |
|---|
| 79 | pushMatrix(matrix); |
|---|
| 80 | |
|---|
| 81 | traverse(transform); |
|---|
| 82 | |
|---|
| 83 | popMatrix(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void apply(osg::Geode& geode) |
|---|
| 87 | { |
|---|
| 88 | for(unsigned int i=0; i<geode.getNumDrawables(); ++i) |
|---|
| 89 | { |
|---|
| 90 | apply(geode.getDrawable(i)); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void pushMatrix(osg::Matrix& matrix) |
|---|
| 95 | { |
|---|
| 96 | _matrixStack.push_back(matrix); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | void popMatrix() |
|---|
| 100 | { |
|---|
| 101 | _matrixStack.pop_back(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void apply(osg::Drawable* drawable) |
|---|
| 105 | { |
|---|
| 106 | if (_matrixStack.empty()) _bb.expandBy(drawable->getBound()); |
|---|
| 107 | else |
|---|
| 108 | { |
|---|
| 109 | osg::Matrix& matrix = _matrixStack.back(); |
|---|
| 110 | const osg::BoundingBox& dbb = drawable->getBound(); |
|---|
| 111 | if (dbb.valid()) |
|---|
| 112 | { |
|---|
| 113 | _bb.expandBy(dbb.corner(0) * matrix); |
|---|
| 114 | _bb.expandBy(dbb.corner(1) * matrix); |
|---|
| 115 | _bb.expandBy(dbb.corner(2) * matrix); |
|---|
| 116 | _bb.expandBy(dbb.corner(3) * matrix); |
|---|
| 117 | _bb.expandBy(dbb.corner(4) * matrix); |
|---|
| 118 | _bb.expandBy(dbb.corner(5) * matrix); |
|---|
| 119 | _bb.expandBy(dbb.corner(6) * matrix); |
|---|
| 120 | _bb.expandBy(dbb.corner(7) * matrix); |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | protected: |
|---|
| 126 | |
|---|
| 127 | typedef std::vector<osg::Matrix> MatrixStack; |
|---|
| 128 | |
|---|
| 129 | MatrixStack _matrixStack; |
|---|
| 130 | osg::BoundingBox _bb; |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | enum Faces |
|---|
| 134 | { |
|---|
| 135 | FRONT_FACE = 1, |
|---|
| 136 | BACK_FACE = 2, |
|---|
| 137 | LEFT_FACE = 4, |
|---|
| 138 | RIGHT_FACE = 8, |
|---|
| 139 | TOP_FACE = 16, |
|---|
| 140 | BOTTOM_FACE = 32 |
|---|
| 141 | }; |
|---|
| 142 | |
|---|
| 143 | osg::Node* createCube(unsigned int mask) |
|---|
| 144 | { |
|---|
| 145 | osg::Geode* geode = new osg::Geode; |
|---|
| 146 | |
|---|
| 147 | osg::Geometry* geometry = new osg::Geometry; |
|---|
| 148 | geode->addDrawable(geometry); |
|---|
| 149 | |
|---|
| 150 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 151 | geometry->setVertexArray(vertices); |
|---|
| 152 | |
|---|
| 153 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 154 | geometry->setNormalArray(normals); |
|---|
| 155 | geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 156 | |
|---|
| 157 | osg::Vec4Array* colours = new osg::Vec4Array; |
|---|
| 158 | geometry->setColorArray(colours); |
|---|
| 159 | geometry->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 160 | colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | osg::Vec3 origin(0.0f,0.0f,0.0f); |
|---|
| 164 | osg::Vec3 dx(2.0f,0.0f,0.0f); |
|---|
| 165 | osg::Vec3 dy(0.0f,1.0f,0.0f); |
|---|
| 166 | osg::Vec3 dz(0.0f,0.0f,1.0f); |
|---|
| 167 | |
|---|
| 168 | osg::Vec3 px(1.0f,0.0,0.0f); |
|---|
| 169 | osg::Vec3 nx(-1.0f,0.0,0.0f); |
|---|
| 170 | osg::Vec3 py(0.0f,1.0f,0.0f); |
|---|
| 171 | osg::Vec3 ny(0.0f,-1.0f,0.0f); |
|---|
| 172 | osg::Vec3 pz(0.0f,0.0f,1.0f); |
|---|
| 173 | osg::Vec3 nz(0.0f,0.0f,-1.0f); |
|---|
| 174 | |
|---|
| 175 | if (mask & FRONT_FACE) |
|---|
| 176 | { |
|---|
| 177 | |
|---|
| 178 | vertices->push_back(origin); |
|---|
| 179 | vertices->push_back(origin+dx); |
|---|
| 180 | vertices->push_back(origin+dx+dz); |
|---|
| 181 | vertices->push_back(origin+dz); |
|---|
| 182 | normals->push_back(ny); |
|---|
| 183 | normals->push_back(ny); |
|---|
| 184 | normals->push_back(ny); |
|---|
| 185 | normals->push_back(ny); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | if (mask & BACK_FACE) |
|---|
| 189 | { |
|---|
| 190 | |
|---|
| 191 | vertices->push_back(origin+dy); |
|---|
| 192 | vertices->push_back(origin+dy+dz); |
|---|
| 193 | vertices->push_back(origin+dy+dx+dz); |
|---|
| 194 | vertices->push_back(origin+dy+dx); |
|---|
| 195 | normals->push_back(py); |
|---|
| 196 | normals->push_back(py); |
|---|
| 197 | normals->push_back(py); |
|---|
| 198 | normals->push_back(py); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | if (mask & LEFT_FACE) |
|---|
| 202 | { |
|---|
| 203 | |
|---|
| 204 | vertices->push_back(origin+dy); |
|---|
| 205 | vertices->push_back(origin); |
|---|
| 206 | vertices->push_back(origin+dz); |
|---|
| 207 | vertices->push_back(origin+dy+dz); |
|---|
| 208 | normals->push_back(nx); |
|---|
| 209 | normals->push_back(nx); |
|---|
| 210 | normals->push_back(nx); |
|---|
| 211 | normals->push_back(nx); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | if (mask & RIGHT_FACE) |
|---|
| 215 | { |
|---|
| 216 | |
|---|
| 217 | vertices->push_back(origin+dx+dy); |
|---|
| 218 | vertices->push_back(origin+dx+dy+dz); |
|---|
| 219 | vertices->push_back(origin+dx+dz); |
|---|
| 220 | vertices->push_back(origin+dx); |
|---|
| 221 | normals->push_back(px); |
|---|
| 222 | normals->push_back(px); |
|---|
| 223 | normals->push_back(px); |
|---|
| 224 | normals->push_back(px); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | if (mask & TOP_FACE) |
|---|
| 228 | { |
|---|
| 229 | |
|---|
| 230 | vertices->push_back(origin+dz); |
|---|
| 231 | vertices->push_back(origin+dz+dx); |
|---|
| 232 | vertices->push_back(origin+dz+dx+dy); |
|---|
| 233 | vertices->push_back(origin+dz+dy); |
|---|
| 234 | normals->push_back(pz); |
|---|
| 235 | normals->push_back(pz); |
|---|
| 236 | normals->push_back(pz); |
|---|
| 237 | normals->push_back(pz); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | if (mask & BOTTOM_FACE) |
|---|
| 241 | { |
|---|
| 242 | |
|---|
| 243 | vertices->push_back(origin); |
|---|
| 244 | vertices->push_back(origin+dy); |
|---|
| 245 | vertices->push_back(origin+dx+dy); |
|---|
| 246 | vertices->push_back(origin+dx); |
|---|
| 247 | normals->push_back(nz); |
|---|
| 248 | normals->push_back(nz); |
|---|
| 249 | normals->push_back(nz); |
|---|
| 250 | normals->push_back(nz); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); |
|---|
| 254 | |
|---|
| 255 | return geode; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | class SwitchHandler : public osgGA::GUIEventHandler |
|---|
| 259 | { |
|---|
| 260 | public: |
|---|
| 261 | |
|---|
| 262 | SwitchHandler(): |
|---|
| 263 | _childNum(0) {} |
|---|
| 264 | |
|---|
| 265 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& , osg::Object* object, osg::NodeVisitor* ) |
|---|
| 266 | { |
|---|
| 267 | osg::Switch* sw = dynamic_cast<osg::Switch*>(object); |
|---|
| 268 | if (!sw) return false; |
|---|
| 269 | |
|---|
| 270 | if (ea.getHandled()) return false; |
|---|
| 271 | |
|---|
| 272 | switch(ea.getEventType()) |
|---|
| 273 | { |
|---|
| 274 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 275 | { |
|---|
| 276 | if (ea.getKey()=='n') |
|---|
| 277 | { |
|---|
| 278 | ++_childNum; |
|---|
| 279 | if (_childNum >= sw->getNumChildren()) _childNum = 0; |
|---|
| 280 | |
|---|
| 281 | sw->setSingleChildOn(_childNum); |
|---|
| 282 | return true; |
|---|
| 283 | } |
|---|
| 284 | break; |
|---|
| 285 | } |
|---|
| 286 | default: |
|---|
| 287 | break; |
|---|
| 288 | } |
|---|
| 289 | return false; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | protected: |
|---|
| 293 | |
|---|
| 294 | virtual ~SwitchHandler() {} |
|---|
| 295 | unsigned int _childNum; |
|---|
| 296 | |
|---|
| 297 | }; |
|---|
| 298 | |
|---|
| 299 | osg::Node* createTestModel() |
|---|
| 300 | { |
|---|
| 301 | osg::Switch* sw = new osg::Switch; |
|---|
| 302 | sw->setEventCallback(new SwitchHandler); |
|---|
| 303 | |
|---|
| 304 | sw->addChild(createCube(FRONT_FACE), true); |
|---|
| 305 | sw->addChild(createCube(FRONT_FACE | BACK_FACE), false); |
|---|
| 306 | sw->addChild(createCube(FRONT_FACE | BACK_FACE | LEFT_FACE), false); |
|---|
| 307 | sw->addChild(createCube(FRONT_FACE | BACK_FACE | LEFT_FACE | RIGHT_FACE), false); |
|---|
| 308 | sw->addChild(createCube(FRONT_FACE | BACK_FACE | LEFT_FACE | RIGHT_FACE | TOP_FACE), false); |
|---|
| 309 | sw->addChild(createCube(FRONT_FACE | BACK_FACE | LEFT_FACE | RIGHT_FACE | TOP_FACE | BOTTOM_FACE), false); |
|---|
| 310 | |
|---|
| 311 | return sw; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | class ShadowCallback : public osg::NodeCallback |
|---|
| 317 | { |
|---|
| 318 | public: |
|---|
| 319 | |
|---|
| 320 | osg::Vec4 _lightpos; |
|---|
| 321 | osg::ref_ptr<osg::StateSet> _ss1; |
|---|
| 322 | |
|---|
| 323 | ShadowCallback() |
|---|
| 324 | { |
|---|
| 325 | osg::Vec4 ambient(0.2,0.2,0.2,1.0); |
|---|
| 326 | osg::Vec4 diffuse(0.8,0.8,0.8,1.0); |
|---|
| 327 | osg::Vec4 zero_colour(0.0,0.0,0.0,1.0); |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | { |
|---|
| 331 | _ss1 = new osg::StateSet; |
|---|
| 332 | |
|---|
| 333 | osg::LightModel* lm1 = new osg::LightModel; |
|---|
| 334 | lm1->setAmbientIntensity(ambient); |
|---|
| 335 | _ss1->setAttribute(lm1); |
|---|
| 336 | |
|---|
| 337 | osg::Light* light1 = new osg::Light; |
|---|
| 338 | light1->setAmbient(ambient); |
|---|
| 339 | light1->setDiffuse(zero_colour); |
|---|
| 340 | light1->setPosition(_lightpos); |
|---|
| 341 | _ss1->setAttributeAndModes(light1, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 342 | _ss1->setMode(GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 347 | { |
|---|
| 348 | osg::notify(osg::NOTICE)<<"We're in callback"<<std::endl; |
|---|
| 349 | |
|---|
| 350 | osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); |
|---|
| 351 | if (!cv) |
|---|
| 352 | { |
|---|
| 353 | traverse(node,nv); |
|---|
| 354 | return; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | osg::ref_ptr<osgUtil::RenderBin> original_bin = cv->getCurrentRenderBin(); |
|---|
| 358 | |
|---|
| 359 | osg::ref_ptr<osgUtil::RenderBin> new_bin = original_bin->find_or_insert(999,"RenderBin"); |
|---|
| 360 | |
|---|
| 361 | cv->setCurrentRenderBin(new_bin.get()); |
|---|
| 362 | |
|---|
| 363 | traverse(node,nv); |
|---|
| 364 | |
|---|
| 365 | cv->setCurrentRenderBin(original_bin.get()); |
|---|
| 366 | |
|---|
| 367 | osg::notify(osg::NOTICE)<<"new_bin->getStateGraphList().size()= "<<new_bin->getStateGraphList().size()<<std::endl; |
|---|
| 368 | osg::notify(osg::NOTICE)<<"new_bin->getRenderBinList().size()= "<<new_bin->getRenderBinList().size()<<std::endl; |
|---|
| 369 | osg::notify(osg::NOTICE)<<"new_bin->getRenderLeafList().size()= "<<new_bin->getRenderLeafList().size()<<std::endl; |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | for(osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().begin(); |
|---|
| 373 | itr != new_bin->getRenderBinList().end(); |
|---|
| 374 | ++itr) |
|---|
| 375 | { |
|---|
| 376 | osg::notify(osg::NOTICE)<<"bin num = "<<itr->first<<std::endl; |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().find(1000); |
|---|
| 381 | osg::ref_ptr<osgUtil::RenderBin> shadowVolumeBin; |
|---|
| 382 | if (itr != new_bin->getRenderBinList().end()) |
|---|
| 383 | { |
|---|
| 384 | shadowVolumeBin = itr->second; |
|---|
| 385 | |
|---|
| 386 | if (shadowVolumeBin.valid()) |
|---|
| 387 | { |
|---|
| 388 | osg::notify(osg::NOTICE)<<"Found shadow volume bin, now removing it"<<std::endl; |
|---|
| 389 | new_bin->getRenderBinList().erase(itr); |
|---|
| 390 | } |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | for(osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().begin(); |
|---|
| 394 | itr != new_bin->getRenderBinList().end(); |
|---|
| 395 | ++itr) |
|---|
| 396 | { |
|---|
| 397 | osg::notify(osg::NOTICE)<<"bin num = "<<itr->first<<std::endl; |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | osg::notify(osg::NOTICE)<<"after new_bin->getStateGraphList().size()= "<<new_bin->getStateGraphList().size()<<std::endl; |
|---|
| 401 | osg::notify(osg::NOTICE)<<"after new_bin->getRenderBinList().size()= "<<new_bin->getRenderBinList().size()<<std::endl; |
|---|
| 402 | osg::notify(osg::NOTICE)<<"after new_bin->getRenderLeafList().size()= "<<new_bin->getRenderLeafList().size()<<std::endl; |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | original_bin->setStateSet(_ss1.get()); |
|---|
| 406 | |
|---|
| 407 | osgUtil::RenderStage* orig_rs = cv->getRenderStage(); |
|---|
| 408 | osgUtil::RenderStage* new_rs = new osgUtil::RenderStage; |
|---|
| 409 | orig_rs->addPostRenderStage(new_rs); |
|---|
| 410 | |
|---|
| 411 | new_rs->setViewport(orig_rs->getViewport()); |
|---|
| 412 | new_rs->setClearColor(orig_rs->getClearColor()); |
|---|
| 413 | new_rs->setClearMask(GL_STENCIL_BUFFER_BIT); |
|---|
| 414 | |
|---|
| 415 | if (shadowVolumeBin.valid()) |
|---|
| 416 | { |
|---|
| 417 | new_rs->getRenderBinList()[0] = shadowVolumeBin; |
|---|
| 418 | new_rs->getRenderBinList()[1] = new_bin; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | } |
|---|
| 423 | }; |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | int main(int argc, char** argv) |
|---|
| 428 | { |
|---|
| 429 | |
|---|
| 430 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " is the example which demonstrates using of GL_ARB_shadow extension implemented in osg::Texture class"); |
|---|
| 434 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()); |
|---|
| 435 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help", "Display this information"); |
|---|
| 436 | arguments.getApplicationUsage()->addCommandLineOption("--positionalLight", "Use a positional light."); |
|---|
| 437 | arguments.getApplicationUsage()->addCommandLineOption("--directionalLight", "Use a direction light."); |
|---|
| 438 | arguments.getApplicationUsage()->addCommandLineOption("--addOccluderToScene", "Add the occluders geometry."); |
|---|
| 439 | arguments.getApplicationUsage()->addCommandLineOption("--noUpdate", "Disable the updating the of light source."); |
|---|
| 440 | arguments.getApplicationUsage()->addCommandLineOption("--base", "Add a base geometry to test shadows."); |
|---|
| 441 | arguments.getApplicationUsage()->addCommandLineOption("--noShadow", "Disable the shadows."); |
|---|
| 442 | arguments.getApplicationUsage()->addCommandLineOption("--two-sided", "Use two-sided stencil extension for shadow volumes."); |
|---|
| 443 | arguments.getApplicationUsage()->addCommandLineOption("--two-pass", "Use two-pass stencil for shadow volumes."); |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | osg::DisplaySettings::instance()->setMinimumNumStencilBits(8); |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | osgViewer::Viewer viewer; |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 453 | { |
|---|
| 454 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 455 | return 1; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | bool postionalLight = false; |
|---|
| 459 | while (arguments.read("--positionalLight")) postionalLight = true; |
|---|
| 460 | while (arguments.read("--directionalLight")) postionalLight = false; |
|---|
| 461 | |
|---|
| 462 | bool addOccluderToScene = false; |
|---|
| 463 | while (arguments.read("--addOccluderToScene")) addOccluderToScene = true; |
|---|
| 464 | |
|---|
| 465 | bool updateLightPosition = true; |
|---|
| 466 | while (arguments.read("--noUpdate")) updateLightPosition = false; |
|---|
| 467 | |
|---|
| 468 | bool createBase = false; |
|---|
| 469 | while (arguments.read("--base")) createBase = true; |
|---|
| 470 | |
|---|
| 471 | bool doShadow = true; |
|---|
| 472 | while (arguments.read("--noShadow")) doShadow = false; |
|---|
| 473 | |
|---|
| 474 | bool cullCallback = false; |
|---|
| 475 | while (arguments.read("-c")) cullCallback = true; |
|---|
| 476 | |
|---|
| 477 | int screenNum = -1; |
|---|
| 478 | while (arguments.read("--screen", screenNum)) viewer.setUpViewOnSingleScreen(screenNum); |
|---|
| 479 | |
|---|
| 480 | osgShadow::ShadowVolumeGeometry::DrawMode drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED; |
|---|
| 481 | while (arguments.read("--two-sided")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED; |
|---|
| 482 | while (arguments.read("--two-pass")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_PASS; |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | { |
|---|
| 487 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
|---|
| 488 | |
|---|
| 489 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
|---|
| 490 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
|---|
| 491 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
|---|
| 492 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
|---|
| 493 | |
|---|
| 494 | std::string pathfile; |
|---|
| 495 | char keyForAnimationPath = '5'; |
|---|
| 496 | while (arguments.read("-p",pathfile)) |
|---|
| 497 | { |
|---|
| 498 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
|---|
| 499 | if (apm || !apm->valid()) |
|---|
| 500 | { |
|---|
| 501 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
|---|
| 502 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
|---|
| 503 | keyswitchManipulator->selectMatrixManipulator(num); |
|---|
| 504 | ++keyForAnimationPath; |
|---|
| 505 | } |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | viewer.addEventHandler( new osgViewer::StatsHandler() ); |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | if (arguments.errors()) |
|---|
| 523 | { |
|---|
| 524 | arguments.writeErrorMessages(std::cout); |
|---|
| 525 | return 1; |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments); |
|---|
| 530 | if (!model) |
|---|
| 531 | { |
|---|
| 532 | model = createTestModel(); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | ComputeBoundingBoxVisitor cbbv; |
|---|
| 537 | model->accept(cbbv); |
|---|
| 538 | osg::BoundingBox bb = cbbv.getBoundingBox(); |
|---|
| 539 | |
|---|
| 540 | if (createBase) |
|---|
| 541 | { |
|---|
| 542 | osg::ref_ptr<osg::Group> newGroup = new osg::Group; |
|---|
| 543 | newGroup->addChild(model.get()); |
|---|
| 544 | |
|---|
| 545 | osg::Geode* geode = new osg::Geode; |
|---|
| 546 | |
|---|
| 547 | osg::Vec3 widthVec(bb.radius(), 0.0f, 0.0f); |
|---|
| 548 | osg::Vec3 depthVec(0.0f, bb.radius(), 0.0f); |
|---|
| 549 | osg::Vec3 centerBase( (bb.xMin()+bb.xMax())*0.5f, (bb.yMin()+bb.yMax())*0.5f, bb.zMin()-bb.radius()*0.1f ); |
|---|
| 550 | |
|---|
| 551 | geode->addDrawable( osg::createTexturedQuadGeometry( centerBase-widthVec*1.5f-depthVec*1.5f, |
|---|
| 552 | widthVec*3.0f, depthVec*3.0f) ); |
|---|
| 553 | newGroup->addChild(geode); |
|---|
| 554 | |
|---|
| 555 | model = newGroup.get(); |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | cbbv.reset(); |
|---|
| 560 | model->accept(cbbv); |
|---|
| 561 | bb = cbbv.getBoundingBox(); |
|---|
| 562 | |
|---|
| 563 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry; |
|---|
| 567 | occluder->computeOccluderGeometry(model.get()); |
|---|
| 568 | |
|---|
| 569 | cbbv.getBase(occluder->getBoundingPolytope(),0.001); |
|---|
| 570 | |
|---|
| 571 | if (addOccluderToScene) |
|---|
| 572 | { |
|---|
| 573 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
|---|
| 574 | geode->addDrawable(occluder.get()); |
|---|
| 575 | group->addChild(geode.get()); |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | osg::ref_ptr<osgShadow::ShadowVolumeGeometry> shadowVolume = new osgShadow::ShadowVolumeGeometry; |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | shadowVolume->setUseDisplayList(false); |
|---|
| 582 | |
|---|
| 583 | osg::Vec4 lightpos; |
|---|
| 584 | |
|---|
| 585 | if (postionalLight) |
|---|
| 586 | { |
|---|
| 587 | lightpos.set(bb.center().x(), bb.center().y(), bb.zMax() + bb.radius() ,1.0f); |
|---|
| 588 | } |
|---|
| 589 | else |
|---|
| 590 | { |
|---|
| 591 | lightpos.set(0.5f,0.25f,0.8f,0.0f); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | osg::ref_ptr<osg::Light> light = new osg::Light; |
|---|
| 597 | |
|---|
| 598 | if (!doShadow) |
|---|
| 599 | { |
|---|
| 600 | group->addChild(model.get()); |
|---|
| 601 | |
|---|
| 602 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
|---|
| 603 | occluder->computeShadowVolumeGeometry(lightpos, *shadowVolume); |
|---|
| 604 | geode->addDrawable(shadowVolume.get()); |
|---|
| 605 | group->addChild(geode.get()); |
|---|
| 606 | |
|---|
| 607 | osg::StateSet* ss = geode->getOrCreateStateSet(); |
|---|
| 608 | ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 609 | |
|---|
| 610 | } |
|---|
| 611 | else if (cullCallback) |
|---|
| 612 | { |
|---|
| 613 | |
|---|
| 614 | int shadowVolumeBin = 1000; |
|---|
| 615 | |
|---|
| 616 | group->setCullCallback(new ShadowCallback()); |
|---|
| 617 | |
|---|
| 618 | group->addChild(model.get()); |
|---|
| 619 | |
|---|
| 620 | { |
|---|
| 621 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
|---|
| 622 | group->addChild(geode.get()); |
|---|
| 623 | |
|---|
| 624 | occluder->computeShadowVolumeGeometry(lightpos, *shadowVolume); |
|---|
| 625 | shadowVolume->setDrawMode(drawMode); |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | if (drawMode == osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED) |
|---|
| 629 | { |
|---|
| 630 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_SIDED seleteced"<<std::endl; |
|---|
| 631 | |
|---|
| 632 | osg::StencilTwoSided* stencil = new osg::StencilTwoSided; |
|---|
| 633 | stencil->setFunction(osg::StencilTwoSided::BACK, osg::StencilTwoSided::ALWAYS,0,~0u); |
|---|
| 634 | stencil->setOperation(osg::StencilTwoSided::BACK, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::DECR_WRAP); |
|---|
| 635 | stencil->setFunction(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::ALWAYS,0,~0u); |
|---|
| 636 | stencil->setOperation(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::INCR_WRAP); |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
|---|
| 640 | |
|---|
| 641 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
|---|
| 642 | ss_sv1->setRenderBinDetails(shadowVolumeBin, "RenderBin"); |
|---|
| 643 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
|---|
| 644 | ss_sv1->setAttribute(colourMask); |
|---|
| 645 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | } |
|---|
| 649 | else |
|---|
| 650 | { |
|---|
| 651 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_PASSES seleteced"<<std::endl; |
|---|
| 652 | |
|---|
| 653 | osg::Stencil* stencil = new osg::Stencil; |
|---|
| 654 | stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); |
|---|
| 655 | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); |
|---|
| 656 | |
|---|
| 657 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
|---|
| 658 | |
|---|
| 659 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
|---|
| 660 | ss_sv1->setRenderBinDetails(shadowVolumeBin, "RenderBin"); |
|---|
| 661 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
|---|
| 662 | ss_sv1->setAttribute(colourMask); |
|---|
| 663 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::ON); |
|---|
| 664 | |
|---|
| 665 | geode->addDrawable(shadowVolume.get()); |
|---|
| 666 | } |
|---|
| 667 | |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | } |
|---|
| 671 | else |
|---|
| 672 | { |
|---|
| 673 | osg::Vec4 ambient(0.2,0.2,0.2,1.0); |
|---|
| 674 | osg::Vec4 diffuse(0.8,0.8,0.8,1.0); |
|---|
| 675 | osg::Vec4 zero_colour(0.0,0.0,0.0,1.0); |
|---|
| 676 | |
|---|
| 677 | |
|---|
| 678 | { |
|---|
| 679 | |
|---|
| 680 | osg::Group* first_model_group = new osg::Group; |
|---|
| 681 | first_model_group->addChild(model.get()); |
|---|
| 682 | group->addChild(first_model_group); |
|---|
| 683 | |
|---|
| 684 | osg::StateSet* ss1 = first_model_group->getOrCreateStateSet(); |
|---|
| 685 | |
|---|
| 686 | osg::LightModel* lm1 = new osg::LightModel; |
|---|
| 687 | lm1->setAmbientIntensity(ambient); |
|---|
| 688 | ss1->setAttribute(lm1); |
|---|
| 689 | |
|---|
| 690 | osg::Light* light1 = new osg::Light; |
|---|
| 691 | light1->setAmbient(ambient); |
|---|
| 692 | light1->setDiffuse(zero_colour); |
|---|
| 693 | light1->setPosition(lightpos); |
|---|
| 694 | ss1->setAttributeAndModes(light1, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 695 | ss1->setMode(GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 696 | |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | { |
|---|
| 701 | |
|---|
| 702 | osg::Camera* camera = new osg::Camera; |
|---|
| 703 | camera->setRenderOrder(osg::Camera::POST_RENDER); |
|---|
| 704 | camera->setClearMask(GL_STENCIL_BUFFER_BIT); |
|---|
| 705 | group->addChild(camera); |
|---|
| 706 | |
|---|
| 707 | osg::StateSet* ss_camera = camera->getOrCreateStateSet(); |
|---|
| 708 | |
|---|
| 709 | osg::Depth* depth = new osg::Depth; |
|---|
| 710 | depth->setWriteMask(false); |
|---|
| 711 | depth->setFunction(osg::Depth::LEQUAL); |
|---|
| 712 | ss_camera->setAttribute(depth); |
|---|
| 713 | |
|---|
| 714 | { |
|---|
| 715 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
|---|
| 716 | occluder->computeShadowVolumeGeometry(lightpos, *shadowVolume); |
|---|
| 717 | shadowVolume->setDrawMode(drawMode); |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | if (drawMode == osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED) |
|---|
| 721 | { |
|---|
| 722 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_SIDED seleteced"<<std::endl; |
|---|
| 723 | |
|---|
| 724 | osg::StencilTwoSided* stencil = new osg::StencilTwoSided; |
|---|
| 725 | stencil->setFunction(osg::StencilTwoSided::BACK, osg::StencilTwoSided::ALWAYS,0,~0u); |
|---|
| 726 | stencil->setOperation(osg::StencilTwoSided::BACK, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::DECR_WRAP); |
|---|
| 727 | stencil->setFunction(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::ALWAYS,0,~0u); |
|---|
| 728 | stencil->setOperation(osg::StencilTwoSided::FRONT, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::KEEP, osg::StencilTwoSided::INCR_WRAP); |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
|---|
| 732 | |
|---|
| 733 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
|---|
| 734 | ss_sv1->setRenderBinDetails(0, "RenderBin"); |
|---|
| 735 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
|---|
| 736 | ss_sv1->setAttribute(colourMask); |
|---|
| 737 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); |
|---|
| 738 | |
|---|
| 739 | geode->addDrawable(shadowVolume.get()); |
|---|
| 740 | |
|---|
| 741 | camera->addChild(geode.get()); |
|---|
| 742 | |
|---|
| 743 | } |
|---|
| 744 | else |
|---|
| 745 | { |
|---|
| 746 | osg::notify(osg::NOTICE)<<"STENCIL_TWO_PASSES seleteced"<<std::endl; |
|---|
| 747 | |
|---|
| 748 | osg::Stencil* stencil = new osg::Stencil; |
|---|
| 749 | stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); |
|---|
| 750 | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); |
|---|
| 751 | |
|---|
| 752 | osg::ColorMask* colourMask = new osg::ColorMask(false, false, false, false); |
|---|
| 753 | |
|---|
| 754 | osg::StateSet* ss_sv1 = geode->getOrCreateStateSet(); |
|---|
| 755 | ss_sv1->setRenderBinDetails(0, "RenderBin"); |
|---|
| 756 | ss_sv1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
|---|
| 757 | ss_sv1->setAttribute(colourMask); |
|---|
| 758 | ss_sv1->setMode(GL_CULL_FACE,osg::StateAttribute::ON); |
|---|
| 759 | |
|---|
| 760 | geode->addDrawable(shadowVolume.get()); |
|---|
| 761 | |
|---|
| 762 | camera->addChild(geode.get()); |
|---|
| 763 | } |
|---|
| 764 | |
|---|
| 765 | } |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | { |
|---|
| 770 | osg::Group* second_model_group = new osg::Group; |
|---|
| 771 | second_model_group->addChild(model.get()); |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | osg::StateSet* ss1 = second_model_group->getOrCreateStateSet(); |
|---|
| 775 | ss1->setRenderBinDetails(5, "RenderBin"); |
|---|
| 776 | |
|---|
| 777 | osg::LightModel* lm1 = new osg::LightModel; |
|---|
| 778 | lm1->setAmbientIntensity(zero_colour); |
|---|
| 779 | ss1->setAttribute(lm1); |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | osg::LightSource* lightsource = new osg::LightSource; |
|---|
| 783 | lightsource->setLight(light.get()); |
|---|
| 784 | light->setAmbient(zero_colour); |
|---|
| 785 | light->setDiffuse(diffuse); |
|---|
| 786 | light->setPosition(lightpos); |
|---|
| 787 | second_model_group->addChild(lightsource); |
|---|
| 788 | |
|---|
| 789 | ss1->setMode(GL_LIGHT0, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | osg::Stencil* stencil = new osg::Stencil; |
|---|
| 793 | stencil->setFunction(osg::Stencil::EQUAL,0,~0u); |
|---|
| 794 | stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); |
|---|
| 795 | ss1->setAttributeAndModes(stencil,osg::StateAttribute::ON); |
|---|
| 796 | |
|---|
| 797 | osg::BlendFunc* blend = new osg::BlendFunc; |
|---|
| 798 | blend->setFunction(osg::BlendFunc::ONE, osg::BlendFunc::ONE); |
|---|
| 799 | ss1->setAttributeAndModes(blend, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 800 | ss1->setMode(GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); |
|---|
| 801 | |
|---|
| 802 | camera->addChild(second_model_group); |
|---|
| 803 | } |
|---|
| 804 | |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | viewer.setSceneData(group.get()); |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | viewer.realize(); |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | while (!viewer.done()) |
|---|
| 818 | { |
|---|
| 819 | if (updateLightPosition) |
|---|
| 820 | { |
|---|
| 821 | float t = viewer.getFrameStamp()->getSimulationTime(); |
|---|
| 822 | if (postionalLight) |
|---|
| 823 | { |
|---|
| 824 | lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius() ,1.0f); |
|---|
| 825 | } |
|---|
| 826 | else |
|---|
| 827 | { |
|---|
| 828 | lightpos.set(sinf(t),cosf(t),0.8f,0.0f); |
|---|
| 829 | } |
|---|
| 830 | light->setPosition(lightpos); |
|---|
| 831 | occluder->computeShadowVolumeGeometry(lightpos, *shadowVolume); |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | viewer.frame(); |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | return 0; |
|---|
| 838 | } |
|---|