コード例 #1
0
ファイル: FltExportVisitor.cpp プロジェクト: joevandyk/osg
void
FltExportVisitor::apply( osg::PositionAttitudeTransform& node )
{
    _firstNode = false;
    ScopedStatePushPop guard( this, node.getStateSet() );

    osg::ref_ptr<osg::RefMatrix> m = new osg::RefMatrix(
        osg::Matrix::translate( -node.getPivotPoint() ) *
        osg::Matrix::scale( node.getScale() ) *
        osg::Matrix::rotate( node.getAttitude() ) *
        osg::Matrix::translate( node.getPosition() ) );

    std::vector< osg::Referenced* > saveUserDataList;
    unsigned int idx;
    for( idx=0; idx<node.getNumChildren(); idx++ )
    {
        saveUserDataList.push_back( node.getChild( idx )->getUserData() );
        node.getChild( idx )->setUserData( m.get() );
    }

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

    // Restore saved UserData.
    unsigned int nd = node.getNumChildren();
    while (nd--)
        node.getChild( nd )->setUserData(
            saveUserDataList[ nd ] );

}
コード例 #2
0
ファイル: daeWTransforms.cpp プロジェクト: joevandyk/osg
//POSATT
void daeWriter::apply( osg::PositionAttitudeTransform &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,"positionAttitudeTransform").c_str());
    
    const osg::Vec3 &pos = node.getPosition();
    const osg::Quat &q = node.getAttitude();
    const osg::Vec3 &s = node.getScale();

    if ( s.x() != 1 || s.y() != 1 || s.z() != 1 )
    {
        //make a scale
        domScale *scale = daeSafeCast< domScale >( currentNode->createAndPlace( COLLADA_ELEMENT_SCALE ) );
        scale->getValue().append( s.x() );
        scale->getValue().append( s.y() );
        scale->getValue().append( s.z() );
    }

    double angle;
    osg::Vec3 axis;
    q.getRotate( angle, axis );
    if ( angle != 0 )
    {
        //make a rotate
        domRotate *rot = daeSafeCast< domRotate >( currentNode->createAndPlace( COLLADA_ELEMENT_ROTATE ) );
        rot->getValue().append( axis.x() );
        rot->getValue().append( axis.y() );
        rot->getValue().append( axis.z() );
        rot->getValue().append( angle );
    }

    if ( pos.x() != 0 || pos.y() != 0 || pos.z() != 0 )
    {
        //make a translate
        domTranslate *trans = daeSafeCast< domTranslate >( currentNode->createAndPlace( COLLADA_ELEMENT_TRANSLATE ) );
        trans->getValue().append( pos.x() );
        trans->getValue().append( pos.y() );
        trans->getValue().append( pos.z() );
    }

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

    traverse( node );
}
コード例 #3
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);

			}
コード例 #4
0
    void apply()
    {
        GeoPoint pos(
            srs,
            uiLon->getValue(), uiLat->getValue(), uiAlt->getValue(),
            ALTMODE_ABSOLUTE);

        geo->setPosition( pos );

        osg::Quat ori =
            osg::Quat(osg::DegreesToRadians(uiRoll->getValue()),    osg::Vec3(0,1,0)) *
            osg::Quat(osg::DegreesToRadians(uiPitch->getValue()),   osg::Vec3(1,0,0)) *
            osg::Quat(osg::DegreesToRadians(uiHeading->getValue()), osg::Vec3(0,0,-1));

        pat->setAttitude( ori );
    }
コード例 #5
0
ファイル: osgearth_transform.cpp プロジェクト: JD31/osgearth
    void apply()
    {
        AltitudeMode altMode = uiRelativeZ->getValue() ? ALTMODE_RELATIVE : ALTMODE_ABSOLUTE;

        GeoPoint pos(
            srs,
            uiLon->getValue(), uiLat->getValue(), uiAlt->getValue(),
            altMode);

        geo->setPosition( pos );

        osg::Quat ori =
            osg::Quat(osg::DegreesToRadians(uiRoll->getValue()),    osg::Vec3(0,1,0)) *
            osg::Quat(osg::DegreesToRadians(uiPitch->getValue()),   osg::Vec3(1,0,0)) *
            osg::Quat(osg::DegreesToRadians(uiHeading->getValue()), osg::Vec3(0,0,-1));

        pat->setAttitude( ori );
    }
