当前位置: 首页>>代码示例>>C++>>正文


C++ NodePtr::addAttachment方法代码示例

本文整理汇总了C++中NodePtr::addAttachment方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::addAttachment方法的具体用法?C++ NodePtr::addAttachment怎么用?C++ NodePtr::addAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodePtr的用法示例。


在下文中一共展示了NodePtr::addAttachment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildBox

//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
void buildBox(void)
{
    Vec3f Lengths(frand()*2.0+0.5, frand()*2.0+0.5, frand()*2.0+0.5);
    Matrix m;
    //create OpenSG mesh
    GeometryPtr box;
    NodePtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
    box = GeometryPtr::dcast(boxNode->getCore());
    SimpleMaterialPtr box_mat = SimpleMaterial::create();
    beginEditCP(box_mat);
        box_mat->setAmbient(Color3f(0.0,0.0,0.0));
        box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0));
    endEditCP(box_mat);
    beginEditCP(box, Geometry::MaterialFieldMask);
        box->setMaterial(box_mat);
    endEditCP(box, Geometry::MaterialFieldMask);
    TransformPtr boxTrans;
    NodePtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
    m.setIdentity();
    Real32 randX = frand()*10.0-5.0;
    Real32 randY = frand()*10.0-5.0;
    m.setTranslate(randX, randY, 10.0);
    beginEditCP(boxTrans, Transform::MatrixFieldMask);
        boxTrans->setMatrix(m);
    endEditCP(boxTrans, Transform::MatrixFieldMask);

    //create ODE data
    PhysicsBodyPtr boxBody = PhysicsBody::create(physicsWorld);
    beginEditCP(boxBody, PhysicsBody::PositionFieldMask);
        boxBody->setPosition(Vec3f(randX, randY, 10.0));
    endEditCP(boxBody, PhysicsBody::PositionFieldMask);
    boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());

    PhysicsBoxGeomPtr boxGeom = PhysicsBoxGeom::create();
    beginEditCP(boxGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask  | PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask);
        boxGeom->setBody(boxBody);
        boxGeom->setSpace(physicsSpace);
        boxGeom->setLengths(Lengths);
        boxGeom->setCategoryBits(BoxCategory);
    endEditCP(boxGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask);

    //add attachments
    beginEditCP(boxNode, Node::AttachmentsFieldMask);
        boxNode->addAttachment(boxGeom);
    endEditCP(boxNode, Node::AttachmentsFieldMask);
    beginEditCP(boxTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);
        boxTransNode->addAttachment(boxBody);
        boxTransNode->addChild(boxNode);
    endEditCP(boxTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);

    //add to SceneGraph
    beginEditCP(spaceGroupNode, Node::ChildrenFieldMask);
        spaceGroupNode->addChild(boxTransNode);
    endEditCP(spaceGroupNode, Node::ChildrenFieldMask);
}
开发者ID:Himbeertoni,项目名称:OpenSGToolbox,代码行数:58,代码来源:21Collisions.cpp

示例2: buildSphere

