コード例 #1
0
ファイル: TXPArchive.cpp プロジェクト: joevandyk/osg
    virtual void apply(osg::MatrixTransform& xform)
    {
        const trpgHeader* header = _archive->GetHeader();
        trpgHeader::trpgTileType tileType;
        header->GetTileOriginType(tileType);
        const osg::Referenced* ref = xform.getUserData();
        const TileIdentifier* tileID = dynamic_cast<const txp::TileIdentifier*>(ref);

        if(!tileID) return; // bail early - this isn't a loaded model

        if(tileType == trpgHeader::TileLocal && tileID->lod == 9999)
        {
        trpg2dPoint tileExtents;
        header->GetTileSize(0, tileExtents);
        osg::BoundingBox bbox;
        _archive->getExtents(bbox);
        osg::Vec3 offset(xform.getMatrix().getTrans());
        offset[0] -= bbox._min[0];
        offset[1] -= bbox._min[1];

        trpg2dPoint offsetXY, tileID(_tileInfo.x,_tileInfo.y);
        int divider = (0x01 << _tileInfo.lod);
        // calculate which tile model is located in
        tileExtents.x /= divider;
        tileExtents.y /= divider;
        offset[0] -= tileID.x*tileExtents.x;
        offset[1] -= tileID.y*tileExtents.y;

        osg::Matrix mat(xform.getMatrix());
        mat.setTrans(offset);
        xform.setMatrix(mat);
        }
    }
コード例 #2
0
        void                                apply( osg::MatrixTransform& mt )
                                            {
                                                if ( !mt.getUpdateCallback() )
                                                    mt.traverse( *this );

                                                osg::AnimationPathCallback* p_ncb = dynamic_cast< osg::AnimationPathCallback* >( mt.getUpdateCallback() );
                                                if ( !p_ncb )
                                                    mt.traverse( *this );

                                                _p_animPath = p_ncb->getAnimationPath();
                                                if ( !_p_animPath )
                                                    mt.traverse( *this );
                                            }
コード例 #3
0
ファイル: daeWTransforms.cpp プロジェクト: IsemanTech/osg
//MATRIX
void daeWriter::apply( osg::MatrixTransform &node )
{
#ifdef _DEBUG
    debugPrint( node );
#endif
    updateCurrentDaeNode();
    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) );
    std::string nodeName = getNodeName(node,"matrixTransform");
    currentNode->setId(nodeName.c_str());

    osg::Callback* ncb = node.getUpdateCallback();
    bool handled = false;
    if (ncb)
    {
        osgAnimation::UpdateMatrixTransform* ut = dynamic_cast<osgAnimation::UpdateMatrixTransform*>(ncb);
        // If targeted by an animation we split up the matrix into multiple place element so they can be targeted individually
        if (ut)
        {
            handled = true;

            const osg::Matrix &mat = node.getMatrix();

            // Note: though this is a generic matrix, based on the fact that it will be animated by and UpdateMatrixTransform,
            // we assume the initial matrix can be decomposed into translation, rotation and scale elements
            writeUpdateTransformElements(mat.getTrans(), mat.getRotate(), mat.getScale());
        }
    }

    // If not targeted by an animation simply write a single matrix place element
    if (!handled)
    {
        domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) );
        nodeName += "_matrix";
        mat->setSid(nodeName.c_str());

        const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr();
        for ( int i = 0; i < 4; i++ )
        {
            for ( int j = 0; j < 4; j++ )
            {
                mat->getValue().append( mat_vals[i + j*4] );
            }
        }
    }

    lastDepth = _nodePath.size();

    writeNodeExtra(node);

    traverse( node );
}
コード例 #4
0
ファイル: WriterNodeVisitor.cpp プロジェクト: artoolkit/osg
void WriterNodeVisitor::apply(osg::MatrixTransform &node)
{
    pushStateSet(node.getStateSet());
    Lib3dsMeshInstanceNode * parent = _cur3dsNode;
#if DISABLE_3DS_ANIMATION
    osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) );
#else
    osg::Matrix mat( node.getMatrix() );
