PhysicsBodyDrawWrapper(const NodeUnrecPtr node, const PhysicsBodyUnrecPtr body, MaterialUnrecPtr mat) : 
     _node(node),_body(body), _mat(mat)
 {
     if(_mat == NULL)
     {
         _mat = getDefaultUnlitMaterial();
     }
 }
Beispiel #2
0
    static void drop(DrawActionBase *action, const BoxVolume     &volume, Color3f col)
#endif
    {
        VolumeDrawWrapper * vdw = new VolumeDrawWrapper(volume, col);

        Material::DrawFunctor func;
        func = osgTypedMethodFunctor1ObjPtr(vdw, &VolumeDrawWrapper::draw);
    
        RenderAction *ra = dynamic_cast<RenderAction*>(action);
        
        ra->dropFunctor(func, getCPtr(getDefaultUnlitMaterial()));
    }
Action::ResultE
SkeletonSkinningAlgorithm::renderEnter(Action *action)
{
    Action::ResultE  res  = Action::Continue;
    RenderAction    *ract =
        boost::polymorphic_downcast<RenderAction *>(action);

    SkinnedGeometry *skinGeo = getSkin();
    Skeleton        *skel    = skinGeo->getSkeleton();

    skel->renderEnter(action, skinGeo);

    const Skeleton::MFJointsType        *joints       = skel->getMFJoints();
    const Skeleton::MFParentJointsType  *parentJoints =
        skel->getMFParentJoints();
    const Skeleton::MFJointMatricesType *jointMats    =
        skel->getMFJointMatrices();

    UInt32 numJoints = joints->size32();

#ifndef OSG_SKELETON_SKINNING_ALGO_DRAW_AXIS
    _mfDrawPositions.resize(numJoints);
    _mfDrawIndex    .clear (         );

    for(UInt32 i = 0; i < numJoints; ++i)
    {
        (*jointMats)[i].mult(Pnt3f(0.f, 0.f, 0.f),
                             _mfDrawPositions[i]  );

        if((*parentJoints)[i] != NULL)
        {
            _mfDrawIndex.push_back(i                               );
            _mfDrawIndex.push_back((*parentJoints)[i]->getJointId());
        }
    }

#else
    Real32 axisLen = 1.f;

    _mfDrawPositions.resize(4 * numJoints);
    _mfDrawIndex    .clear (             );

    for(UInt32 i = 0; i < numJoints; ++i)
    {
        (*jointMats)[i].mult(Pnt3f(0.f, 0.f, 0.f),
                             _mfDrawPositions[4 * i + 0]);

        if((*parentJoints)[i] != NULL)
        {
            _mfDrawIndex.push_back(4 * i                                + 0);
            _mfDrawIndex.push_back(4 * (*parentJoints)[i]->getJointId() + 0);

            Vec3f vec =
                _mfDrawPositions[4 * i                                + 0] -
                _mfDrawPositions[4 * (*parentJoints)[i]->getJointId() + 0];

            axisLen = 0.2f * vec.length();
            axisLen = 1.f;
        }
        else
        {
            axisLen = 1.f;
        }

        (*jointMats)[i].mult(
            Pnt3f(axisLen, 0.f,     0.f    ), _mfDrawPositions[4 * i + 1]);
        (*jointMats)[i].mult(
            Pnt3f(0.f,     axisLen, 0.f    ), _mfDrawPositions[4 * i + 2]);
        (*jointMats)[i].mult(
            Pnt3f(0.f,     0.f,     axisLen), _mfDrawPositions[4 * i + 3]);

        _mfDrawIndex.push_back(4 * i + 0);
        _mfDrawIndex.push_back(4 * i + 1);
        _mfDrawIndex.push_back(4 * i + 0);
        _mfDrawIndex.push_back(4 * i + 2);
        _mfDrawIndex.push_back(4 * i + 0);
        _mfDrawIndex.push_back(4 * i + 3);
    }
#endif // #ifndef OSG_SKELETON_SKINNING_ALGO_DRAW_AXIS

    DrawEnv::DrawFunctor   drawFuncSkinAlgo =
        boost::bind(&SkeletonSkinningAlgorithm::drawFunc, this, _1);
    PrimeMaterial         *skelMat          = getDefaultUnlitMaterial();
    State                 *state            = skelMat->getState      ();

    ract->dropFunctor(drawFuncSkinAlgo, state, skelMat->getSortKey());

    return res;
}
Beispiel #4
0
// 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();

    // create the scene
     
    /*
        Geometry data in OpenSG is stored in several separate vectors.
        
        These vectors are not a direct part of the Geometry Core but
        rather split up into multiple separate classes.
        
        These classes, the GeoProperties, contain a single field containg
        their values, which can be accessed directly, see the docs for
        GeoProperty for the whole interface.
    */
    
    /*
        The first part: the primtive types.
        These are taken from OpenGL, any values that can be passed to
        glBegin(); are legal. Different types can be freely mixed.
        
        All properties have only one field, which has the same name for every
        property, thus the mask is also called the same for each property.
    */
    GeoPTypesPtr type = GeoPTypesUI8::create();        
    beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask);
    {
        type->addValue(GL_POLYGON  );
        type->addValue(GL_TRIANGLES);
        type->addValue(GL_QUADS    );
    }
    endEditCP  (type, GeoPTypesUI8::GeoPropDataFieldMask);
    
    /*
        The second part: the primtive lengths.
        These define the number of vertices to be passed to OpenGL for each
        primitive. Thus there have to be at least as many entries as in the
        types property.
    */
    GeoPLengthsPtr lens = GeoPLengthsUI32::create();    
    beginEditCP(lens, GeoPLengthsUI32::GeoPropDataFieldMask);
    {
        lens->addValue(4);
        lens->addValue(6);
        lens->addValue(8);
    }
    endEditCP  (lens, GeoPLengthsUI32::GeoPropDataFieldMask);
       
    /*
        The third part: the vertex positions.
        
        OpenSG uses different types for vectors and points.
        
        Points (e.g. Pnt3f) are just positions in space, they have a limited
        set of operations they can handle. Vectors (e.g. Vec3f) are the more
        general kind.
    */
    GeoPositions3fPtr pnts = GeoPositions3f::create();
    beginEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask);
    {
        // the 4 points of the polygon
        pnts->addValue(Pnt3f(-1, -1, -1));
        pnts->addValue(Pnt3f(-1, -1,  1));
        pnts->addValue(Pnt3f( 1, -1,  1));
        pnts->addValue(Pnt3f( 1, -1, -1));

        // the 6 points of the two triangles
        pnts->addValue(Pnt3f( 1,  0, -1));
        pnts->addValue(Pnt3f(-1,  0, -1));
        pnts->addValue(Pnt3f( 0,  1, -1));

        pnts->addValue(Pnt3f(-1,  0,  1));
        pnts->addValue(Pnt3f( 1,  0,  1));
        pnts->addValue(Pnt3f( 0,  1,  1));

        // the 8 points of the two quads
        pnts->addValue(Pnt3f(-1,  -1,  1));    
        pnts->addValue(Pnt3f( 1,  -1,  1));    
        pnts->addValue(Pnt3f( 1,   0,  1));    
        pnts->addValue(Pnt3f(-1,   0,  1));    

        pnts->addValue(Pnt3f( 1,  -1, -1));    
        pnts->addValue(Pnt3f(-1,  -1, -1));    
        pnts->addValue(Pnt3f(-1,   0, -1));    
        pnts->addValue(Pnt3f( 1,   0, -1));    
    }
    endEditCP  (pnts, GeoPositions3f::GeoPropDataFieldMask);
   
    /*
       Put it all together into a Geometry NodeCore.
    */
    geo=Geometry::create();
    beginEditCP(geo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::MaterialFieldMask  );
    {
        geo->setTypes    (type);
        geo->setLengths  (lens);
        geo->setPositions(pnts);

        // assign a material to the geometry to make it visible. The details
        // of materials are defined later.
        geo->setMaterial(getDefaultUnlitMaterial());   
    }
    endEditCP  (geo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::MaterialFieldMask  );
    
    // put the geometry core into a node
    NodePtr n = Node::create();
    beginEditCP(n, Node::CoreFieldMask);
    {
        n->setCore(geo);
    }
    endEditCP  (n, Node::CoreFieldMask);
    
    // add a transformation to make it move     
    NodePtr scene = Node::create();  
    trans = Transform::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask  );
    {
        scene->setCore(trans);
        scene->addChild(n);
    }
    endEditCP  (scene, Node::CoreFieldMask | Node::ChildrenFieldMask  );
 

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
// 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();
   
    // Create the Scene
    NodePtr scene = Node::create();
    GroupPtr grcore = Group::create();
    
    beginEditCP(scene);
    scene->setCore(grcore);

    // Add a Torus for background
    
    scene->addChild(makeTorus(.2, 2, 16, 16));

    // The actual creation of the functors is a little complicated.
    // Mainly because the braindead M$ compiler has problems with, you have to
    // explicitly create the functor for the right combination of return value
    // type, number of arguments and argument types (values, pointers,
    // references, etc.) and whether it is a function, a static method or an
    // instance method.
    // Given that the signatures of the draw and volumeUpdate functions are
    // fixed, the three variants shown here should cover all the bases

    // Add the DrawFunctor node for standard functions
    
    NodePtr df = Node::create();
    DrawFunctorCorePtr func = DrawFunctorCore::create();

    beginEditCP(func);
    func->setMaterial(getDefaultUnlitMaterial());  
    
    func->setDraw(
        osgTypedFunctionFunctor1Ptr< Action::ResultE, DrawActionBase >(draw));
            
    func->setVolumeUpdate(
        osgTypedFunctionVoidFunctor1Ptr< Volume >(volUpdate));
            
    endEditCP(func);

    beginEditCP(df);
    df->setCore(func);
    endEditCP(df);

    scene->addChild(df);

    // Some transparent material
    // Even though the DrawFunctorCore can do any kind of OpenGL functions, the
    // Material of the Core is used to decide whether the node should be sorted
    // and rendered last
    
    SimpleMaterialPtr transmat = SimpleMaterial::create();
    
    beginEditCP(transmat);
    transmat->setTransparency(0.1);  // The actual value is overriden by the draw
                                // anyway, but it has to be != 0 to be
                                // considered transparent
    transmat->setLit(false);
    endEditCP(transmat);
    
    // Add the DrawFunctor node for static methods of a class
    // Static methods are pretty much the same as functions
    
    NodePtr dfsm = Node::create();
    DrawFunctorCorePtr funcsm = DrawFunctorCore::create();

    beginEditCP(funcsm);
    funcsm->setMaterial(transmat);    
    
    funcsm->setDraw(
        osgTypedFunctionFunctor1Ptr< Action::ResultE, DrawActionBase >(
            &SWrapper::draw));
            
    funcsm->setVolumeUpdate(
        osgTypedFunctionVoidFunctor1Ptr< Volume >(&SWrapper::volUpdate));
    
    endEditCP(funcsm);

    beginEditCP(dfsm);
    dfsm->setCore(funcsm);
    endEditCP(dfsm);

    scene->addChild(dfsm);

    // Add the DrawFunctor node for methods
    // The functor creation functions need the type of the object for which
    // methods should be called.
    
    Wrapper wrap(Color4f(0,1,0,.3));
    
    NodePtr dfm = Node::create();
    DrawFunctorCorePtr funcm = DrawFunctorCore::create();

    beginEditCP(funcm);

    funcm->setMaterial(transmat);    

    funcm->setDraw(
        osgTypedMethodFunctor1ObjPtr< Action::ResultE, Wrapper, DrawActionBase >(
            &wrap, &Wrapper::draw));

    funcm->setVolumeUpdate(
        osgTypedMethodVoidFunctor1ObjPtr< Wrapper, Volume >(
            &wrap, &Wrapper::volUpdate));

    endEditCP(funcm);

    beginEditCP(dfm);
    dfm->setCore(funcm);
    endEditCP(dfm);

    scene->addChild(dfm);
    
    // Add a Sphere, just for fun
    
    scene->addChild(makeLatLongSphere(16,16,.4));


    endEditCP(scene);
    
    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}