//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
void buildSphere(void)
{
    Real32 Radius(frand()*1.5+0.2);
    Matrix m;
    //create OpenSG mesh
    GeometryPtr sphere;
    NodePtr sphereNode = makeSphere(2, Radius);
    sphere = GeometryPtr::dcast(sphereNode->getCore());
    SimpleMaterialPtr sphere_mat = SimpleMaterial::create();
    beginEditCP(sphere_mat);
    sphere_mat->setAmbient(Color3f(0.0,0.0,0.0));
    sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0));
    endEditCP(sphere_mat);
    beginEditCP(sphere, Geometry::MaterialFieldMask);
    sphere->setMaterial(sphere_mat);
    endEditCP(sphere);
    TransformPtr sphereTrans;
    NodePtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans);
    m.setIdentity();
    Real32 randX = frand()*10.0-5.0;
    Real32 randY = frand()*10.0-5.0;
    m.setTranslate(randX, randY, 10.0);
    beginEditCP(sphereTrans, Transform::MatrixFieldMask);
    sphereTrans->setMatrix(m);
    endEditCP(sphereTrans);
    //create ODE data
    PhysicsBodyPtr sphereBody = PhysicsBody::create(physicsWorld);
    beginEditCP(sphereBody, PhysicsBody::PositionFieldMask | PhysicsBody::AngularDampingFieldMask);
        sphereBody->setPosition(Vec3f(randX, randY, 10.0));
        sphereBody->setAngularDamping(0.0001);
    endEditCP(sphereBody, PhysicsBody::PositionFieldMask | PhysicsBody::AngularDampingFieldMask);
    sphereBody->setSphereMass(0.4,Radius);

    PhysicsSphereGeomPtr sphereGeom = PhysicsSphereGeom::create();
    beginEditCP(sphereGeom, PhysicsSphereGeom::BodyFieldMask | PhysicsSphereGeom::SpaceFieldMask | PhysicsSphereGeom::RadiusFieldMask | PhysicsSphereGeom::CategoryBitsFieldMask);
        sphereGeom->setBody(sphereBody);
        sphereGeom->setSpace(physicsSpace);
        sphereGeom->setRadius(Radius);
        sphereGeom->setCategoryBits(SphereCategory);
    endEditCP(sphereGeom, PhysicsSphereGeom::BodyFieldMask | PhysicsSphereGeom::SpaceFieldMask | PhysicsSphereGeom::RadiusFieldMask | PhysicsSphereGeom::CategoryBitsFieldMask);
    
    //add attachments
    beginEditCP(sphereNode, Node::AttachmentsFieldMask);
    sphereNode->addAttachment(sphereGeom);
    endEditCP(sphereNode);
    beginEditCP(sphereTransNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask);
    sphereTransNode->addAttachment(sphereBody);
    sphereTransNode->addChild(sphereNode);
    endEditCP(sphereTransNode);
    //add to SceneGraph
    beginEditCP(spaceGroupNode, Node::ChildrenFieldMask);
    spaceGroupNode->addChild(sphereTransNode);
    endEditCP(spaceGroupNode);
}
开发者ID:Himbeertoni,项目名称:OpenSGToolbox,代码行数:57,代码来源:21Collisions.cpp

示例3: buildTriMesh

