| | 585 | namespace ModelFive |
| | 586 | { |
| | 587 | osg::AnimationPathCallback* createAnimationPathCallback( float radius, float time ) |
| | 588 | { |
| | 589 | osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath; |
| | 590 | path->setLoopMode( osg::AnimationPath::LOOP ); |
| | 591 | |
| | 592 | unsigned int numSamples = 32; |
| | 593 | float delta_yaw = 2.0f * osg::PI/((float)numSamples - 1.0f); |
| | 594 | float delta_time = time / (float)numSamples; |
| | 595 | for ( unsigned int i=0; i<numSamples; ++i ) |
| | 596 | { |
| | 597 | float yaw = delta_yaw * (float)i; |
| | 598 | osg::Vec3 pos( sinf(yaw)*radius, cosf(yaw)*radius, 0.0f ); |
| | 599 | osg::Quat rot( -yaw, osg::Z_AXIS ); |
| | 600 | path->insert( delta_time * (float)i, osg::AnimationPath::ControlPoint(pos, rot) ); |
| | 601 | } |
| | 602 | |
| | 603 | osg::ref_ptr<osg::AnimationPathCallback> apcb = new osg::AnimationPathCallback; |
| | 604 | apcb->setAnimationPath( path.get() ); |
| | 605 | return apcb.release(); |
| | 606 | } |
| | 607 | |
| | 608 | osg::Group* createModel(osg::ArgumentParser& arguments) |
| | 609 | { |
| | 610 | unsigned int rcvShadowMask = 0x1; |
| | 611 | unsigned int castShadowMask = 0x2; |
| | 612 | |
| | 613 | // Set the ground (only receives shadow) |
| | 614 | osg::ref_ptr<osg::MatrixTransform> groundNode = new osg::MatrixTransform; |
| | 615 | groundNode->addChild( osgDB::readNodeFile("lz.osg") ); |
| | 616 | groundNode->setMatrix( osg::Matrix::translate(200.0f, 200.0f,-200.0f) ); |
| | 617 | //groundNode->setNodeMask( rcvShadowMask ); |
| | 618 | |
| | 619 | // Set the cessna (only casts shadow) |
| | 620 | osg::ref_ptr<osg::MatrixTransform> cessnaNode = new osg::MatrixTransform; |
| | 621 | cessnaNode->addChild( osgDB::readNodeFile("cessna.osg.0,0,90.rot") ); |
| | 622 | cessnaNode->addUpdateCallback( createAnimationPathCallback(50.0f, 6.0f) ); |
| | 623 | //cessnaNode->setNodeMask( castShadowMask ); |
| | 624 | |
| | 625 | osg::ref_ptr<osg::Group> shadowRoot = new osg::Group; |
| | 626 | shadowRoot->addChild( groundNode.get() ); |
| | 627 | for ( unsigned int i=0; i<10; ++i ) |
| | 628 | { |
| | 629 | for ( unsigned int j=0; j<10; ++j ) |
| | 630 | { |
| | 631 | osg::ref_ptr<osg::MatrixTransform> cessnaInstance = new osg::MatrixTransform; |
| | 632 | cessnaInstance->setMatrix( osg::Matrix::translate((float)i*50.0f-25.0f, (float)j*50.0f-25.0f, 0.0f) ); |
| | 633 | cessnaInstance->addChild( cessnaNode.get() ); |
| | 634 | shadowRoot->addChild( cessnaInstance.get() ); |
| | 635 | } |
| | 636 | } |
| | 637 | |
| | 638 | return shadowRoot.release(); |
| | 639 | } |
| | 640 | } |
| | 641 | |