コード例 #6
0
ファイル: daeWTransforms.cpp プロジェクト: IsemanTech/osg
//POSATT
void daeWriter::apply( osg::PositionAttitudeTransform &node )
{
#ifdef _DEBUG
    debugPrint( node );
#endif
    updateCurrentDaeNode();
    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) );
    std::string nodeName = getNodeName(node,"positionAttitudeTransform");
    currentNode->setId(nodeName.c_str());

    const osg::Vec3 &pos = node.getPosition();
    const osg::Quat &q = node.getAttitude();
    const osg::Vec3 &s = node.getScale();

    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;

            writeUpdateTransformElements(pos, q, s);
        }
    }

    // If not targeted by an animation simply add the elements that actually contribute to placement
    if (!handled)
    {
        if ( s.x() != 1 || s.y() != 1 || s.z() != 1 )
        {
            // Make a scale place element
            domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) );
            scale->setSid("scale");
            scale->getValue().append3( s.x(), s.y(), s.z() );
        }

        double angle;
        osg::Vec3 axis;
        q.getRotate( angle, axis );
        if ( angle != 0 )
        {
            // Make a rotate place element
            domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
            rot->setSid("rotate");
            rot->getValue().append4( axis.x(), axis.y(), axis.z(), osg::RadiansToDegrees(angle) );
        }

    if ( s.x() != 1 || s.y() != 1 || s.z() != 1 )
        {
            // Make a translate place element
            domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) );
            trans->setSid("translate");
            trans->getValue().append3( pos.x(), pos.y(), pos.z() );
        }
    }

    writeNodeExtra(node);

    lastDepth = _nodePath.size();

    traverse( node );
}
コード例 #7
0
ファイル: Uebung1.cpp プロジェクト: q02031990/CPlusPlus-
	osg::Node* createModel()
	{
		//Das Modell in der Übung besteht aus:
		// - Rotor
		//   - Kugel (Rotornabe)
		//   - 2 Quader (2x Rotorblätter)
		// - Turm
		//   - Zylinder (Turmdingsda)
		//   - 2 Quader für Gehäuse + Fundament

		//Gruppe (ist root Node)
		osg::Group* root = new osg::Group();

		//Die zwei Subnodes Rotor und Turm
		osg::Group* rotor = new osg::Group();
		osg::Group* tower = new osg::Group();

		root->addChild(rotor);
		root->addChild(tower);

		//Subnodes von Rotor...

		//Rotornabe
		osg::Geode* sphere = new osg::Geode();
		osg::ShapeDrawable* sphereShape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-0.25, 0, 0), 0.5));
		sphereShape->setColor(osg::Vec4(0.38, 0.75, 1.0, 1.0));
		sphere->addDrawable(sphereShape);

		//Rotorblätter
		osg::Geode* rotorBlade1 = new osg::Geode();
		osg::ShapeDrawable* rotorBladeShape1 = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, 1.25, 0), 0.25, 2.0, 0.5));
		rotorBladeShape1->setColor(osg::Vec4(0.60, 0.0, 0.0, 1.0));
		rotorBlade1->addDrawable(rotorBladeShape1);
		osg::Geode* rotorBlade2 = new osg::Geode();
		osg::ShapeDrawable* rotorBladeShape2 = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, -1.25, 0), 0.25, 2.0, 0.5));
		rotorBladeShape2->setColor(osg::Vec4(0.60, 0.0, 0.0, 1.0));
		rotorBlade2->addDrawable(rotorBladeShape2);


		//Transform Node
		rotorMovement = new osg::PositionAttitudeTransform();
		rotorMovement->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
		rotor->addChild(rotorMovement);

		rotorMovement->addChild(sphere);
		rotorMovement->addChild(rotorBlade1);
		rotorMovement->addChild(rotorBlade2);

		//Subnodes von Turm
		//Turmdingsda
		osg::Geode* towerThing = new osg::Geode();
		osg::ShapeDrawable* towerThingShape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(-0.75, 0, -1.5), 0.25, 3.0));
		towerThingShape->setColor(osg::Vec4(0.71, 0.39, 0.17, 1.0));
		towerThing->addDrawable(towerThingShape);

		tower->addChild(towerThing);

		//Gehäuse
		osg::Geode* housing = new osg::Geode();
		osg::ShapeDrawable* housingShape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(-0.75, 0, 0), 1, 1, 1));
		housingShape->setColor(osg::Vec4(0.0, 0.11, 0.60, 1.0));
		housing->addDrawable(housingShape);

		tower->addChild(housing);

		//Fundament
		osg::Geode* base = new osg::Geode();
		osg::ShapeDrawable* baseShape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(-0.75, 0, -3), 1, 1, 0.25));
		baseShape->setColor(osg::Vec4(0.0, 0.11, 0.60, 1.0));
		base->addDrawable(baseShape);

		tower->addChild(base);

		return root;
	}
コード例 #8
0
ファイル: Uebung1.cpp プロジェクト: q02031990/CPlusPlus-
	void Rotate()
	{
		rotorMovement->setAttitude(osg::Quat(osg::DegreesToRadians(rotation), osg::Vec3(1, 0, 0)));
		rotation -= 5;
	}