//////////////////////////////////////////////////////////////////////////
//! trimesh defined by filenode will be loaded
//////////////////////////////////////////////////////////////////////////
void buildTriMesh(void)
{
    //NodePtr tri = makeTorus(0.5, 1.0, 24, 12);
    //NodePtr tri = makeBox(10.0, 10.0, 10.0, 1, 1, 1);
    NodePtr tri = Node::Ptr::dcast(TriGeometryBase->shallowCopy());
    if(tri!=NullFC)
    {
        GeometryPtr triGeo = GeometryPtr::dcast(tri->getCore()); 
        Matrix m;
        SimpleMaterialPtr tri_mat = SimpleMaterial::create();
        beginEditCP(tri_mat);
        tri_mat->setAmbient(Color3f(0.1,0.1,0.2));
        tri_mat->setDiffuse(Color3f(1.0,0.1,0.7));
        endEditCP(tri_mat);
        triGeo->setMaterial(tri_mat);
        TransformPtr triTrans;
        NodePtr triTransNode = makeCoredNode<Transform>(&triTrans);
        m.setIdentity();
        Real32 randX = frand()*10.0-5.0;
        Real32 randY = frand()*10.0-5.0;
        m.setTranslate(randX, randY, 18.0);
        triTrans->setMatrix(m);

        //create ODE data
        Vec3f GeometryBounds(calcMinGeometryBounds(triGeo));
        PhysicsBodyPtr triBody = PhysicsBody::create(physicsWorld);
        beginEditCP(triBody, PhysicsBody::PositionFieldMask | PhysicsBody::LinearDampingFieldMask | PhysicsBody::AngularDampingFieldMask);
            triBody->setPosition(Vec3f(randX, randY, 18.0));
            triBody->setLinearDamping(0.0001);
            triBody->setAngularDamping(0.0001);
        endEditCP(triBody, PhysicsBody::PositionFieldMask | PhysicsBody::LinearDampingFieldMask | PhysicsBody::AngularDampingFieldMask);
            triBody->setBoxMass(1.0,GeometryBounds.x(), GeometryBounds.y(), GeometryBounds.z());
        PhysicsGeomPtr triGeom;
        if(true)
        {
            triGeom = PhysicsTriMeshGeom::create();
            beginEditCP(triGeom, PhysicsTriMeshGeom::BodyFieldMask | 
                            PhysicsTriMeshGeom::SpaceFieldMask | 
                            PhysicsTriMeshGeom::GeometryNodeFieldMask);
                triGeom->setBody(triBody);
                //add geom to space for collision
                triGeom->setSpace(physicsSpace);
                //set the geometryNode to fill the ode-triMesh
                PhysicsTriMeshGeom::Ptr::dcast(triGeom)->setGeometryNode(tri);
            endEditCP(triGeom, PhysicsTriMeshGeom::BodyFieldMask | 
                            PhysicsTriMeshGeom::SpaceFieldMask | 
                            PhysicsTriMeshGeom::GeometryNodeFieldMask);
        }
        else
        {

            triGeom = PhysicsBoxGeom::create();
            beginEditCP(triGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::LengthsFieldMask);
                triGeom->setBody(triBody);
                triGeom->setSpace(physicsSpace);
                PhysicsBoxGeom::Ptr::dcast(triGeom)->setLengths(GeometryBounds);

            endEditCP(triGeom, PhysicsBoxGeom::BodyFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::LengthsFieldMask);
        }
        beginEditCP(triGeom, PhysicsGeom::CategoryBitsFieldMask);
            triGeom->setCategoryBits(TriCategory);
        endEditCP(triGeom, PhysicsGeom::CategoryBitsFieldMask);
        
        //add attachments
        tri->addAttachment(triGeom);
        triTransNode->addAttachment(triBody);
        //add to SceneGraph
        triTransNode->addChild(tri);
        spaceGroupNode->addChild(triTransNode);
    }
    else
    {
        SLOG << "Could not read MeshData!" << endLog;
    }
}
开发者ID:Himbeertoni,项目名称:OpenSGToolbox,代码行数:78,代码来源:21Collisions.cpp

示例4: main


//.........这里部分代码省略.........
        SlickBoxParams->setMu2(0.0);
        SlickBoxParams->setBounce(0.0);
        SlickBoxParams->setBounceSpeedThreshold(0.0);
        SlickBoxParams->setSoftCFM(0.0);
        SlickBoxParams->setSoftERP(0.2);
        SlickBoxParams->setMotion1(0.0);
        SlickBoxParams->setMotion2(0.0);
        SlickBoxParams->setMotionN(0.0);
        SlickBoxParams->setSlip1(0.0);
        SlickBoxParams->setSlip2(0.0);
    endEditCP(SlickBoxParams);
    physicsSpace->addCollisionContactCategory(BoxCategory, TerrainCategory, SlickBoxParams);
    physicsSpace->addCollisionContactCategory(BoxCategory, BoxCategory, SlickBoxParams);
    //physicsSpace->addCollisionContactCategory(BoxCategory, SphereCategory, SlickBoxParams);
    physicsSpace->addCollisionContactCategory(BoxCategory, TriCategory, SlickBoxParams);

    
    TutorialCollisionListener BoxColListener(Path("./Data/click.wav"));
    physicsSpace->addCollisionListener(&BoxColListener,BoxCategory, 2.0);

    TutorialCollisionListener SphereColListener(Path("./Data/pop.wav"));
    physicsSpace->addCollisionListener(&SphereColListener,SphereCategory, 2.0);

    physHandler = PhysicsHandler::create();
    beginEditCP(physHandler, PhysicsHandler::WorldFieldMask | PhysicsHandler::SpacesFieldMask | PhysicsHandler::StepSizeFieldMask | PhysicsHandler::UpdateNodeFieldMask);
        physHandler->setWorld(physicsWorld);
        physHandler->getSpaces().push_back(physicsSpace);
        physHandler->setStepSize(0.001);
        physHandler->setUpdateNode(rootNode);
    endEditCP(physHandler, PhysicsHandler::WorldFieldMask | PhysicsHandler::SpacesFieldMask | PhysicsHandler::StepSizeFieldMask | PhysicsHandler::UpdateNodeFieldMask);
    physHandler->attachUpdateProducer(TutorialWindowEventProducer);

    beginEditCP(rootNode, Node::AttachmentsFieldMask);
        rootNode->addAttachment(physHandler);    
        rootNode->addAttachment(physicsWorld);
        rootNode->addAttachment(physicsSpace);
    endEditCP(rootNode, Node::AttachmentsFieldMask);


	/************************************************************************/
	/* create spaces, geoms and bodys                                                                     */
	/************************************************************************/
    //create a group for our space
    GroupPtr spaceGroup;
	spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
    //create the ground plane
    GeometryPtr plane;
	NodePtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
    plane = GeometryPtr::dcast(planeNode->getCore());
    //and its Material
	SimpleMaterialPtr plane_mat = SimpleMaterial::create();
	beginEditCP(plane_mat);
		plane_mat->setAmbient(Color3f(0.7,0.7,0.7));
		plane_mat->setDiffuse(Color3f(0.9,0.6,1.0));
	endEditCP(plane_mat);
    beginEditCP(plane, Geometry::MaterialFieldMask);
	    plane->setMaterial(plane_mat);
    endEditCP(plane);


    //create Physical Attachments
	PhysicsBoxGeomPtr planeGeom = PhysicsBoxGeom::create();
    beginEditCP(planeGeom, PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask);
        planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0));
        //add geoms to space for collision
        planeGeom->setSpace(physicsSpace);
