コード例 #1
0
void RigidBodyAnimation::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::MatrixTransform* matTrans = static_cast< osg::MatrixTransform* >( node);
/*   if( node == NULL )
    {
        return;
    }

    osgbCollision::RefBulletObject< btRigidBody >* rb = dynamic_cast<
        osgbCollision::RefBulletObject< btRigidBody >* >( matTrans->getUserData
    if( rb == NULL )
    {
        osg::notify( osg::WARN ) << "RigidBodyAnimation requires RefBulletObjec
        return;
    }*/
osgbDynamics::RigidBody* rig=dynamic_cast<osgbDynamics::RigidBody*> (matTrans->getUpdateCallback());
    btRigidBody* body = rig->getRigidBody();
    if( body->getInvMass() != 0.0 ||!rig->getParentWorld())
    {
        traverse( node, nv );;
   }

    osg::Matrix mat = computeLocalToWorld( node->getParentalNodePaths()[0] );
    //osg::Matrix mat = matTrans->getMatrix();
    body->getMotionState()->setWorldTransform(
        osgbCollision::asBtTransform( mat ) );
    traverse( node, nv );

}
コード例 #2
0
void PhysicsVisitor::apply( osg::Geode& node )
{
    // retrieve the node mask which is used for physics material and later for other properies
    // only the first byte is relevant for pyhsics material description
    _attribute = node.getNodeMask() & 0xFF;

    // this means no need for building static collision geom
    //  this is not the same as MAT_NOCOL, as MAT_NOCOL collisions are detected
    if ( _attribute == Physics::NO_BUILD )
        return;

    // get the accumulated world matrix for this node
    osg::Matrixf  mat = computeLocalToWorld( getNodePath() );
    unsigned int numDrawables = node.getNumDrawables();
    for ( unsigned int cnt = 0; cnt < numDrawables; ++cnt )
    {
        osg::Drawable* p_drawable = node.getDrawable( cnt );
        osg::Geometry* p_geom     = p_drawable->asGeometry();
        // evaluate the geom and generate an appropriate collision geometry
        if ( p_geom )
        {
            osg::Array*      p_verts   = p_geom->getVertexArray();
            osg::IndexArray* p_indices = p_geom->getVertexIndices();
            unsigned int     numPrims  = p_geom->getNumPrimitiveSets();
            {
                for ( unsigned int primcnt = 0; primcnt < numPrims; ++primcnt )
                {
                    osg::PrimitiveSet* p_set = p_geom->getPrimitiveSet( primcnt );
                    switch( p_set->getMode() )
                    {
                        case osg::PrimitiveSet::POINTS:
                        case osg::PrimitiveSet::LINES:
                        case osg::PrimitiveSet::LINE_STRIP:
                        case osg::PrimitiveSet::LINE_LOOP:
                            return;

                        case osg::PrimitiveSet::TRIANGLES:
                            buildTrianlges( p_set, p_verts, mat, p_indices );
                            break;

                        case osg::PrimitiveSet::TRIANGLE_STRIP:
                            buildTrianlgeStrip( p_set, p_verts, mat, p_indices );
                            break;

                        case osg::PrimitiveSet::TRIANGLE_FAN:
                        case osg::PrimitiveSet::QUADS:
                        case osg::PrimitiveSet::QUAD_STRIP:
                        case osg::PrimitiveSet::POLYGON:

                        default:
                            log_error << "Physics Serializer: unsupported primitive set for physics geometry! currently only TRIANGLES and TRIANGLE_STRIP types are supported." << std::endl;
                    }
                }
            }
        }
    }
}
コード例 #3
0
bool ossimPlanetSceneView::pickObjects(osgUtil::IntersectVisitor::HitList& hits,
                                       osg::Node* startNode,
                                       double vx, double vy,
                                       double /*startPointShift*/)
{
   osg::Node* rootNode = 0;
   if(startNode)
   {
      rootNode = startNode;
   }
   else
   {
      rootNode = getSceneData();
   }
   osg::Matrixd proj   = getProjectionMatrix();
   osg::Matrixd view   = getViewMatrix();
   const osg::Viewport* viewport = getViewport();
   osg::Matrixd projToWindow = viewport->computeWindowMatrix();
   osg::Vec3d projPt(vx, vy, 1.0);
   osg::Vec3d windowPt = projPt*projToWindow;
   
   osg::NodePathList parentNodePaths = rootNode->getParentalNodePaths(rootNode);
   for(unsigned int i=0;i<parentNodePaths.size();++i)
   {
      osg::NodePath& nodePath = parentNodePaths[i];
      
      // remove the intersection node from the nodePath as it'll be accounted for
      // in the PickVisitor traversal, so we don't double account for its transform.
      if (!nodePath.empty()) nodePath.pop_back();  
      
      osg::Matrixd modelview(view);
      // modify the view matrix so that it accounts for this nodePath's accumulated transform
      if (!nodePath.empty()) modelview.preMult(computeLocalToWorld(nodePath));
      
      osgUtil::PickVisitor pick(viewport, proj, modelview, windowPt[0], windowPt[1]);
      pick.setTraversalMask(0xffffffff);
      rootNode->accept(pick);
      
      // copy all the hits across to the external hits list
      for(osgUtil::PickVisitor::LineSegmentHitListMap::iterator itr = pick.getSegHitList().begin();
          itr != pick.getSegHitList().end();
          ++itr)
      {
         hits.insert(hits.end(), itr->second.begin(), itr->second.end());
      }
      
   }

   return !hits.empty();
}
コード例 #4
0
osg::Matrix SparkUpdatingHandler::computeTransformMatrix( SparkDrawable* spark, osg::Transform* trackee )
{
    osg::Node* sparkGeode = (spark->getNumParents()>0 ? spark->getParent(0) : NULL);
    if ( !sparkGeode )
        return osg::Matrix::identity();
    else if ( !sparkGeode->getNumParents() || !trackee->getNumParents() )
        return osg::Matrix::identity();
    else if ( sparkGeode->getParent(0)==trackee->getParent(0) )
        return osg::Matrix::identity();
    
    // Collect the parent paths, ignoring the last one (the spark/trackee itself)
    osg::NodePath& sparkPath = sparkGeode->getParentalNodePaths().size()>0?sparkGeode->getParentalNodePaths()[0]:osg::NodePath(); if(sparkPath.size()>0) sparkPath.pop_back();
    
    osg::NodePathList& lst = trackee->getParentalNodePaths();
    
    if(lst.size()==0)
        return osg::Matrix::identity();
    
    osg::NodePath& trackeePath = lst[0];
    trackeePath.pop_back();

    return computeLocalToWorld(trackeePath) * computeWorldToLocal(sparkPath);
}