#endif
    apply3DSMatrixNode(node, &mat, "mtx");
    if (succeeded())
        traverse(node);
    _cur3dsNode = parent;
    popStateSet(node.getStateSet());
}
コード例 #5
0
void
CountsVisitor::apply(osg::MatrixTransform& node)
{
    pushStateSet(node.getStateSet());

    _matrixTransforms++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uMatrixTransforms.insert(rp);
    _totalChildren += node.getNumChildren();
    apply(node.getStateSet());

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
コード例 #6
0
ファイル: Normals.cpp プロジェクト: amhagan/osg
void Normals::MakeNormalsVisitor::apply(osg::MatrixTransform& tx)
{
    _matStack.push( _mat );
    _mat = _mat * tx.getMatrix();

    traverse( tx );

    _mat = _matStack.top();
    _matStack.pop();
}
コード例 #7
0
void
FltExportVisitor::apply( osg::MatrixTransform& node )
{
    // Importer reads a Matrix record and inserts a MatrixTransform above
    //   the current node. We need to do the opposite: Write a Matrix record
    //   as an ancillary record for each child. We do that by storing the
    //   MatrixTransform in each child's UserData. Each child then checks
    //   UserData and writes a Matrix record if UserData is a MatrixTransform.

    _firstNode = false;
    ScopedStatePushPop guard( this, node.getStateSet() );

    osg::ref_ptr< osg::RefMatrix > m = new osg::RefMatrix;
    m->set( node.getMatrix() );
    if (node.getUserData())
    {
        const osg::RefMatrix* rm = dynamic_cast<const osg::RefMatrix*>( node.getUserData() );
        if (rm)
            (*m) *= *rm;
    }

    typedef std::vector< osg::ref_ptr< osg::Referenced > > UserDataList;
    
    UserDataList saveUserDataList( node.getNumChildren() );

    unsigned int idx;
    for( idx=0; idx<node.getNumChildren(); ++idx )
    {
        saveUserDataList[ idx ] = node.getChild( idx )->getUserData();
        node.getChild( idx )->setUserData( m.get() );
    }

    traverse( (osg::Node&)node );

    // Restore saved UserData.
    for( idx=0; idx< node.getNumChildren(); ++idx )
    {
      node.getChild( idx )->setUserData( saveUserDataList[ idx ].get() );
    }
}
コード例 #8
0
			virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) 
			{

				// Matrix that rotates from the marker grid to paddle coordinate system
				osg::Matrix rotationMatrix = osg::Matrix(arTransformB->getMatrix().getRotate());

				osg::Vec3 globalUp = osg::Z_AXIS;							// z-axis on the marker grid
				osg::Vec3 localUp = globalUp * rotationMatrix;				// z-axis on the paddle
				osg::Vec3 projection = globalUp ^ (localUp ^ globalUp);		// projection of paddle up vector onto reference plane
				float magnitude = projection.length();						// length of projection

				std::cout << projection << ", " << magnitude << std::endl;

				osg::Vec3 paddlePos = arTransformB->getMatrix().getTrans();


				osg::Vec3 offsetA = paddlePos - hotSpotAPos;
				osg::Vec3 offsetB = paddlePos - hotSpotBPos;

				float scale = 1 + projection.x();

				if (offsetA.length() < 80) {
					hotSpotA->setColor(osg::Vec4(0, 0, 1, 1));
					contentA->setScale(osg::Vec3(scale, scale, scale));
				} else {
					hotSpotA->setColor(osg::Vec4(0.4, 0.4, 0.4, 1));
				}


				if (offsetB.length() < 80) {
					hotSpotB->setColor(osg::Vec4(0, 0, 1, 1));
					contentB->setScale(osg::Vec3(scale, scale, scale));
				} else {
					hotSpotB->setColor(osg::Vec4(0.4, 0.4, 0.4, 1));
				}

				traverse(node,nv);

			}
コード例 #9
0
ファイル: daeWTransforms.cpp プロジェクト: joevandyk/osg
//MATRIX
void daeWriter::apply( osg::MatrixTransform &node )
{
#ifdef _DEBUG
    debugPrint( node );
#endif

    while ( lastDepth >= _nodePath.size() )
    {
        //We are not a child of previous node
        currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
        lastDepth--;
    }

    currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
    currentNode->setId(getNodeName(node,"matrixTransform").c_str());
    
    domMatrix *mat = daeSafeCast< domMatrix >(currentNode->createAndPlace( COLLADA_ELEMENT_MATRIX ) );
    const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr();
    //for ( int i = 0; i < 16; i++ )
    //{
    //  mat->getValue().append( mat_vals[i] );
    //}
    mat->getValue().append( mat_vals[0] );
    mat->getValue().append( mat_vals[4] );
    mat->getValue().append( mat_vals[8] );
    mat->getValue().append( mat_vals[12] );
    mat->getValue().append( mat_vals[1] );
    mat->getValue().append( mat_vals[5] );
    mat->getValue().append( mat_vals[9] );
    mat->getValue().append( mat_vals[13] );
    mat->getValue().append( mat_vals[2] );
    mat->getValue().append( mat_vals[6] );
    mat->getValue().append( mat_vals[10] );
    mat->getValue().append( mat_vals[14] );
    mat->getValue().append( mat_vals[3] );
    mat->getValue().append( mat_vals[7] );
    mat->getValue().append( mat_vals[11] );
    mat->getValue().append( mat_vals[15] );

    lastVisited = MATRIX;
    lastDepth = _nodePath.size();

    traverse( node );
}
コード例 #10
0
void AnimationCleanerVisitor::apply(osg::MatrixTransform& transform) {
    HasGeometryVisitor hasData;
    transform.traverse(hasData);

    if(!hasData.geometry) {
        // if animation transforms have no child geometry they are cleanable
        osgAnimation::Skeleton* skeleton = dynamic_cast<osgAnimation::Skeleton*>(&transform);
        osgAnimation::Bone* bone = dynamic_cast<osgAnimation::Bone*>(&transform);
        if(skeleton) {
            _transforms.push_back(osg::ref_ptr<osgAnimation::Skeleton>(skeleton));
        }
        if(bone) {
            _transforms.push_back(osg::ref_ptr<osgAnimation::Bone>(bone));
        }
    }

    osgAnimation::UpdateMatrixTransform* update = getCallbackType<osgAnimation::UpdateMatrixTransform>(transform.getUpdateCallback());
    if(update) {
        _updates[update] = osg::ref_ptr<osg::Node>(&transform);
    }

    traverse(transform);
}
コード例 #11
0
 void                            apply( osg::MatrixTransform& node )
                                 {
                                     ++_numVisited;
                                     compileResource( node.getStateSet() );
                                     traverse( node );
                                 }