开发者ID:Himbeertoni,项目名称:OpenSGToolbox,代码行数:67,代码来源:21Collisions.cpp

示例5: main

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin = GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // load the scene

    NodePtr scene;
    
    if(argc < 2)
    {
        FWARNING(("No file given!\n"));
 
        scene = makeTorus(.5, 2, 16, 16);
    }
    else
    {
        /*
            All scene file loading is handled via the SceneFileHandler.
        */
        scene = SceneFileHandler::the().read(argv[1]);
    }

    /* 
       An Attachment is a special field container that can be attached to many
       of the internal classes like Nodes and NodeCores. There can be multiple
       Attachments attached to an object.
       
       Attachments can be attached to all FieldContainers that are derived from
       AttachmentContainer. This includes most higher-level classes in the
       system, like Nodes, NodeCores, Windows, Viewports etc.

       The only predefined kind of Attachment is the Name, which can
       keep the name of an object. Some of loaders (e.g. the WRL loader)
       create these kinds of Attachments for named nodes.
    */
    
    /*
        An Attachment is a FieldContainer and as such needs to be created using
        ::create().
    */
    NamePtr name = Name::create();
    
    /* 
        The NameAttachment only has a single field, there's no need to use the
        mask here.
    */
    beginEditCP(name);
    {
        name->getField().setValue("Scene");
    }
    endEditCP  (name);
    
    /*
        Attach the name to the scene node.
     */
    beginEditCP(scene, Node::AttachmentsFieldMask);
    {
        scene->addAttachment(name);
    }
    endEditCP  (scene, Node::AttachmentsFieldMask);
    
    /*
        Check if the scene has a Name attachment
        
        Attachments are categorized by the GroupID of their class. Every
        AttachmentContainer generally keeps only one attachment of a specific
        kind. 
     */
    AttachmentPtr a;
    
    a = scene->findAttachment(Name::getClassType());
    
    if(a!=NullFC)
    {
        NamePtr n = NamePtr::dcast(a);
        
        SLOG << "Node name: " << n->getField().getValue() << endl;
    }
    else
    {
        SLOG << "Node has no name!" << endl;
    }
    
    // use the finder helper to find a named object
    
    finder f;
    NodePtr found;
    
    found = f.find(scene, "Scene");  
    SLOG << "Found object " << found << " named Scene." << endl;
//.........这里部分代码省略.........
开发者ID:mlimper,项目名称:OpenSG1x,代码行数:101,代码来源:10attachment.cpp


注:本文中的NodePtr::addAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。