예제 #1
0
// This function creates a cylinder similarly to the teapot
// and the torus above. This time the cylinder is trimmed with
// a circle defined by 9 square-based control points to show
// an example of defining a circle without using infinite control
// points (see [Piegl and Tiller], pp. 299, Ex7.2 (Figure 7.16)) as
// well as to show how to define a rational trimming curve.
NodePtr makeTrimmedCylinder()
{
    SimpleMaterialPtr cylmat =  SimpleMaterial::create();
    beginEditCP(cylmat);
    {
        cylmat->setDiffuse(  Color3f(0.0, 0.8, 0.7));
        cylmat->setAmbient(  Color3f(0.2, 0.2, 0.2));
        cylmat->setEmission( Color3f(0.02, 0.02, 0.02) );
        cylmat->setSpecular( Color3f(0.78, 0.78, 0.78) );
        cylmat->setShininess( 128 );
        cylmat->addChunk(g_fb_chunk);
    }
    endEditCP(cylmat);
    float knots4[4] = {0, 0, 1, 1};
    float knots_circle[8] = {0, 0, 0, 0.5, 0.5, 1, 1, 1};
    float knots_outertrim[7] = {0, 0, 1, 2, 3, 4, 4};
    float knots_trimcircle[12] = {0, 0, 0, 0.25, 0.25, 0.5,
                                  0.5, 0.75, 0.75, 1, 1, 1
                                 };
    float cylcps[10][4] = {
        { 1.00,     0, -.50, 1},
        { 1.00,     0,  .50, 1},
        {    0,  1.00,    0, 0},
        {    0,  1.00,    0, 0},
        {-1.00,     0, -.50, 1},
        {-1.00,     0,  .50, 1},
        {    0, -1.00,    0, 0},
        {    0, -1.00,    0, 0},
        { 1.00,     0, -.50, 1},
        { 1.00,     0,  .50, 1},
    };
    float outertrim_cps[5][2] = {
        {0, 0},
        {1, 0},
        {1, 1},
        {0, 1},
        {0, 0},
    };
    float trimcircle_cps[9][3] = {
        {0.541667, 0.5,      1},
        {0.383016, 0.235702, 0.707107},
        {0.5,      0.333333, 1},
        {0.324091, 0.235702, 0.707107},
        {0.458333, 0.5,      1},
        {0.324091, 0.471405, 0.707107},
        {0.5,      0.666667, 1},
        {0.383016, 0.471405, 0.707107},
        {0.541667, 0.5,      1},
    };
    NodePtr cylnode = makeSurface(10, cylcps, 2, 1, 8, knots_circle,
                                  4, knots4, 0.001, cylmat);
    SurfacePtr s = SurfacePtr::dcast(cylnode->getCore());
    // add outer trimming around the domain
    addTrimCurve(s, 5, outertrim_cps, 1, 7, knots_outertrim, true);
    // add inside circle trimming
    addTrimCurve(s, 9, trimcircle_cps, 2, 12, knots_trimcircle, true);
    return cylnode;

}
예제 #2
0
    GeometryPtr createGeo(UInt32 mat)
    {
        GeoIndicesPtr ind = _ind[mat];
        
        FDEBUG(("CreateGeoRec::createGeo: Mat %d: %d inds (%d tris)\n",
                mat, ind->getSize(), ind->getSize()/3));
                
        endEditCP(ind);

        GeometryPtr geo = Geometry::create();

        GeoPLengthsUI32Ptr len = GeoPLengthsUI32::create();
        beginEditCP(len);
        len->push_back(ind->getSize());
        endEditCP(len);

        GeoPTypesUI8Ptr typ = GeoPTypesUI8::create();
        beginEditCP(typ);
        typ->push_back(GL_TRIANGLES);
        endEditCP(typ);

        beginEditCP(geo);
        if(random_color)
        {
            SimpleMaterialPtr mat = SimpleMaterial::create();
            beginEditCP(mat);
            Color3f c(  drand48() * .7f + .3f,
                        drand48() * .7f + .3f,
                        drand48() * .7f + .3f);
            mat->setDiffuse(c);
            mat->setSpecular(Color3f(1.f,1.f,1.f));
            mat->setShininess(10.f);                        
            endEditCP(mat);
            geo->setMaterial(mat);
        }
        else
        {
            geo->setMaterial(MaterialPool::getMaterial(mat));
        }
        geo->setPositions(_pos);
        geo->setIndices(ind);
        geo->setLengths(len);
        geo->setTypes(typ);
        
        geo->getIndexMapping().push_back(Geometry::MapPosition);
        endEditCP(geo);

        calcVertexNormals(geo);
        //calcFaceNormals(geo);
        createSingleIndex(geo);

        return geo;
    }
예제 #3
0
// This function creates a torus from a single NURBS surface
// using only 25 control points (of which 12 are unique).
// Similarly to the teapot, this uses the half-circle
// constructed from 3 control points (of which the middle point
// is infinite) which is then mirrored to form a full circle.
// (See the NURBS book [Piegl and Tiller], pp. 296, Ex7.1 (Figure 7.15)
// for details on the half-circle.)
NodePtr makeTorus()
{
    SimpleMaterialPtr torusmat =  SimpleMaterial::create();
    beginEditCP(torusmat);
    {
        torusmat->setDiffuse(  Color3f(1.0, 0.0, 0.2));
        torusmat->setAmbient(  Color3f(0.2, 0.2, 0.2));
        torusmat->setEmission( Color3f(0.02, 0.02, 0.02) );
        torusmat->setSpecular( Color3f(0.78, 0.78, 0.78) );
        torusmat->setShininess( 128 );
        torusmat->addChunk(g_fb_chunk);
    }
    endEditCP(torusmat);
    float knots_circle[8] = {0, 0, 0, 0.5, 0.5, 1, 1, 1};
    float toruscps[25][4] = {
        { 1.00,     0,  .75, 1}, //
        {  .25,     0,    0, 0}, //
        { 1.00,     0, 1.25, 1}, //
        { -.25,     0,    0, 0}, //
        { 1.00,     0,  .75, 1},
        {    0,  1.00,    0, 0}, //
        {    0,   .25,    0, 0}, //
        {    0,  1.00,    0, 0},
        {    0,  -.25,    0, 0}, //
        {    0,  1.00,    0, 0},
        {-1.00,     0,  .75, 1}, //
        { -.25,     0,    0, 0}, //
        {-1.00,     0, 1.25, 1}, //
        {  .25,     0,    0, 0}, //
        {-1.00,     0,  .75, 1},
        {    0, -1.00,    0, 0}, //
        {    0,  -.25,    0, 0},
        {    0, -1.00,    0, 0},
        {    0,   .25,    0, 0},
        {    0, -1.00,    0, 0},
        { 1.00,     0,  .75, 1},
        {  .25,     0,    0, 0},
        { 1.00,     0, 1.25, 1},
        { -.25,     0,    0, 0},
        { 1.00,     0,  .75, 1},
    };
    NodePtr torus = makeSurface(25, toruscps, 2, 2, 8, knots_circle,
                                8, knots_circle, 0.005, torusmat);
    return torus;
}
예제 #4
0
//! Copy Constructor
DVRVolume::DVRVolume(const DVRVolume &source) :
    Inherited         (source),
    drawStyleListValid(false ),
    textureManager    (this  ),
    shadingInitialized(false )
{
    SINFO << "DVRVolume::DVRVolume(const DVRVolume &source) this: "
          << this << std::endl;

    //!! FIXME:
    //!! This is only performed during instantiation of real objects
    //!! Which is only done with the copy constructor
    //!!
    //!! Otherwise my code cores - (maybe the copy constructor of FCPtr is 
    //!! broken?!)

    DVRVolumePtr ptr(*this);
    
    // Fake material for render action
    SimpleMaterialPtr m = SimpleMaterial::create();

    beginEditCP(m);
    {
        m->setTransparency(0.001f                );
        m->setLit         (false                 );
        m->setDiffuse     (Color3f(1.0, 1.0, 1.0));
        m->setAmbient     (Color3f(1.0, 1.0, 1.0));
    }
    endEditCP(m);
    
    // Chunk material as storage fieldcontainer for textures
    ChunkMaterialPtr cm = SimpleMaterial::create();

    // Add all
    beginEditCP(ptr, RenderMaterialFieldMask | TextureStorageFieldMask);
    {
        setRenderMaterial(m );
        setTextureStorage(cm);
    }
    endEditCP  (ptr, RenderMaterialFieldMask | TextureStorageFieldMask);

    commonConstructor();
}
예제 #5
0
NodePtr createScenegraph(){
    
    SimpleMaterialPtr simpleMaterial = SimpleMaterial::create();

    beginEditCP (simpleMaterial,    SimpleMaterial::DiffuseFieldMask |
                                    SimpleMaterial::AmbientFieldMask |
                                    SimpleMaterial::TransparencyFieldMask);
                
        simpleMaterial->setDiffuse(Color3f(1,0,0));
        simpleMaterial->setAmbient(Color3f(0.2, 0.2, 0.2));
        simpleMaterial->setTransparency(0.5);

    endEditCP   (simpleMaterial,    SimpleMaterial::DiffuseFieldMask |
                                    SimpleMaterial::AmbientFieldMask |
                                    SimpleMaterial::TransparencyFieldMask);
                                    
    NodePtr simpleMaterialNode = Node::create();
    NodePtr sphere = makeSphere(2,6);
    
    MaterialGroupPtr mg = MaterialGroup::create();
    beginEditCP(mg);
        mg->setMaterial(simpleMaterial);
    endEditCP(mg);
    
    beginEditCP(simpleMaterialNode);
        simpleMaterialNode->setCore(mg);
        simpleMaterialNode->addChild(sphere);
    endEditCP(simpleMaterialNode);
    
    NodePtr root = Node::create();
    
    beginEditCP(root);
        root->setCore(Group::create());
        root->addChild(simpleMaterialNode);
    endEditCP(root);
    
    return root;
}
예제 #6
0
int main(int argc, char **argv)
{
    osgInit(argc,argv);

    // GLUT init
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    PassiveWindowPtr pwin=PassiveWindow::create();
    pwin->init();   
    
    // create the texture
    tx1 = TextureChunk::create();
   
    const UInt16 width = 16, height = 1;
    
    ImagePtr pImg1 = Image::create();
    pImg1->set(Image::OSG_RGB_PF, width, height );
    
    beginEditCP(pImg1);
    UInt8 *d = pImg1->editData();
    
    for(UInt16 y = 0; y < height; ++y)
    {
        for(UInt16 x = 0; x < width; ++x)
        {
            *d++ = static_cast<UInt8>(x * 255.f / width);
            *d++ = static_cast<UInt8>(y * 255.f / height);
            *d++ = static_cast<UInt8>(128);
        }
    }
    endEditCP(pImg1);
    
    
    beginEditCP(tx1);
    tx1->setImage(pImg1); 
    tx1->setMinFilter(GL_NEAREST);
    tx1->setMagFilter(GL_NEAREST);
    tx1->setWrapS(GL_REPEAT);
    tx1->setWrapT(GL_REPEAT);
    endEditCP(tx1);

    tg = TexGenChunk::create();
    
    beginEditCP(tg);
    tg->setGenFuncS(GL_EYE_LINEAR);
    tg->setGenFuncSPlane(Vec4f(0,.15,0,0));
    endEditCP(tg);
    
  
    // create the material
    SimpleMaterialPtr mat = SimpleMaterial::create();
    
    beginEditCP(mat);
    mat->setDiffuse(Color3f(1,1,1));
    mat->setLit(false);
    mat->addChunk(tx1);
    mat->addChunk(tg);
    endEditCP(mat);
    
    // create the scene

    NodePtr torus = makeTorus( .5, 2, 16, 32 );

    GeometryPtr geo = GeometryPtr::dcast(torus->getCore());
    
    beginEditCP(geo, Geometry::MaterialFieldMask);
    geo->setMaterial(mat);
    endEditCP(geo, Geometry::MaterialFieldMask);
      
    transn1 = makeCoredNode<Transform>(&trans1);
    beginEditCP(transn1, Node::CoreFieldMask | Node::ChildrenFieldMask);
    {
        transn1->addChild(torus);
    }
    endEditCP  (transn1, Node::CoreFieldMask | Node::ChildrenFieldMask);


    transn2 = makeCoredNode<Transform>(&trans2);

    NodePtr scene = makeCoredNode<Group>();  
    beginEditCP(scene);
    scene->addChild(transn1);
    scene->addChild(transn2);
    endEditCP(scene);
    
    beginEditCP(tg);
    tg->setSBeacon(torus);
    endEditCP(tg);
    
    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // create the window and initial camera/viewport
    mgr->setWindow(pwin );
    // tell the manager what to manage
    mgr->setRoot  (scene);
    
    // show the whole scene
    mgr->showAll();
    mgr->redraw();

    webInterface = new WebInterface();
    webInterface->setRoot(scene);
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}
예제 #7
0
int main(int argc, char** argv)
{
    std::cout << "osgInit()..." << std::endl;
    osgInit( argc, argv );
    
    std::cout << "glutInit()..." <<  std::endl;
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
    int winID = glutCreateWindow("OpenSG");
    
    glutKeyboardFunc(key);
    glutVisibilityFunc(vis);
    glutReshapeFunc(resize);
    glutDisplayFunc(display);       
    glutMouseFunc(mouse);   
    glutMotionFunc(motion); 
    
    glutIdleFunc(display);
            
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
    glClearColor( .3, .3, .8, 1 );
    
    std::cout << "Creating objects..." << std::endl;
    
    //BEACON
    NodePtr beaconNode = Node::create();
    GroupPtr beaconCore = Group::create();
    beginEditCP( beaconNode );
    beaconNode->setCore( beaconCore );
    endEditCP( beaconNode );
    
    /*
    //LIGHT
    NodePtr dlightNode = Node::create();
    DirectionalLightPtr dlightCore = DirectionalLight::create();
    beginEditCP(dlightNode);
    dlightNode->setCore(dlightCore);
    endEditCP(dlightNode);
    
    beginEditCP(dlightCore);
    dlightCore->setAmbient( .3, .3, .3, 1 );
    dlightCore->setDiffuse( .5, .5, .5, 1 );
    dlightCore->setDirection( 0, 0 , 1 );
    dlightCore->setBeacon( beaconNode );
    endEditCP(dlightCore);
    */
        
    //TRANSFORM
    NodePtr transNode = Node::create();
    TransformPtr transCore = Transform::create();
    beginEditCP( transNode );
    transNode->setCore( transCore );
    transNode->addChild( beaconNode );
    endEditCP( transNode );
    cam_trans = transCore;
    
    //LOD
    NodePtr lowDetailNode = makeBox( 1,1,1, 1,1,1 );
    GeometryPtr boxCore = GeometryPtr::dcast(lowDetailNode->getCore());
    SimpleMaterialPtr lowDetailMat = SimpleMaterial::create();
    lowDetailMat->setDiffuse( Color3f( 1,0,0 ) );
    lowDetailMat->setAmbient( Color3f( 1,0,0 ) );
    boxCore->setMaterial( lowDetailMat );
    
    NodePtr     medDetailNode = makeSphere( 1, 1 );
    GeometryPtr medSphereCore = GeometryPtr::dcast(medDetailNode->getCore());
    SimpleMaterialPtr medDetailMat = SimpleMaterial::create();
    medDetailMat->setDiffuse( Color3f( 0,1,0 ) );
    medDetailMat->setAmbient( Color3f( 0,1,0 ) );
    medSphereCore->setMaterial( medDetailMat );
    
    NodePtr highDetailNode = makeSphere( 2, 1 );
    GeometryPtr highSphereCore = GeometryPtr::dcast(highDetailNode->getCore());
    SimpleMaterialPtr highDetailMat = SimpleMaterial::create();
    highDetailMat->setDiffuse( Color3f( 0,0,1 ) );
    highDetailMat->setAmbient( Color3f( 0,0,1 ) );
    highDetailMat->setSpecular( Color3f(1, 1, 1) );
    highDetailMat->setShininess( 10 );
    highSphereCore->setMaterial( highDetailMat );
    
    NodePtr lodNode = Node::create();
    DistanceLODPtr lodNodeCore = DistanceLOD::create();
    beginEditCP(lodNode);
    lodNode->setCore(lodNodeCore);
    lodNode->addChild( highDetailNode );
    lodNode->addChild( medDetailNode );
    lodNode->addChild( lowDetailNode );
    endEditCP(lodNode);
    
    beginEditCP(lodNodeCore);
    lodNodeCore->editSFCenter()->setValue( Pnt3f(0, 0, 2) );
    lodNodeCore->editMFRange()->push_back( 4.0 );
    lodNodeCore->editMFRange()->push_back( 8.0 );
    lodNodeCore->editMFRange()->push_back( 11.0 );
    endEditCP(lodNodeCore);
    
        
    //TRANSFORM LOD
    NodePtr transLODNode = Node::create();
    TransformPtr transLODCore = Transform::create();
    transMat.setTranslate( 1, -1, -1 );
    beginEditCP(transLODCore);
    transLODCore->editSFMatrix()->setValue( transMat );
    endEditCP(transLODCore);
    beginEditCP( transLODNode );
    transLODNode->setCore( transLODCore );
    transLODNode->addChild( lodNode );
    endEditCP( transLODNode );
    
    
        
    //ROOT
    root = Node::create();
    GroupPtr rootCore = Group::create();
    beginEditCP(root);
    root->setCore(rootCore);
    root->addChild(transNode);
    root->addChild(transLODNode);
    endEditCP(root);
    
    
    
    camera = PerspectiveCamera::create();
    beginEditCP(camera);
    camera->setBeacon( beaconNode );
    camera->setFov( deg2rad(90) );
    camera->setNear( 0.1 );
    camera->setFar( 10000 );
    endEditCP(camera);
    
    SolidBackgroundPtr background = SolidBackground::create();
    
    viewp = Viewport::create();
    beginEditCP(viewp);
    viewp->setCamera( camera );
    viewp->setBackground( background );
    viewp->setRoot( root );
    viewp->setSize( 0,0, 1,1 );
    endEditCP(viewp);
    
    GLint glVP[4];
    glGetIntegerv( GL_VIEWPORT, glVP );
    
    GLUTWindowPtr gwin = GLUTWindow::create();
    gwin->setId(winID);
    gwin->setSize(glVP[2], glVP[3]);
    
    window = gwin;
    beginEditCP(window);
    window->addPort( viewp );
    window->init();
    endEditCP(window);
    
    drAct = DrawAction::create();
    
    Vec3f pos( 0, 0, 3 );
    tball.setMode( Trackball::OSGObject );
    tball.setStartPosition( pos, true );
    tball.setSum( true );
    tball.setTranslationMode( Trackball::OSGFree );

    glutMainLoop();
    return 0;
}
예제 #8
0
int main(int argc, char **argv)
{
    osgInit(argc,argv);

    // GLUT init
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

    glutCreateWindow("OpenSG");

    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    PassiveWindowPtr pwin=PassiveWindow::create();
    pwin->init();

    // create the scene
    NodePtr scene;

    scene = Node::create();

    // create the material

    // Pass 1: Simple red, shiny, depth-tested

    DepthChunkPtr cl1 = DepthChunk::create();
    beginEditCP(cl1);
    cl1->setEnable(true);
    cl1->setFunc(GL_LEQUAL);
    endEditCP(cl1);

    SimpleMaterialPtr mat = SimpleMaterial::create();
    beginEditCP(mat);
    mat->setDiffuse(Color3f(1,0,0));
    mat->setSpecular(Color3f(.9,.9,.9));
    mat->setShininess(30);
    mat->setLit(true);
    mat->addChunk(cl1);
    endEditCP(mat);

    // Pass 2: Green unlit, without depth testing

    DepthChunkPtr cl2 = DepthChunk::create();
    beginEditCP(cl2);
    cl2->setEnable(false);
    endEditCP(cl2);

    SimpleMaterialPtr mat2 = SimpleMaterial::create();
    beginEditCP(mat2);
    mat2->setDiffuse(Color3f(0,1,0));
    mat2->setLit(false);
    mat2->setTransparency(.8);
    mat2->addChunk(cl2);
    endEditCP(mat2);

    // Bring them together

    MultiPassMaterialPtr mpm = MultiPassMaterial::create();

    beginEditCP(mpm);
    mpm->editMFMaterials()->push_back(mat);
    mpm->editMFMaterials()->push_back(mat2);
    endEditCP(mpm);

    GeometryPtr g1 = makeTorusGeo(0.2, 2, 8, 16);

    beginEditCP(scene);
    scene->setCore(g1);
    endEditCP(scene);

    beginEditCP(g1);

    g1->setMaterial(mpm);

    endEditCP(g1);

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // create the window and initial camera/viewport
    mgr->setWindow(pwin );
    // tell the manager what to manage
    mgr->setRoot  (scene);

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

    // GLUT main loop
    glutMainLoop();

    return 0;
}
예제 #9
0
NodePtr Puck::init()
{
	// CREATE THE PUCK
    NodePtr puck_trans_node = makeCoredNode<Transform>(&transPtr);
    beginEditCP(transPtr);
	{
		transPtr->getMatrix().setTranslate(position[0],position[1],position[2]);
	}
    endEditCP(transPtr);


    NodePtr puck = OSG::makeCylinder(PUCK_HALF_HEIGHT*2.0,radius, 32, true, true ,true);
    beginEditCP(puck_trans_node);
	{
		puck_trans_node->addChild(puck);
	}
    endEditCP(puck_trans_node);

    SimpleMaterialPtr puck_mat = SimpleMaterial::create();
    beginEditCP(puck_mat);
	{
		puck_mat->setAmbient(Color3f(0.0,0.0,0.0));
		puck_mat->setDiffuse(Color3f(1.0,0.0,0.0));
	}
    endEditCP(puck_mat);

    GeometryPtr puck_geo = GeometryPtr::dcast(puck->getCore());
    beginEditCP(puck_geo);
		puck_geo->setMaterial(puck_mat);
    beginEditCP(puck_geo);

	/////////////////////////////
	// SETUP THE INTERSECTION TEST COMPONENTS
	// Create a small geometry to show the ray and what was hit
    // Contains a line and a single triangle.
    // The line shows the ray, the triangle whatever was hit.
	isectPoints = GeoPositions3f::create();
    beginEditCP(isectPoints);
    {
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
    }
    endEditCP(isectPoints);
	GeoIndicesUI32Ptr index = GeoIndicesUI32::create();     
    beginEditCP(index);
    {
        index->addValue(0);
        index->addValue(1);
        index->addValue(2);
        index->addValue(3);
        index->addValue(4);
    }
    endEditCP(index);

    GeoPLengthsUI32Ptr lens = GeoPLengthsUI32::create();    
    beginEditCP(lens);
    {
        lens->addValue(2);
        lens->addValue(3);
    }
    endEditCP(lens);
    
    GeoPTypesUI8Ptr type = GeoPTypesUI8::create();  
    beginEditCP(type);
    {
        type->addValue(GL_LINES);
        type->addValue(GL_TRIANGLES);
    }
    endEditCP(type);
    
    SimpleMaterialPtr red = SimpleMaterial::create();
    
    beginEditCP(red);
    {
        red->setDiffuse     (Color3f( 1,0,0 ));   
        red->setTransparency(0.5);   
        red->setLit         (false);   
    }
    endEditCP  (red);

    testgeocore = Geometry::create();
    beginEditCP(testgeocore);
    {
        testgeocore->setPositions(isectPoints);
        testgeocore->setIndices(index);
        testgeocore->setLengths(lens);
        testgeocore->setTypes(type);
        testgeocore->setMaterial(red);
    }
    endEditCP(testgeocore);   

	NodePtr testgeo = Node::create();
    beginEditCP(testgeo);
    {
        testgeo->setCore(testgeocore);
    }
    endEditCP(testgeo);
    
	beginEditCP(puck_trans_node);
	{
		puck_trans_node->addChild(testgeo);
	}


	return puck_trans_node;
}
예제 #10
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();

    // The scene group
    
    NodePtr  scene = Node::create();
    GroupPtr g     = Group::create();
    
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
    scene->setCore(g);
    
    if(argc < 2)
    {
        FWARNING(("No file given!\n"));
        FWARNING(("Supported file formats:\n"));
        
        std::list<const char*> suffixes;
        SceneFileHandler::the().getSuffixList(suffixes);
        
        for(std::list<const char*>::iterator it  = suffixes.begin();
                                             it != suffixes.end();
                                           ++it)
        {
            FWARNING(("%s\n", *it));
        }

        fileroot = makeTorus(.5, 2, 16, 16);
    }
    else
    {
        /*
            All scene file loading is handled via the SceneFileHandler.
        */
        fileroot = SceneFileHandler::the().read(argv[1]);
    }

    scene->addChild(fileroot);
    
    // Create a small geometry to show the ray and what was hit
    // Contains a line and a single triangle.
    // The line shows the ray, the triangle whatever was hit.
    
    SimpleMaterialPtr red = SimpleMaterial::create();
    
    beginEditCP(red);
    {
        red->setDiffuse     (Color3f( 1,0,0 ));   
        red->setTransparency(0.5);   
        red->setLit         (false);   
    }
    endEditCP  (red);

    isectPoints = GeoPositions3f::create();
    beginEditCP(isectPoints);
    {
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
        isectPoints->addValue(Pnt3f(0,0,0));
    }
    endEditCP(isectPoints);

    GeoIndicesUI32Ptr index = GeoIndicesUI32::create();     
    beginEditCP(index);
    {
        index->addValue(0);
        index->addValue(1);
        index->addValue(2);
        index->addValue(3);
        index->addValue(4);
        index->addValue(5);
        index->addValue(6);
    }
    endEditCP(index);

    GeoPLengthsUI32Ptr lens = GeoPLengthsUI32::create();    
    beginEditCP(lens);
    {
        lens->addValue(4);
        lens->addValue(3);
    }
    endEditCP(lens);
    
    GeoPTypesUI8Ptr type = GeoPTypesUI8::create();  
    beginEditCP(type);
    {
        type->addValue(GL_LINES);
        type->addValue(GL_TRIANGLES);
    }
    endEditCP(type);

    testgeocore = Geometry::create();
    beginEditCP(testgeocore);
    {
        testgeocore->setPositions(isectPoints);
        testgeocore->setIndices(index);
        testgeocore->setLengths(lens);
        testgeocore->setTypes(type);
        testgeocore->setMaterial(red);
    }
    endEditCP(testgeocore);   
    
    NodePtr testgeo = Node::create();
    beginEditCP(testgeo);
    {
        testgeo->setCore(testgeocore);
    }
    endEditCP(testgeo);
    
    scene->addChild(testgeo);
    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();

    mgr->getCamera()->setNear(mgr->getCamera()->getNear() / 10);

    // Show the bounding volumes? Not for now
    mgr->getAction()->setVolumeDrawing(false);
    
    // GLUT main loop
    glutMainLoop();

    return 0;

    // GLUT main loop
    glutMainLoop();

    return 0;
}
예제 #11
0
int main (int argc, char **argv)
{
    osgInit(argc,argv);

    // GLUT init

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    int winid = glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    glutVisibilityFunc(vis);
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutIdleFunc(display);

    // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );

    // OSG

    SceneFileHandler::the().print();

    // create the graph

    // beacon for camera and light
    NodePtr b1n = Node::create();
    GroupPtr b1 = Group::create();
    beginEditCP(b1n);
    b1n->setCore( b1 );
    endEditCP(b1n);

    // transformation
    NodePtr t1n = Node::create();
    TransformPtr t1 = Transform::create();
    beginEditCP(t1n);
    t1n->setCore( t1 );
    t1n->addChild( b1n );
    endEditCP(t1n);

    cam_trans = t1;

    // light

    NodePtr dlight = Node::create();
    DirectionalLightPtr dl = DirectionalLight::create();

    beginEditCP(dlight);
    dlight->setCore( dl );
    endEditCP(dlight);

    beginEditCP(dl);
    dl->setAmbient( .3, .3, .3, 1 );
    dl->setDiffuse( 1, 1, 1, 1 );
    dl->setDirection(0,0,1);
    dl->setBeacon( b1n);
    endEditCP(dl);

    // root
    root = Node::create();
    GroupPtr gr1 = Group::create();
    beginEditCP(root);
    root->setCore( gr1 );
    root->addChild( t1n );
    root->addChild( dlight );
    endEditCP(root);

    // Load the file

    NodePtr file = NullFC;
    NodePtr file1 = NullFC;

    if ( argc > 1 )
        file1 = SceneFileHandler::the().read(argv[1]);

    if ( file1 == NullFC )
    {
        std::cerr << "Couldn't load file, ignoring" << std::endl;
        file1 = makeTorus( .5, 2, 16, 16 );
    }

    file1->updateVolume();

//    file->dump();

//    subRefCP(file);

//    return 0;


    Vec3f min,max;
    file1->getVolume().getBounds( min, max );

    std::cout << "Volume: from " << min << " to " << max << std::endl;


    file = Node::create();
    MaterialGroupPtr testMat = MaterialGroup::create();

    SimpleMaterialPtr defaultMaterial = SimpleMaterial::create();

    beginEditCP(defaultMaterial);
    defaultMaterial->setDiffuse(Color3f(1,.0,.0));
    defaultMaterial->setAmbient(Color3f(0.1,0.1,0.1));
    defaultMaterial->setSpecular(Color3f(1,1,1));
    defaultMaterial->setShininess(20);
    endEditCP  (defaultMaterial);


    testMat->setMaterial(defaultMaterial);

    beginEditCP(file);
    {
//        file->setCore(testMat);
        file->setCore(Group::create());
        file->addChild(file1);
    }
    endEditCP  (file);

    scene_trans      = Transform::create();
    NodePtr sceneTrN = Node::create();

    beginEditCP(sceneTrN);
    {
        sceneTrN->setCore(scene_trans);
        sceneTrN->addChild(file);
        sceneTrN->addChild(makeTorus( .5, 2, 16, 16 ));
    }
    endEditCP(sceneTrN);

    beginEditCP(dlight);
    dlight->addChild(sceneTrN);
    endEditCP(dlight);

    std::cerr << "Tree: " << std::endl;
//  root->dump();

    // Camera

    cam = PerspectiveCamera::create();
    cam->setBeacon( b1n );
    cam->setFov( deg2rad( 90 ) );
    cam->setNear( 0.1 );
    cam->setFar( 100000 );

    // Background
    SolidBackgroundPtr bkgnd = SolidBackground::create();
    beginEditCP(bkgnd, SolidBackground::ColorFieldMask);
    bkgnd->setColor(Color3f(1,1,1));
    endEditCP(bkgnd, SolidBackground::ColorFieldMask);

    // Viewport

    vp = Viewport::create();
    vp->setCamera( cam );
    vp->setBackground( bkgnd );
    vp->setRoot( root );
    vp->setSize( 0,0, 1,1 );

    // Window
    std::cout << "GLUT winid: " << winid << std::endl;

    GLUTWindowPtr gwin;

    GLint glvp[4];
    glGetIntegerv( GL_VIEWPORT, glvp );

    gwin = GLUTWindow::create();
    gwin->setId(winid);
    gwin->setSize( glvp[2], glvp[3] );

    win = gwin;

    win->addPort( vp );

    win->init();

    // Action

    ract = DrawAction::create();
    renact = RenderAction::create();

    // tball

    Vec3f pos;
    pos.setValues(min[0] + ((max[0] - min[0]) * 0.5),
                  min[1] + ((max[1] - min[1]) * 0.5),
                  max[2] + ( max[2] - min[2] ) * 1.5 );

    float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6;

    Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2,
                  min[1] + (max[1] - min[1]) / 2,
                  min[2] + (max[2] - min[2]) / 2);

    tball.setMode( Trackball::OSGObject );
    tball.setStartPosition( pos, true );
    tball.setSum( true );
    tball.setTranslationMode( Trackball::OSGFree );
    tball.setTranslationScale(scale);
    tball.setRotationCenter(tCenter);

    // run...

    glutMainLoop();

    return 0;
}
예제 #12
0
// This function creates the classic Utah teapot from 4 NURBS
// surfaces: one surface each for the lid, body, handle and spout.
// The "classic" representation is using 18 rational Bezier patches,
// but in order to show the construction of more complex surfaces
// these have been combined into as few NURBS surfaces as possible.
NodePtr makeTeapot()
{
    SimpleMaterialPtr teapotmat =  SimpleMaterial::create();
    beginEditCP(teapotmat);
    {
        teapotmat->setDiffuse(  Color3f(0.8, 0.8, 0.8));
        teapotmat->setAmbient(  Color3f(0.2, 0.2, 0.2));
        teapotmat->setEmission( Color3f(0.02, 0.02, 0.02) );
        teapotmat->setSpecular( Color3f(0.78, 0.78, 0.78) );
        teapotmat->setShininess( 128 );
        teapotmat->addChunk(g_fb_chunk);
    }
    endEditCP(teapotmat);
    NodePtr teapotroot = makeCoredNode<Group>();
    float knots11[11] = {0, 0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1, 1};
    float knots14[14] = {0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3};
    float knots_circle[8] = {0, 0, 0, 0.5, 0.5, 1, 1, 1};
    float lidcps[35][4] = {
        { 0.0000, 4.0000, 0.0000, 1.0000},
        { 0.0000, 4.0000, 0.8000, 1.0000},
        { 0.0000, 3.6000, 0.0000, 1.0000},
        { 0.0000, 3.4000, 0.2000, 1.0000},
        { 0.0000, 3.2000, 0.4000, 1.0000},
        { 0.0000, 3.2000, 1.3000, 1.0000},
        { 0.0000, 3.0000, 1.3000, 1.0000},

        {-0.0000, 0.0000, 0.0000, 0.0000},
        {-0.8000, 0.0000, 0.0000, 0.0000},
        {-0.0000, 0.0000, 0.0000, 0.0000},
        {-0.2000, 0.0000, 0.0000, 0.0000},
        {-0.4000, 0.0000, 0.0000, 0.0000},
        {-1.3000, 0.0000, 0.0000, 0.0000},
        {-1.3000, 0.0000, 0.0000, 0.0000},

        { 0.0000, 4.0000,-0.0000, 1.0000},
        { 0.0000, 4.0000,-0.8000, 1.0000},
        { 0.0000, 3.6000,-0.0000, 1.0000},
        { 0.0000, 3.4000,-0.2000, 1.0000},
        { 0.0000, 3.2000,-0.4000, 1.0000},
        { 0.0000, 3.2000,-1.3000, 1.0000},
        { 0.0000, 3.0000,-1.3000, 1.0000},

        { 0.0000, 0.0000, 0.0000, 0.0000},
        { 0.8000, 0.0000, 0.0000, 0.0000},
        { 0.0000, 0.0000, 0.0000, 0.0000},
        { 0.2000, 0.0000, 0.0000, 0.0000},
        { 0.4000, 0.0000, 0.0000, 0.0000},
        { 1.3000, 0.0000, 0.0000, 0.0000},
        { 1.3000, 0.0000, 0.0000, 0.0000},

        { 0.0000, 4.0000, 0.0000, 1.0000},
        { 0.0000, 4.0000, 0.8000, 1.0000},
        { 0.0000, 3.6000, 0.0000, 1.0000},
        { 0.0000, 3.4000, 0.2000, 1.0000},
        { 0.0000, 3.2000, 0.4000, 1.0000},
        { 0.0000, 3.2000, 1.3000, 1.0000},
        { 0.0000, 3.0000, 1.3000, 1.0000},
    };
    NodePtr lid = makeSurface(35, lidcps, 2, 3, 8, knots_circle,
                              11, knots11, 0.005, teapotmat);
    float bodycps[50][4] = {
        { 0.0000, 3.0000, 1.4000, 1.0000},
        { 0.0000, 3.1750, 1.3375, 1.0000},
        { 0.0000, 3.1750, 1.4375, 1.0000},
        { 0.0000, 3.0000, 1.5000, 1.0000},
        { 0.0000, 2.3000, 1.7500, 1.0000},
        { 0.0000, 1.6000, 2.0000, 1.0000},
        { 0.0000, 1.0000, 2.0000, 1.0000},
        { 0.0000, 0.4000, 2.0000, 1.0000},
        { 0.0000, 0.2000, 1.5000, 1.0000},
        { 0.0000, 0.0000, 1.5000, 1.0000},

        {-1.4000, 0.0000, 0.0000, 0.0000},
        {-1.3375, 0.0000, 0.0000, 0.0000},
        {-1.4375, 0.0000, 0.0000, 0.0000},
        {-1.5000, 0.0000, 0.0000, 0.0000},
        {-1.7500, 0.0000, 0.0000, 0.0000},
        {-2.0000, 0.0000, 0.0000, 0.0000},
        {-2.0000, 0.0000, 0.0000, 0.0000},
        {-2.0000, 0.0000, 0.0000, 0.0000},
        {-1.5000, 0.0000, 0.0000, 0.0000},
        {-1.5000, 0.0000, 0.0000, 0.0000},

        { 0.0000, 3.0000,-1.4000, 1.0000},
        { 0.0000, 3.1750,-1.3375, 1.0000},
        { 0.0000, 3.1750,-1.4375, 1.0000},
        { 0.0000, 3.0000,-1.5000, 1.0000},
        { 0.0000, 2.3000,-1.7500, 1.0000},
        { 0.0000, 1.6000,-2.0000, 1.0000},
        { 0.0000, 1.0000,-2.0000, 1.0000},
        { 0.0000, 0.4000,-2.0500, 1.0000},
        { 0.0000, 0.2000,-1.5000, 1.0000},
        { 0.0000, 0.0000,-1.5000, 1.0000},

        { 1.4000, 0.0000, 0.0000, 0.0000},
        { 1.3375, 0.0000, 0.0000, 0.0000},
        { 1.4375, 0.0000, 0.0000, 0.0000},
        { 1.5000, 0.0000, 0.0000, 0.0000},
        { 1.7500, 0.0000, 0.0000, 0.0000},
        { 2.0000, 0.0000, 0.0000, 0.0000},
        { 2.0000, 0.0000, 0.0000, 0.0000},
        { 2.0000, 0.0000, 0.0000, 0.0000},
        { 1.5000, 0.0000, 0.0000, 0.0000},
        { 1.5000, 0.0000, 0.0000, 0.0000},

        { 0.0000, 3.0000, 1.4000, 1.0000},
        { 0.0000, 3.1750, 1.3375, 1.0000},
        { 0.0000, 3.1750, 1.4375, 1.0000},
        { 0.0000, 3.0000, 1.5000, 1.0000},
        { 0.0000, 2.3000, 1.7500, 1.0000},
        { 0.0000, 1.6000, 2.0000, 1.0000},
        { 0.0000, 1.0000, 2.0000, 1.0000},
        { 0.0000, 0.4000, 2.0000, 1.0000},
        { 0.0000, 0.2000, 1.5000, 1.0000},
        { 0.0000, 0.0000, 1.5000, 1.0000},

    };
    NodePtr body = makeSurface(50, bodycps, 2, 3, 8, knots_circle,
                               14, knots14, 0.005, teapotmat);
    float handlecps[35][4] = {
        { 1.5000, 2.8000, 0.0000, 1.0000},
        { 2.5000, 2.8000, 0.0000, 1.0000},
        { 3.0000, 2.8000, 0.0000, 1.0000},
        { 3.0000, 2.2000, 0.0000, 1.0000},
        { 3.0000, 1.6000, 0.0000, 1.0000},
        { 2.6500, 1.0500, 0.0000, 1.0000},
        { 1.9000, 0.6000, 0.0000, 1.0000},

        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},
        { 0.0000, 0.0000, 0.3000, 0.0000},

        { 1.6000, 2.5000, 0.0000, 1.0000},
        { 2.3000, 2.5000, 0.0000, 1.0000},
        { 2.7000, 2.5000, 0.0000, 1.0000},
        { 2.7000, 2.2000, 0.0000, 1.0000},
        { 2.7000, 1.9000, 0.0000, 1.0000},
        { 2.5000, 1.5000, 0.0000, 1.0000},
        { 2.0000, 1.0000, 0.0000, 1.0000},

        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},
        { 0.0000, 0.0000,-0.3000, 0.0000},

        { 1.5000, 2.8000, 0.0000, 1.0000},
        { 2.5000, 2.8000, 0.0000, 1.0000},
        { 3.0000, 2.8000, 0.0000, 1.0000},
        { 3.0000, 2.2000, 0.0000, 1.0000},
        { 3.0000, 1.6000, 0.0000, 1.0000},
        { 2.6500, 1.0500, 0.0000, 1.0000},
        { 1.9000, 0.6000, 0.0000, 1.0000},
    };

    NodePtr handle = makeSurface(35, handlecps, 2, 3, 8, knots_circle,
                                 11, knots11, 0.005, teapotmat);
    float spoutcps[35][4] = {
        {-1.7000, 0.6000, 0.0000, 1.0000},
        {-3.1000, 0.9000, 0.0000, 1.0000},
        {-2.4000, 2.6000, 0.0000, 1.0000},
        {-3.3000, 3.0000, 0.0000, 1.0000},
        {-3.5250, 3.1250, 0.0000, 1.0000},
        {-3.4500, 3.1500, 0.0000, 1.0000},
        {-3.2000, 3.0000, 0.0000, 1.0000},

        { 0.0000, 0.0000, 0.6600, 0.0000},
        { 0.0000, 0.0000, 0.6600, 0.0000},
        { 0.0000, 0.0000, 0.2500, 0.0000},
        { 0.0000, 0.0000, 0.2500, 0.0000},
        { 0.0000, 0.0000, 0.2500, 0.0000},
        { 0.0000, 0.0000, 0.1500, 0.0000},
        { 0.0000, 0.0000, 0.1500, 0.0000},

        {-1.7000, 1.7000, 0.0000, 1.0000},
        {-2.6000, 1.7000, 0.0000, 1.0000},
        {-2.3000, 2.6000, 0.0000, 1.0000},
        {-2.7000, 3.0000, 0.0000, 1.0000},
        {-2.8000, 3.1000, 0.0000, 1.0000},
        {-2.9000, 3.1000, 0.0000, 1.0000},
        {-2.8000, 3.0000, 0.0000, 1.0000},

        { 0.0000, 0.0000,-0.6600, 0.0000},
        { 0.0000, 0.0000,-0.6600, 0.0000},
        { 0.0000, 0.0000,-0.2500, 0.0000},
        { 0.0000, 0.0000,-0.2500, 0.0000},
        { 0.0000, 0.0000,-0.2500, 0.0000},
        { 0.0000, 0.0000,-0.1500, 0.0000},
        { 0.0000, 0.0000,-0.1500, 0.0000},

        {-1.7000, 0.6000, 0.0000, 1.0000},
        {-3.1000, 0.9000, 0.0000, 1.0000},
        {-2.4000, 2.6000, 0.0000, 1.0000},
        {-3.3000, 3.0000, 0.0000, 1.0000},
        {-3.5250, 3.1250, 0.0000, 1.0000},
        {-3.4500, 3.1500, 0.0000, 1.0000},
        {-3.2000, 3.0000, 0.0000, 1.0000},
    };
    NodePtr spout = makeSurface(35, spoutcps, 2, 3, 8, knots_circle,
                                11, knots11, 0.005, teapotmat);

    beginEditCP(teapotroot);
    teapotroot->addChild(lid);
    teapotroot->addChild(body);
    teapotroot->addChild(handle);
    teapotroot->addChild(spout);
    endEditCP(teapotroot);
    return teapotroot;
}
예제 #13
0
NodePtr createRose()
{
    GeometryPtr geoPtr = Geometry::create();
    beginEditCP(geoPtr);
    {
        GeoPTypesUI8Ptr typesPtr = GeoPTypesUI8::create();
        typesPtr->push_back(GL_QUADS);
        geoPtr->setTypes(typesPtr);

        GeoPLengthsUI32Ptr lensPtr = GeoPLengthsUI32::create();
        lensPtr->push_back(96);
        geoPtr->setLengths(lensPtr);

        GeoPositions3fPtr posPtr = GeoPositions3f::create();

        // top
        posPtr->push_back(Vec3f( 0.00f,  1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f,  0.10f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.10f,  0.00f));

        posPtr->push_back(Vec3f( 0.00f,  1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.10f,  0.00f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f, -0.10f));

        posPtr->push_back(Vec3f( 0.00f,  1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f, -0.10f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.10f,  0.00f));

        posPtr->push_back(Vec3f( 0.00f,  1.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.10f,  0.00f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f,  0.10f));

        // bottom
        posPtr->push_back(Vec3f( 0.00f, -1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f, -0.10f,  0.00f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f,  0.10f));

        posPtr->push_back(Vec3f( 0.00f, -1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f,  0.10f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f(-0.10f, -0.10f,  0.00f));

        posPtr->push_back(Vec3f( 0.00f, -1.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f, -0.10f,  0.00f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f, -0.10f));

        posPtr->push_back(Vec3f( 0.00f, -1.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f, -0.10f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.10f, -0.10f,  0.00f));

        // left
        posPtr->push_back(Vec3f(-1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f, -0.10f,  0.00f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f,  0.10f));

        posPtr->push_back(Vec3f(-1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f,  0.10f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.10f,  0.00f));

        posPtr->push_back(Vec3f(-1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.10f,  0.00f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f, -0.10f));

        posPtr->push_back(Vec3f(-1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f, -0.10f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f(-0.10f, -0.10f,  0.00f));

        // right
        posPtr->push_back(Vec3f( 1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f,  0.10f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.10f, -0.10f,  0.00f));

        posPtr->push_back(Vec3f( 1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f, -0.10f,  0.00f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f, -0.10f));

        posPtr->push_back(Vec3f( 1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f, -0.10f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.10f,  0.00f));

        posPtr->push_back(Vec3f( 1.00f,  0.00f,  0.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.10f,  0.00f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f,  0.10f));

        // front
        posPtr->push_back(Vec3f( 0.00f,  0.00f,  1.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f,  0.10f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f,  0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f,  1.00f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f,  0.10f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f,  0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f,  0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f,  1.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f,  0.10f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f,  0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f,  1.00f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f,  0.10f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f,  0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f,  0.10f));

        // back
        posPtr->push_back(Vec3f( 0.00f,  0.00f, -1.00f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f, -0.10f));
        posPtr->push_back(Vec3f(-0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f, -0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f, -1.00f));
        posPtr->push_back(Vec3f( 0.00f,  0.10f, -0.10f));
        posPtr->push_back(Vec3f( 0.05f,  0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f, -0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f, -1.00f));
        posPtr->push_back(Vec3f( 0.10f,  0.00f, -0.10f));
        posPtr->push_back(Vec3f( 0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f, -0.10f));

        posPtr->push_back(Vec3f( 0.00f,  0.00f, -1.00f));
        posPtr->push_back(Vec3f( 0.00f, -0.10f, -0.10f));
        posPtr->push_back(Vec3f(-0.05f, -0.05f, -0.05f));
        posPtr->push_back(Vec3f(-0.10f,  0.00f, -0.10f));

        geoPtr->setPositions(posPtr);

        SimpleMaterialPtr matPtr = SimpleMaterial::create();
        beginEditCP(matPtr);
        {
            matPtr->setDiffuse(Color3f(1, 0, 0));
        }
        endEditCP(matPtr);
        geoPtr->setMaterial(matPtr);
    }
    endEditCP(geoPtr);

    calcFaceNormals(geoPtr);

    NodePtr nodePtr = Node::create();
    beginEditCP(nodePtr, Node::CoreFieldMask);
    {
        nodePtr->setCore(geoPtr);
    }
    endEditCP(nodePtr, Node::CoreFieldMask);

    return nodePtr;
}
예제 #14
0
void CharacterModel::convertMaterials(std::string configfile)
{
    getMaterials().clear();
    UInt32 mcnt = 0;
    PathHandler ph;
    
    ph.setBaseFile(configfile.c_str());
       
    for(int mid = 0; mid < _coreModel->getCoreMaterialCount(); mid++)
    {
        CalCoreMaterial *coremat = _coreModel->getCoreMaterial(mid);
        SimpleMaterialPtr mat = SimpleMaterial::create();

        beginEditCP(mat);

        CalCoreMaterial::Color &calamb = coremat->getAmbientColor();
        CalCoreMaterial::Color &caldif = coremat->getDiffuseColor();
        CalCoreMaterial::Color &calspec = coremat->getSpecularColor();

        mat->setAmbient(Color3f(calamb.red / 255.0f, calamb.green / 255.0f, calamb.blue / 255.0f));
        mat->setDiffuse(Color3f(caldif.red / 255.0f, caldif.green / 255.0f, caldif.blue / 255.0f));
        mat->setSpecular(Color3f(calspec.red / 255.0f, calspec.green / 255.0f, calspec.blue / 255.0f));
        
        mat->setShininess(coremat->getShininess() * 100.f);
        mat->setLit(true);
        mat->setColorMaterial(GL_NONE);
        
        for(int mapId = 0; mapId < coremat->getMapCount(); mapId++)
        {
            std::string file = coremat->getMapFilename(mapId);
            std::string pfile = ph.findFile(file.c_str());
            SINFO << "Loading texture '" << pfile << "'..." << endLog;

            ImagePtr img = Image::create();
            
             if(!img->read(pfile.c_str()))
            {
                SWARNING << "CharacterModel::convertMaterials: error "
                         << "loading image " << file << endLog;
            }
            else
            {
                // amz with my test scene paladin.cfg all textures were
                // upside down so I disabled the vertical flipping perhaps
                // they fixed the bug in Cal3D?
#if 0
                beginEditCP(img);
                {
                // For some reason Cal3D expects textures upside down ???
                UInt32 bpl = img->getBpp() * img->getWidth();
                UChar8 *t = img->getData(), 
                       *b = t + (img->getHeight() - 1) * bpl,
                        dum;

                for(UInt32 y = img->getHeight() / 2; y > 0; --y)
                {
                    for(UInt32 x = bpl; x > 0; --x, ++t, ++b)
                    {
                        dum = *t;
                        *t = *b;
                        *b = dum;
                    }
                    b -= bpl * 2;
                }
                }
                endEditCP(img);
#endif
                
                TextureChunkPtr tex = TextureChunk::create();
                
                beginEditCP(tex);
                tex->setImage(img);
                tex->setEnvMode(GL_MODULATE);
                endEditCP(tex);
                
                mat->addChunk(tex);
            }
        }
            
        endEditCP(mat);
        
        coremat->setUserData((Cal::UserData)mcnt);
        getMaterials().push_back(mat);
        mcnt ++;
    }    
}
예제 #15
0
NodePtr createScenegraph(){
    //At first we load all needed models from file
    NodePtr w_high = SceneFileHandler::the().read("data/woman_high.wrl");
    NodePtr w_medium = SceneFileHandler::the().read("data/woman_medium.wrl");
    NodePtr w_low = SceneFileHandler::the().read("data/woman_low.wrl");
    
    //we check the result
    if ((w_high == NullFC)&&(w_medium == NullFC)&&(w_low == NullFC)){
        std::cout << "It was not possible to load all needed models from file" << std::endl;
        return NullFC;
    }
    
    //now the LOD core
    DistanceLODPtr lod = DistanceLOD::create();
    beginEditCP(lod, DistanceLOD::CenterFieldMask | DistanceLOD::RangeFieldMask);
        lod->getSFCenter()->setValue(Pnt3f(0,0,0));
        lod->getMFRange()->push_back(200);
        lod->getMFRange()->push_back(500);
    endEditCP(lod, DistanceLOD::CenterFieldMask | DistanceLOD::RangeFieldMask);
    
    //the node containing the LOD core. The three models will be
    //added as its children
    NodePtr lodNode = Node::create();
    beginEditCP(lodNode);
        lodNode->setCore(lod);
        lodNode->addChild(w_high);
        lodNode->addChild(w_medium);
        lodNode->addChild(w_low);
    endEditCP(lodNode);
    
        //create the node with switch core ********************
    SwitchPtr sw = Switch::create();
    beginEditCP(sw, Switch::ChoiceFieldMask);
        //Notice: the first choice is 0
        sw->setChoice(0);
    endEditCP(sw, Switch::ChoiceFieldMask);
    
    NodePtr switchNode = Node::create();
    beginEditCP(switchNode);
        switchNode->setCore(sw);
        switchNode->addChild(lodNode);
    endEditCP(switchNode);
    
    //end witch creation **********************************
    
    NodePtr root = Node::create();
    beginEditCP(root);
        root->setCore(Group::create());
        root->addChild(switchNode);
    endEditCP(root);
    
    // we know want to extract the mesh geometry out of the graph
    // it is sufficent to pass the model only as root for searching
    NodePtr womanGeometry = checkName(w_high);
	GeometryPtr geo;
	if (womanGeometry != NullFC){
		geo = GeometryPtr::dcast(womanGeometry->getCore());
		if (geo == NullFC)
			std::cout << "Casting failed!" << std::endl;
	}else{ 
		std::cout << "No correct geometry node found!" << std::endl;
		//create a dummy object
		geo = makeBoxGeo(0.5,0.5,0.5,1,1,1);
	}
    
    // generating a material *********************************
    
    SimpleMaterialPtr mat = SimpleMaterial::create();
    beginEditCP(mat);
        mat->setAmbient(Color3f(0.2,0.2,0.2));
        mat->setDiffuse(Color3f(0.6,0.3,0.1));
        mat->setSpecular(Color3f(1,1,1));
        mat->setShininess(0.8);
    endEditCP(mat);
    
    beginEditCP(geo, Geometry::MaterialFieldMask);
        geo->setMaterial(mat);
    endEditCP(geo, Geometry::MaterialFieldMask);
    
    // end material generation *******************************
    
    //new node with "old" geometry core referenced
    NodePtr woman = Node::create();
    beginEditCP(woman);
        woman->setCore(geo);
    endEditCP(woman);
    
    //translate it a bit to see both women
    NodePtr womanTrans = Node::create();
    TransformPtr t = Transform::create();
    beginEditCP(t);
        Matrix m;
        m.setIdentity();
        m.setTranslate(Vec3f(0,0,200));
        t->setMatrix(m);
    endEditCP(t); 
    beginEditCP(womanTrans);
        womanTrans->setCore(t);
        womanTrans->addChild(woman);
    endEditCP(womanTrans);
    
    //add it to the root
    beginEditCP(root);
        root->addChild(womanTrans);
    endEditCP(root);
    
    return root;
}
예제 #16
0
NodePtr createScenegraph(){
    // the scene must be created here
    for (int x = 0; x < N; x++)
        for (int z = 0; z < N; z++)
            wMesh[x][z] = 0;
            
    // GeoPTypes will define the types of primitives to be used
    GeoPTypesPtr type = GeoPTypesUI8::create();
    beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask);
	// we want to use quads ONLY 
	type->addValue(GL_QUADS);
    endEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask);
    
    // GeoPLength will define the number of vertices of
    // the used primitives
    GeoPLengthsPtr length = GeoPLengthsUI32::create();
    beginEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask);
	// the length of our quads is four ;-)
	length->addValue((N-1)*(N-1)*4);
    endEditCP(length, GeoPLengthsUI32::GeoPropDataFieldMask);

    // GeoPositions3f stores the positions of all vertices used in 
    // this specific geometry core
    GeoPositions3fPtr pos = GeoPositions3f::create();
    beginEditCP(pos, GeoPositions3f::GeoPropDataFieldMask);
	// here they all come
	for (int x = 0; x < N; x++)
            for (int z = 0; z < N; z++)
		pos->addValue(Pnt3f(x, wMesh[x][z], z));
    endEditCP(pos, GeoPositions3f::GeoPropDataFieldMask);

    //GeoColors3f stores all color values that will be used
    GeoColors3fPtr colors = GeoColors3f::create();
    beginEditCP(colors, GeoColors3f::GeoPropDataFieldMask);
        for (int x = 0; x < N; x++)
            for (int z = 0; z < N; z++)
		colors->addValue(Color3f(0,0,1));
    endEditCP(colors, GeoColors3f::GeoPropDataFieldMask);
    
    GeoNormals3fPtr norms = GeoNormals3f::create();
    beginEditCP(norms, GeoNormals3f::GeoPropDataFieldMask);
        for (int x = 0; x < N; x++)
            for (int z = 0; z < N; z++)
		// As initially all heights are set to zero thus yielding a plane,
		// we set all normals to (0,1,0) parallel to the y-axis
		norms->addValue(Vec3f(0,1,0));
    endEditCP(norms, GeoNormals3f::GeoPropDataFieldMask);
    
    SimpleMaterialPtr mat = SimpleMaterial::create();
    beginEditCP(mat);
        mat->setDiffuse(Color3f(0,0,1));
    endEditCP(mat);
    
    // GeoIndicesUI32 points to all relevant data used by the 
    // provided primitives
    GeoIndicesUI32Ptr indices = GeoIndicesUI32::create();
    beginEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask);
        for (int x = 0; x < N-1; x++)
            for (int z = 0; z < N-1; z++){
		// points to four vertices that will
		// define a single quad
		indices->addValue(z*N+x);	
		indices->addValue((z+1)*N+x);
		indices->addValue((z+1)*N+x+1);
		indices->addValue(z*N+x+1);
            }
    endEditCP(indices, GeoIndicesUI32::GeoPropDataFieldMask);

        GeometryPtr geo = Geometry::create();
    beginEditCP(geo,
        Geometry::TypesFieldMask	|
	Geometry::LengthsFieldMask	|
	Geometry::IndicesFieldMask	|
	Geometry::PositionsFieldMask	|
	Geometry::NormalsFieldMask      |
        Geometry::MaterialFieldMask     |
	Geometry::ColorsFieldMask	|
        Geometry::DlistCacheFieldMask
	);
	
	geo->setTypes(type);
	geo->setLengths(length);
	geo->setIndices(indices);
	geo->setPositions(pos);
	geo->setNormals(norms);
        geo->setMaterial(mat);
	//geo->setColors(colors);
        geo->setDlistCache(false);

    endEditCP(geo,
        Geometry::TypesFieldMask	|
	Geometry::LengthsFieldMask	|
	Geometry::IndicesFieldMask	|
	Geometry::PositionsFieldMask	|
	Geometry::NormalsFieldMask	|
        Geometry::MaterialFieldMask     |
	Geometry::ColorsFieldMask	|
        Geometry::DlistCacheFieldMask
	);
    
    PointLightPtr pLight = PointLight::create();
    NodePtr root = Node::create();
    NodePtr water = Node::create();
    NodePtr pLightTransformNode = Node::create();
    TransformPtr pLightTransform = Transform::create();
    NodePtr pLightNode = Node::create();
    
    beginEditCP(pLightNode);
        pLightNode->setCore(Group::create());
    endEditCP(pLightNode);
    
    Matrix m;
    m.setIdentity();
    m.setTranslate(50,25,50);
    
    beginEditCP(pLightTransform);
        pLightTransform->setMatrix(m);
    endEditCP(pLightTransform);
    
    //we add a little spehere that will represent the light source
    GeometryPtr sphere = makeSphereGeo(2,2);

    SimpleMaterialPtr sm = SimpleMaterial::create();

    beginEditCP(sm, SimpleMaterial::DiffuseFieldMask |
                    SimpleMaterial::LitFieldMask);
    {
        sm->setLit(false);
        sm->setDiffuse(Color3f(1,1,1));
    }
    endEditCP  (sm, SimpleMaterial::DiffuseFieldMask |
                    SimpleMaterial::LitFieldMask);

    beginEditCP(sphere, Geometry::MaterialFieldMask);
    {
        sphere->setMaterial(sm);
    }
    endEditCP  (sphere, Geometry::MaterialFieldMask);
    
    NodePtr sphereNode = Node::create();
    beginEditCP(sphereNode);
        sphereNode->setCore(sphere);
    endEditCP(sphereNode);

    beginEditCP(pLightTransformNode);
        pLightTransformNode->setCore(pLightTransform);
        pLightTransformNode->addChild(pLightNode);
        pLightTransformNode->addChild(sphereNode);
    endEditCP(pLightTransformNode);

    beginEditCP(pLight);
        pLight->setPosition(Pnt3f(0,0,0));
    
        //Attenuation parameters
        pLight->setConstantAttenuation(1);
        pLight->setLinearAttenuation(0);
        pLight->setQuadraticAttenuation(0);
        
        //color information
        pLight->setDiffuse(Color4f(1,1,1,1));
        pLight->setAmbient(Color4f(0.2,0.2,0.2,1));
        pLight->setSpecular(Color4f(1,1,1,1));
        
        //set the beacon
        pLight->setBeacon(pLightNode);
    endEditCP  (pLight);

    
    beginEditCP(water);
        water->setCore(geo);
    endEditCP(water);
    
    beginEditCP(root);
        root->setCore(pLight);
        root->addChild(water);
        root->addChild(pLightTransformNode);
    endEditCP(root);    
    return root;
}
예제 #17
0
NodePtr createScoreBoards()
{
	GeometryPtr geo;
	NodePtr bg;
	SimpleMaterialPtr m;
	ScoreBoard1 = new TextStuff() ;
	ScoreBoard2 = new TextStuff() ;

	// First get the global group node
    OSG::NodePtr scoreBoardsNodePtr = OSG::Node::create();
    scoreBoardsNodePtr->setCore(OSG::Group::create());

    // Setup text 1
    ScoreBoard1->initialize();
    ScoreBoard1->updateFace();
    ScoreBoard1->updateScore(0,0);
    // Setup text 2
    ScoreBoard2->initialize();
    ScoreBoard2->updateFace();
    ScoreBoard2->updateScore(0,0);

	////////// 1 /////////
	// make its transform
	TransformPtr trans1;
    NodePtr trans_node1 = makeCoredNode<Transform>(&trans1);
    beginEditCP(trans1);
		trans1->getMatrix().setTransform(Vec3f(0,4,-10.5),Quaternion( Vec3f(0,1,0),deg2rad(0)));
    endEditCP(trans1);

	// make geometry
	bg = makePlane(9.3, 1, 8,2);
	 m= SimpleMaterial::create();
    beginEditCP(m);
    {		
        m->setAmbient      (Color3f(0,0,0));
        m->setDiffuse      (Color3f(0.0,0.0,0.0));
    }
    endEditCP  (m);  
	geo = GeometryPtr::dcast(bg->getCore());  
    beginEditCP(geo);
		geo->setMaterial(m);
    beginEditCP(geo);

	beginEditCP(bg);
	bg->addChild(ScoreBoard1->mRootNode);
	endEditCP(bg);

	beginEditCP(trans_node1);
		trans_node1->addChild(bg);
	endEditCP(trans_node1);

	////////// 2 /////////
	// make its transform
	TransformPtr trans2;
    NodePtr trans_node2 = makeCoredNode<Transform>(&trans2);
    beginEditCP(trans2);
		trans2->getMatrix().setTransform(Vec3f(0,4,10.5),Quaternion( Vec3f(0,1,0),deg2rad(180)));
    endEditCP(trans2);

	// make geometry
	bg = makePlane(9.3, 1, 8,2);
	m = SimpleMaterial::create();
    beginEditCP(m);
    {		
        m->setAmbient      (Color3f(0,0,0));
        m->setDiffuse      (Color3f(0.0,0.0,0.0));
    }
    endEditCP  (m);  
	geo = GeometryPtr::dcast(bg->getCore());  
    beginEditCP(geo);
		geo->setMaterial(m);
    beginEditCP(geo);

	beginEditCP(bg);
	bg->addChild(ScoreBoard2->mRootNode);
	endEditCP(bg);

	beginEditCP(trans_node2);
		trans_node2->addChild(bg);
	endEditCP(trans_node2);


	beginEditCP(scoreBoardsNodePtr);
		scoreBoardsNodePtr->addChild(trans_node1);
		scoreBoardsNodePtr->addChild(trans_node2);
	endEditCP(scoreBoardsNodePtr);
  

    return scoreBoardsNodePtr;
}