Changeset 1339 for trunk/Tutorials

Show
Ignore:
Timestamp:
06/23/08 16:48:12 (2 months ago)
Author:
cneumann
Message:

fixed compile errors in tutorials 01 to 11 (07,09 are not present on trunk)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Tutorials/01hello.cpp

    r835 r1339  
    4545    int winid = setupGLUT(&argc, argv); 
    4646 
    47     // the connection between GLUT and OpenSG 
    48     GLUTWindowPtr gwin= GLUTWindow::create(); 
    49     gwin->setGlutId(winid); 
    50     gwin->init(); 
    51  
    52     // create the scene 
    53     NodePtr scene = makeTorus(.5, 2, 16, 16); 
    54  
    55     commitChanges(); 
    56  
    57     // create the SimpleSceneManager helper 
    58     mgr = new SimpleSceneManager; 
    59  
    60     // tell the manager what to manage 
    61     mgr->setWindow(gwin ); 
    62     mgr->setRoot  (scene); 
    63  
    64     // show the whole scene 
    65     mgr->showAll(); 
     47    // open a new scope, because the pointers gwin and scene below should 
     48    // go out of scope before entering glutMainLoop. 
     49    // Otherwise OpenSG will complain about objects being alive after shutdown. 
     50    { 
     51        // the connection between GLUT and OpenSG 
     52        GLUTWindowRefPtr gwin= GLUTWindow::create(); 
     53        gwin->setGlutId(winid); 
     54        gwin->init(); 
     55     
     56        // create the scene 
     57        NodeRefPtr scene = makeTorus(.5, 2, 16, 16); 
     58     
     59        commitChanges(); 
     60     
     61        // create the SimpleSceneManager helper 
     62        mgr = new SimpleSceneManager; 
     63     
     64        // tell the manager what to manage 
     65        mgr->setWindow(gwin ); 
     66        mgr->setRoot  (scene); 
     67     
     68        // show the whole scene 
     69        mgr->showAll(); 
     70    } 
    6671     
    6772    // GLUT main loop 
     
    113118        case 27:         
    114119        { 
     120            delete mgr; 
     121         
    115122            OSG::osgExit(); 
    116123            exit(0); 
  • trunk/Tutorials/02move.cpp

    r835 r1339  
    2424 
    2525// The pointer to the transformation 
    26 TransformPtr trans; 
    27  
     26TransformRefPtr trans; 
    2827 
    2928// The SimpleSceneManager to manage simple applications 
     
    6463    int winid = setupGLUT(&argc, argv); 
    6564 
    66     // the connection between GLUT and OpenSG 
    67     GLUTWindowPtr gwin= GLUTWindow::create(); 
    68     gwin->setGlutId(winid); 
    69     gwin->init(); 
    70  
    71     // create the scene 
    72  
    73     NodePtr torus = makeTorus( .5, 2, 16, 32 ); 
    74  
    75     // create the transformation node 
    76     // scenegraph nodes are split into 2 parts: the node and its core 
     65    // open a new scope, because the pointers gwin and scene below should 
     66    // go out of scope before entering glutMainLoop. 
     67    // Otherwise OpenSG will complain about objects being alive after shutdown. 
     68    { 
     69        // the connection between GLUT and OpenSG 
     70        GLUTWindowRefPtr gwin= GLUTWindow::create(); 
     71        gwin->setGlutId(winid); 
     72        gwin->init(); 
    7773     
    78     // 1. create the Node 
    79     NodePtr scene = Node::create(); 
     74        // create the scene 
    8075     
    81     // 2. create the core 
    82     trans = Transform::create(); 
     76        NodeRefPtr torus = makeTorus( .5, 2, 16, 32 ); 
    8377     
    84     // 3. associate the core with the node 
    85   
    86     scene->setCore(trans); 
    87     // add the torus as a child 
    88     scene->addChild(torus); 
     78        // create the transformation node 
     79        // scenegraph nodes are split into 2 parts: the node and its core 
     80         
     81        // 1. create the Node 
     82        NodeRefPtr scene = Node::create(); 
     83         
     84        // 2. create the core 
     85        trans = Transform::create(); 
     86         
     87        // 3. associate the core with the node 
    8988     
    90     commitChanges(); 
    91  
    92     // create the SimpleSceneManager helper 
    93     mgr = new SimpleSceneManager; 
    94  
    95     // tell the manager what to manage 
    96     mgr->setWindow(gwin ); 
    97     mgr->setRoot  (scene); 
    98  
    99     // show the whole scene 
    100     mgr->showAll(); 
     89        scene->setCore(trans); 
     90        // add the torus as a child 
     91        scene->addChild(torus); 
     92         
     93        commitChanges(); 
     94     
     95        // create the SimpleSceneManager helper 
     96        mgr = new SimpleSceneManager; 
     97     
     98        // tell the manager what to manage 
     99        mgr->setWindow(gwin ); 
     100        mgr->setRoot  (scene); 
     101     
     102        // show the whole scene 
     103        mgr->showAll(); 
     104    } 
    101105 
    102106    // GLUT main loop 
     
    142146        case 27:   
    143147        { 
     148            // clean up global variables 
     149            trans = NULL; 
     150            delete mgr; 
     151         
    144152            OSG::osgExit(); 
    145153            exit(0); 
  • trunk/Tutorials/03share.cpp

    r835 r1339  
    2727 
    2828// a seprate transformation for every copy 
    29 TransformPtr trans[ncopies]; 
     29TransformRefPtr trans[ncopies]; 
    3030 
    3131 
     
    4444     
    4545    // set the transforms' matrices 
    46     for(UInt16 i=0; i<ncopies; ++i) 
     46    for(UInt16 i=0; i < ncopies; ++i) 
    4747    { 
    4848        m.setTransform(Vec3f(      osgSin(t / 1000.f + i * 4 * ncopies / Pi),  
     
    6969    int winid = setupGLUT(&argc, argv); 
    7070 
    71     // the connection between GLUT and OpenSG 
    72     GLUTWindowPtr gwin= GLUTWindow::create(); 
    73     gwin->setGlutId(winid); 
    74     gwin->init(); 
    75  
    76     // create the scene 
    77      
    78     /* 
    79        Scenegraph nodes in OpenSG consist of two parts: the Node and its Core. 
    80         
    81        The Node contains the general information that anchors an object in the 
    82        graph: the parent, a list of children, a bounding volume. Note that the 
    83        Node contains a single parent, a Node can only be connected to a graph 
    84        in one place. 
    85         
    86        There is only one Node class, all nodes in the scenegraph use the same 
    87        Node. The specific information that distinguishes node kinds from each 
    88        other is stored in the NodeCore. 
    89  
    90        Consequently there is a different kind of NodeCore for the different 
    91        kinds of functions a node can have. The NodeCore contains all the 
    92        information that the Node doesn't. 
    93         
    94        NodeCores can be used by multiple Nodes. In this example the Geometry 
    95        NodeCore of the torus is used to display multiple tori. 
    96     */ 
    97      
    98     // this time, create just the core of the geometry 
    99     GeometryPtr torus = makeTorusGeo( .5, 2, 8, 12 ); 
    100  
    101     // create the scene 
    102     // the scene has a single group with ncopies transformations below, 
    103     // each of these carries a Node that shares the geometry 
    104      
    105     /* 
    106        The Group NodeCore is the basic type to create the hierarchical graph. 
    107        It does very little to its children, just calls all of them when asked 
    108        to do anything, and collecting their information if necessary. 
    109     */ 
    110      
    111     // create the root Group node 
    112     NodePtr  scene = Node::create(); 
    113     GroupPtr g     = Group::create(); 
    114      
    115     scene->setCore(g); 
    116      
    117     // create the copied geometry nodes and their transformations 
    118     for(UInt16 i = 0; i<ncopies; ++i) 
     71    // open a new scope, because the pointers below should go out of scope 
     72    // before entering glutMainLoop. 
     73    // Otherwise OpenSG will complain about objects being alive after shutdown. 
    11974    { 
    120         // create the nodes for the shared Geometry core 
    121         NodePtr geonode = Node::create(); 
    122          
    123         // assign the Core to the Node 
    124         geonode->setCore(torus); 
    125  
    126         // add a transformation for every Geometry 
    127         NodePtr transnode = Node::create(); 
    128          
    129         trans[i] = Transform::create(); 
    130           
    131         transnode->setCore (trans[i]); 
    132         transnode->addChild(geonode ); 
    133         
    134         scene->addChild(transnode);        
     75        // the connection between GLUT and OpenSG 
     76        GLUTWindowRefPtr gwin= GLUTWindow::create(); 
     77        gwin->setGlutId(winid); 
     78        gwin->init(); 
     79     
     80        // create the scene 
     81         
     82        /* 
     83        Scenegraph nodes in OpenSG consist of two parts: the Node and its Core. 
     84         
     85        The Node contains the general information that anchors an object in the 
     86        graph: the parent, a list of children, a bounding volume. Note that the 
     87        Node contains a single parent, a Node can only be connected to a graph 
     88        in one place. 
     89         
     90        There is only one Node class, all nodes in the scenegraph use the same 
     91        Node. The specific information that distinguishes node kinds from each 
     92        other is stored in the NodeCore. 
     93     
     94        Consequently there is a different kind of NodeCore for the different 
     95        kinds of functions a node can have. The NodeCore contains all the 
     96        information that the Node doesn't. 
     97         
     98        NodeCores can be used by multiple Nodes. In this example the Geometry 
     99        NodeCore of the torus is used to display multiple tori. 
     100        */ 
     101         
     102        // this time, create just the core of the geometry 
     103        GeometryRefPtr torus = makeTorusGeo( .5, 2, 8, 12 ); 
     104     
     105        // create the scene 
     106        // the scene has a single group with ncopies transformations below, 
     107        // each of these carries a Node that shares the geometry 
     108         
     109        /* 
     110        The Group NodeCore is the basic type to create the hierarchical graph. 
     111        It does very little to its children, just calls all of them when asked 
     112        to do anything, and collecting their information if necessary. 
     113        */ 
     114         
     115        // create the root Group node 
     116        NodeRefPtr  scene = Node::create(); 
     117        GroupRefPtr g     = Group::create(); 
     118         
     119        scene->setCore(g); 
     120         
     121        // create the copied geometry nodes and their transformations 
     122        for(UInt16 i = 0; i < ncopies; ++i) 
     123        { 
     124            // create the nodes for the shared Geometry core 
     125            NodeRefPtr geonode = Node::create(); 
     126             
     127            // assign the Core to the Node 
     128            geonode->setCore(torus); 
     129     
     130            // add a transformation for every Geometry 
     131            NodeRefPtr transnode = Node::create(); 
     132             
     133            trans[i] = Transform::create(); 
     134             
     135            transnode->setCore (trans[i]); 
     136            transnode->addChild(geonode ); 
     137         
     138            scene->addChild(transnode);        
     139        } 
     140     
     141        commitChanges(); 
     142     
     143        // create the SimpleSceneManager helper 
     144        mgr = new SimpleSceneManager; 
     145     
     146        // tell the manager what to manage 
     147        mgr->setWindow(gwin ); 
     148        mgr->setRoot  (scene); 
     149     
     150        // show the whole scene 
     151        mgr->showAll(); 
    135152    } 
    136  
    137     commitChanges(); 
    138  
    139     // create the SimpleSceneManager helper 
    140     mgr = new SimpleSceneManager; 
    141  
    142     // tell the manager what to manage 
    143     mgr->setWindow(gwin ); 
    144     mgr->setRoot  (scene); 
    145  
    146     // show the whole scene 
    147     mgr->showAll(); 
    148153 
    149154    // GLUT main loop 
     
    189194        case 27:     
    190195        { 
     196            // clean up global variables 
     197            for(UInt16 i = 0; i < ncopies; ++i) 
     198                trans[i] = NULL; 
     199             
     200            delete mgr; 
     201         
    191202            OSG::osgExit(); 
    192203            exit(0); 
  • trunk/Tutorials/04hiertransform.cpp

    r835 r1339  
    2222 
    2323// just use a single transformation that is shared 
    24 TransformPtr trans; 
     24TransformRefPtr trans; 
    2525 
    2626 
     
    5757    int winid = setupGLUT(&argc, argv); 
    5858 
    59     // the connection between GLUT and OpenSG 
    60     GLUTWindowPtr gwin= GLUTWindow::create(); 
    61     gwin->setGlutId(winid); 
    62     gwin->init(); 
    63  
    64     // create the scene 
    65  
    66     /* 
    67         Transformation accumulate through the graph, i.e. all nodes below 
    68         a Transformation are influenced by it, even other Transformations. 
    69          
    70         This can be used to create models of objects that move together and 
    71         in relation to each other, the prime examples being a robot arm and 
    72         a planetary system. This example does something not quite unlike a 
    73         robot arm. 
    74     */     
    75  
    76     // create the scene 
    77      
    78     /* 
    79        This time the graph is not wide, but deep, i.e. every Transformation 
    80        only has two children, a Geometry and another transformation. 
    81        The end resulting motion of the geometry is the accumulation of 
    82        all the Transformations above it. 
    83     */ 
    84       
    85     // use a cylinder this time 
    86     GeometryPtr cyl = makeCylinderGeo( 1, .3, 8, true, true, true ); 
    87      
    88     // the single transformation Core used 
    89     trans = Transform::create(); 
    90      
    91     // setup an intial transformation 
    92     Matrix m; 
    93     m.setTransform(Vec3f(0, .9, 0)); 
    94  
    95     trans->setMatrix(m); 
    96      
    97     /* 
    98        NullFC is the generic NULL value for FieldContainer pointer. 
    99     */ 
    100     NodePtr last = NullFC; 
    101      
    102     // create the copied transformations and their geometry nodes 
    103     for(UInt16 i = 1; i < ncopies; ++i) 
     59    // open a new scope, because the pointers below should go out of scope 
     60    // before entering glutMainLoop. 
     61    // Otherwise OpenSG will complain about objects being alive after shutdown. 
    10462    { 
    105         // create the shared Geometry 
    106         NodePtr geonode = Node::create(); 
    107         geonode->setCore(cyl); 
    108  
    109         // add a transformation to the Geometry 
    110         NodePtr transnode = Node::create(); 
    111  
    112         transnode->setCore (trans); 
    113         transnode->addChild(geonode ); 
    114         if(last != NullFC) 
     63        // the connection between GLUT and OpenSG 
     64        GLUTWindowRefPtr gwin= GLUTWindow::create(); 
     65        gwin->setGlutId(winid); 
     66        gwin->init(); 
     67     
     68        // create the scene 
     69     
     70        /* 
     71            Transformation accumulate through the graph, i.e. all nodes below 
     72            a Transformation are influenced by it, even other Transformations. 
     73             
     74            This can be used to create models of objects that move together and 
     75            in relation to each other, the prime examples being a robot arm and 
     76            a planetary system. This example does something not quite unlike a 
     77            robot arm. 
     78        */     
     79     
     80        // create the scene 
     81         
     82        /* 
     83        This time the graph is not wide, but deep, i.e. every Transformation 
     84        only has two children, a Geometry and another transformation. 
     85        The end resulting motion of the geometry is the accumulation of 
     86        all the Transformations above it. 
     87        */ 
     88         
     89        // use a cylinder this time 
     90        GeometryRefPtr cyl = makeCylinderGeo( 1, .3, 8, true, true, true ); 
     91         
     92        // the single transformation Core used 
     93        trans = Transform::create(); 
     94         
     95        // setup an intial transformation 
     96        Matrix m; 
     97        m.setTransform(Vec3f(0, .9, 0)); 
     98     
     99        trans->setMatrix(m); 
     100         
     101        NodeRefPtr last = NULL; 
     102         
     103        // create the copied transformations and their geometry nodes 
     104        for(UInt16 i = 1; i < ncopies; ++i) 
    115105        { 
    116             transnode->addChild(last);        
     106            // create the shared Geometry 
     107            NodeRefPtr geonode = Node::create(); 
     108            geonode->setCore(cyl); 
     109     
     110            // add a transformation to the Geometry 
     111            NodeRefPtr transnode = Node::create(); 
     112     
     113            transnode->setCore (trans  ); 
     114            transnode->addChild(geonode); 
     115             
     116            if(last != NULL) 
     117            { 
     118                transnode->addChild(last);        
     119            } 
     120         
     121            last = transnode; 
    117122        } 
    118         
    119         last = transnode; 
     123     
     124        NodeRefPtr scene = last; 
     125     
     126        commitChanges(); 
     127     
     128        // create the SimpleSceneManager helper 
     129        mgr = new SimpleSceneManager; 
     130     
     131        // tell the manager what to manage 
     132        mgr->setWindow(gwin ); 
     133        mgr->setRoot  (scene); 
     134     
     135        // show the whole scene 
     136        mgr->showAll(); 
    120137    } 
    121   
    122     NodePtr scene = last; 
    123  
    124     commitChanges(); 
    125  
    126     // create the SimpleSceneManager helper 
    127     mgr = new SimpleSceneManager; 
    128  
    129     // tell the manager what to manage 
    130     mgr->setWindow(gwin ); 
    131     mgr->setRoot  (scene); 
    132  
    133     // show the whole scene 
    134     mgr->showAll(); 
    135138 
    136139    // GLUT main loop 
     
    176179        case 27:     
    177180        { 
     181            // clean up global variables 
     182            trans = NULL; 
     183            delete mgr; 
     184         
    178185            OSG::osgExit(); 
    179186            exit(0); 
  • trunk/Tutorials/05geometry.cpp

    r835 r1339  
    2727 
    2828// The pointer to the transformation 
    29 TransformPtr trans; 
     29TransformRefPtr trans; 
    3030 
    3131// The pointer to the geometry core 
    32 GeometryPtr geo; 
     32GeometryRefPtr geo; 
    3333 
    3434 
     
    4848    int winid = setupGLUT(&argc, argv); 
    4949 
    50     // the connection between GLUT and OpenSG 
    51     GLUTWindowPtr gwin= GLUTWindow::create(); 
    52     gwin->setGlutId(winid); 
    53     gwin->init(); 
    54  
    55     // create the scene 
    56       
    57     /* 
    58         Geometry data in OpenSG is stored in several separate vectors. 
    59          
    60         These vectors are not a direct part of the Geometry Core but 
    61         rather split up into multiple separate classes. 
    62          
    63         These classes, the GeoProperties, contain a single field containg 
    64         their values, which can be accessed directly, see the docs for 
    65         GeoProperty for the whole interface. 
    66     */ 
    67      
    68     /* 
    69         The first part: the primtive types. 
    70         These are taken from OpenGL, any values that can be passed to 
    71         glBegin(); are legal. Different types can be freely mixed. 
    72          
    73         All properties have only one field, which has the same name for every 
    74         property, thus the mask is also called the same for each property. 
    75     */ 
    76     GeoUInt8PropertyPtr type = GeoUInt8Property::create(); 
    77     type->addValue(GL_POLYGON  ); 
    78     type->addValue(GL_TRIANGLES); 
    79     type->addValue(GL_QUADS    ); 
    80      
    81     /* 
    82         The second part: the primtive lengths. 
    83         These define the number of vertices to be passed to OpenGL for each 
    84         primitive. Thus there have to be at least as many entries as in the 
    85         types property. 
    86     */ 
    87     GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 
    88     lens->addValue(4); 
    89     lens->addValue(6); 
    90     lens->addValue(8); 
    91         
    92     /* 
    93         The third part: the vertex positions. 
    94          
    95         OpenSG uses different types for vectors and points. 
    96          
    97         Points (e.g. Pnt3f) are just positions in space, they have a limited 
    98         set of operations they can handle. Vectors (e.g. Vec3f) are the more 
    99         general kind. 
    100     */ 
    101     GeoPnt3fPropertyPtr  pnts = OSG::GeoPnt3fProperty::create(); 
    102     // the 4 points of the polygon 
    103     pnts->addValue(Pnt3f(-1, -1, -1)); 
    104     pnts->addValue(Pnt3f(-1, -1,  1)); 
    105     pnts->addValue(Pnt3f( 1, -1,  1)); 
    106     pnts->addValue(Pnt3f( 1, -1, -1)); 
    107  
    108     // the 6 points of the two triangles 
    109     pnts->addValue(Pnt3f( 1,  0, -1)); 
    110     pnts->addValue(Pnt3f(-1,  0, -1)); 
    111     pnts->addValue(Pnt3f( 0,  1, -1)); 
    112  
    113     pnts->addValue(Pnt3f(-1,  0,  1)); 
    114     pnts->addValue(Pnt3f( 1,  0,  1)); 
    115     pnts->addValue(Pnt3f( 0,  1,  1)); 
    116  
    117     // the 8 points of the two quads 
    118     pnts->addValue(Pnt3f(-1,  -1,  1));     
    119     pnts->addValue(Pnt3f( 1,  -1,  1));     
    120     pnts->addValue(Pnt3f( 1,   0,  1));     
    121     pnts->addValue(Pnt3f(-1,   0,  1));     
    122  
    123     pnts->addValue(Pnt3f( 1,  -1, -1));     
    124     pnts->addValue(Pnt3f(-1,  -1, -1));     
    125     pnts->addValue(Pnt3f(-1,   0, -1));     
    126     pnts->addValue(Pnt3f( 1,   0, -1));     
    127     
    128     /* 
    129        Put it all together into a Geometry NodeCore. 
    130     */ 
    131     geo=Geometry::create(); 
    132     geo->setTypes    (type); 
    133     geo->setLengths  (lens); 
    134     geo->setPositions(pnts); 
    135  
    136     // assign a material to the geometry to make it visible. The details 
    137     // of materials are defined later. 
    138     geo->setMaterial(getDefaultUnlitMaterial());    
    139      
    140     // put the geometry core into a node 
    141     NodePtr n = Node::create(); 
    142     n->setCore(geo); 
    143      
    144     // add a transformation to make it move      
    145     NodePtr scene = Node::create();   
    146     trans = Transform::create(); 
    147     scene->setCore(trans); 
    148     scene->addChild(n); 
    149  
    150     commitChanges(); 
    151  
    152     // create the SimpleSceneManager helper 
    153     mgr = new SimpleSceneManager; 
    154  
    155     // tell the manager what to manage 
    156     mgr->setWindow(gwin ); 
    157     mgr->setRoot  (scene); 
    158  
    159     // show the whole scene 
    160     mgr->showAll(); 
     50    // open a new scope, because the pointers below should go out of scope 
     51    // before entering glutMainLoop. 
     52    // Otherwise OpenSG will complain about objects being alive after shutdown. 
     53    { 
     54        // the connection between GLUT and OpenSG 
     55        GLUTWindowRefPtr gwin = GLUTWindow::create(); 
     56        gwin->setGlutId(winid); 
     57        gwin->init(); 
     58     
     59        // create the scene 
     60         
     61        /* 
     62            Geometry data in OpenSG is stored in several separate vectors. 
     63             
     64            These vectors are not a direct part of the Geometry Core but 
     65            rather split up into multiple separate classes. 
     66             
     67            These classes, the GeoProperties, contain a single field containg 
     68            their values, which can be accessed directly, see the docs for 
     69            GeoProperty for the whole interface. 
     70        */ 
     71         
     72        /* 
     73            The first part: the primtive types. 
     74            These are taken from OpenGL, any values that can be passed to 
     75            glBegin(); are legal. Different types can be freely mixed. 
     76        */ 
     77        GeoUInt8PropertyRefPtr type = GeoUInt8Property::create(); 
     78        type->addValue(GL_POLYGON  ); 
     79        type->addValue(GL_TRIANGLES); 
     80        type->addValue(GL_QUADS    ); 
     81         
     82        /* 
     83            The second part: the primtive lengths. 
     84            These define the number of vertices to be passed to OpenGL for each 
     85            primitive. Thus there have to be at least as many entries as in the 
     86            types property. 
     87        */ 
     88        GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create(); 
     89        lens->addValue(4); 
     90        lens->addValue(6); 
     91        lens->addValue(8); 
     92         
     93        /* 
     94            The third part: the vertex positions. 
     95             
     96            OpenSG uses different types for vectors and points. 
     97             
     98            Points (e.g. Pnt3f) are just positions in space, they have a limited 
     99            set of operations they can handle. Vectors (e.g. Vec3f) are the more 
     100            general kind. 
     101        */ 
     102        GeoPnt3fPropertyRefPtr  pnts = OSG::GeoPnt3fProperty::create(); 
     103        // the 4 points of the polygon 
     104        pnts->addValue(Pnt3f(-1, -1, -1)); 
     105        pnts->addValue(Pnt3f(-1, -1,  1)); 
     106        pnts->addValue(Pnt3f( 1, -1,  1)); 
     107        pnts->addValue(Pnt3f( 1, -1, -1)); 
     108     
     109        // the 6 points of the two triangles 
     110        pnts->addValue(Pnt3f( 1,  0, -1)); 
     111        pnts->addValue(Pnt3f(-1,  0, -1)); 
     112        pnts->addValue(Pnt3f( 0,  1, -1)); 
     113     
     114        pnts->addValue(Pnt3f(-1,  0,  1)); 
     115        pnts->addValue(Pnt3f( 1,  0,  1)); 
     116        pnts->addValue(Pnt3f( 0,  1,  1)); 
     117     
     118        // the 8 points of the two quads 
     119        pnts->addValue(Pnt3f(-1,  -1,  1));     
     120        pnts->addValue(Pnt3f( 1,  -1,  1));     
     121        pnts->addValue(Pnt3f( 1,   0,  1));     
     122        pnts->addValue(Pnt3f(-1,   0,  1));     
     123     
     124        pnts->addValue(Pnt3f( 1,  -1, -1));     
     125        pnts->addValue(Pnt3f(-1,  -1, -1));     
     126        pnts->addValue(Pnt3f(-1,   0, -1));     
     127        pnts->addValue(Pnt3f( 1,   0, -1));     
     128     
     129        /* 
     130        Put it all together into a Geometry NodeCore. 
     131        */ 
     132        geo = Geometry::create(); 
     133        geo->setTypes    (type); 
     134        geo->setLengths  (lens); 
     135        geo->setPositions(pnts); 
     136     
     137        // assign a material to the geometry to make it visible. The details 
     138        // of materials are defined later. 
     139        geo->setMaterial(getDefaultUnlitMaterial());    
     140         
     141        // put the geometry core into a node 
     142        NodeRefPtr n = Node::create(); 
     143        n->setCore(geo); 
     144         
     145        // add a transformation to make it move      
     146        NodeRefPtr scene = Node::create();   
     147        trans = Transform::create(); 
     148        scene->setCore(trans); 
     149        scene->addChild(n); 
     150     
     151        commitChanges(); 
     152     
     153        // create the SimpleSceneManager helper 
     154        mgr = new SimpleSceneManager; 
     155     
     156        // tell the manager what to manage 
     157        mgr->setWindow(gwin ); 
     158        mgr->setRoot  (scene); 
     159     
     160        // show the whole scene 
     161        mgr->showAll(); 
     162    } 
    161163 
    162164    // GLUT main loop 
     
    203205    // note that this is the abstract parent class, it doesn't have a specific 
    204206    // type 
    205     GeoVectorPropertyPtr pos = geo->getPositions(); 
     207    GeoVectorProperty *pos = geo->getPositions(); 
    206208     
    207209    for(UInt32 i = 0; i < pos->getSize(); i++) 
     
    210212        pos->getValue(p, i); 
    211213         
    212         p[0] += osgSin(t / 300) * p[1] / 100; 
    213         p[1] += osgSin(t / 300) * p[2] / 100; 
    214         p[2] += osgSin(t / 300) * p[0] / 100; 
     214        p[0] += osgSin(t / 3000) * p[0] / 100; 
     215        p[1] += osgSin(t / 3000) * p[1] / 100; 
     216        p[2] += osgSin(t / 3000) * p[2] / 100; 
    215217         
    216218        pos->setValue(p, i); 
     
    254256        case 27:     
    255257        { 
     258            // clean up global variables 
     259            geo   = NULL; 
     260            trans = NULL; 
     261            delete mgr; 
     262         
    256263            OSG::osgExit(); 
    257264            exit(0); 
  • trunk/Tutorials/06indexgeometry.cpp

    r835 r1339  
    2020 
    2121// The pointer to the transformation 
    22 TransformPtr trans; 
     22TransformRefPtr trans; 
    2323 
    2424// The SimpleSceneManager to manage simple applications 
     
    5555    int winid = setupGLUT(&argc, argv); 
    5656 
    57     // the connection between GLUT and OpenSG 
    58     GLUTWindowPtr gwin= GLUTWindow::create(); 
    59     gwin->setGlutId(winid); 
    60     gwin->init(); 
    61  
    62     // create the scene 
    63       
    64     /* 
    65         Some of the positions in the Geometry example were added to it  
    66         multiple times, when they were used by multiple primitives. 
    67          
    68         For large objects that's very inefficient memorywise, thus it is 
    69         possible to reuse the positions by using an index. 
    70     */ 
    71      
    72     /* 
    73         The initial setup is the same as in the geometry... 
    74     */ 
    75     GeoUInt8PropertyPtr type = GeoUInt8Property::create(); 
    76     type->addValue(GL_POLYGON  ); 
    77     type->addValue(GL_TRIANGLES); 
    78     type->addValue(GL_QUADS    ); 
    79  
    80     GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 
    81     lens->addValue(4); 
    82     lens->addValue(6); 
    83     lens->addValue(8); 
    84         
    85     /* 
    86         This time, only unique positions are stored. 
    87     */ 
    88     GeoPnt3fPropertyPtr pnts = GeoPnt3fProperty::create(); 
    89     // the base 
    90     pnts->addValue(Pnt3f(-1, -1, -1)); 
    91     pnts->addValue(Pnt3f(-1, -1,  1)); 
    92     pnts->addValue(Pnt3f( 1, -1,  1)); 
    93     pnts->addValue(Pnt3f( 1, -1, -1)); 
    94  
    95     // the roof base 
    96     pnts->addValue(Pnt3f(-1,  0, -1)); 
    97     pnts->addValue(Pnt3f(-1,  0,  1)); 
    98     pnts->addValue(Pnt3f( 1,  0,  1)); 
    99     pnts->addValue(Pnt3f( 1,  0, -1)); 
    100  
    101     // the gable 
    102     pnts->addValue(Pnt3f( 0,  1, -1)); 
    103     pnts->addValue(Pnt3f( 0,  1,  1)); 
    104     
    105     /* 
    106         The first new part: Colors. 
    107          
    108         In parallel to the Positions every vertex can also have a separate 
    109         color. 
    110          
    111         Colors also have their own types, they are neither Points nor Vectors. 
    112     */ 
    113     GeoVec3fPropertyPtr colors = GeoVec3fProperty::create(); 
    114     // the base 
    115     colors->addValue(Color3f(1, 1, 0)); 
    116     colors->addValue(Color3f(1, 0, 0)); 
    117     colors->addValue(Color3f(1, 0, 0)); 
    118     colors->addValue(Color3f(1, 1, 0)); 
    119  
    120     // the roof base 
    121     colors->addValue(Color3f(0, 1, 1)); 
    122     colors->addValue(Color3f(1, 0, 1)); 
    123     colors->addValue(Color3f(1, 0, 1)); 
    124     colors->addValue(Color3f(0, 1, 1)); 
    125  
    126     // the gable 
    127     colors->addValue(Color3f( 0,  1,  1)); 
    128     colors->addValue(Color3f( 1,  1,  0)); 
    129    
    130     /* 
    131         The second new part: Indices. 
    132          
    133         The Indices are positioned between the primitives and the positions 
    134         (and other attribute data like colors). So in this example the polygon 
    135         does not use the first 4 elements from the positions property, it used 
    136         the first 4 elements from the indices property, which define the 
    137         positions to be used. The same 4 indices are used to select the colors 
    138         for the vertices. 
    139     */ 
    140     GeoUInt32PropertyPtr indices = GeoUInt32Property::create(); 
    141     // indices for the polygon 
    142     indices->addValue(0); 
    143     indices->addValue(1); 
    144     indices->addValue(2); 
    145     indices->addValue(3); 
    146          
    147     // indices for the triangles 
    148     indices->addValue(7); 
    149     indices->addValue(4); 
    150     indices->addValue(8); 
    151  
    152     indices->addValue(5); 
    153     indices->addValue(6); 
    154     indices->addValue(9); 
    155          
    156     // indices for the quads 
    157     indices->addValue(1); 
    158     indices->addValue(2); 
    159     indices->addValue(6); 
    160     indices->addValue(5); 
    161  
    162     indices->addValue(3); 
    163     indices->addValue(0); 
    164     indices->addValue(4); 
    165     indices->addValue(7); 
    166      
    167     /* 
    168        Put it all together into a Geometry NodeCore. 
    169     */ 
    170     GeometryPtr geo=Geometry::create(); 
    171     geo->setTypes    (type); 
    172     geo->setLengths  (lens); 
    173     geo->setIndices  (indices); 
    174     geo->setPositions(pnts); 
    175     geo->setColors   (colors); 
    176     geo->setMaterial (getDefaultMaterial());    
    177      
    178     // put the geometry core into a node 
    179     NodePtr n = Node::create(); 
    180     n->setCore(geo); 
    181      
    182     // add a transformation to make it move      
    183     NodePtr scene = Node::create();   
    184     trans = Transform::create(); 
    185     scene->setCore(trans); 
    186     scene->addChild(n); 
    187  
    188     commitChanges(); 
    189  
    190     // create the SimpleSceneManager helper 
    191     mgr = new SimpleSceneManager; 
    192  
    193     // tell the manager what to manage 
    194     mgr->setWindow(gwin ); 
    195     mgr->setRoot  (scene); 
    196  
    197     // show the whole scene 
    198     mgr->showAll(); 
     57    // open a new scope, because the pointers below should go out of scope 
     58    // before entering glutMainLoop. 
     59    // Otherwise OpenSG will complain about objects being alive after shutdown. 
     60    { 
     61        // the connection between GLUT and OpenSG 
     62        GLUTWindowRefPtr gwin = GLUTWindow::create(); 
     63        gwin->setGlutId(winid); 
     64        gwin->init(); 
     65     
     66        // create the scene 
     67         
     68        /* 
     69            Some of the positions in the Geometry example were added to it  
     70            multiple times, when they were used by multiple primitives. 
     71             
     72            For large objects that's very inefficient memorywise, thus it is 
     73            possible to reuse the positions by using an index. 
     74        */ 
     75         
     76        /* 
     77            The initial setup is the same as in the geometry... 
     78        */ 
     79        GeoUInt8PropertyRefPtr type = GeoUInt8Property::create(); 
     80        type->addValue(GL_POLYGON  ); 
     81        type->addValue(GL_TRIANGLES); 
     82        type->addValue(GL_QUADS    ); 
     83     
     84        GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create(); 
     85        lens->addValue(4); 
     86        lens->addValue(6); 
     87        lens->addValue(8); 
     88         
     89        /* 
     90            This time, only unique positions are stored. 
     91        */ 
     92        GeoPnt3fPropertyRefPtr pnts = GeoPnt3fProperty::create(); 
     93        // the base 
     94        pnts->addValue(Pnt3f(-1, -1, -1)); 
     95        pnts->addValue(Pnt3f(-1, -1,  1)); 
     96        pnts->addValue(Pnt3f( 1, -1,  1)); 
     97        pnts->addValue(Pnt3f( 1, -1, -1)); 
     98     
     99        // the roof base 
     100        pnts->addValue(Pnt3f(-1,  0, -1)); 
     101        pnts->addValue(Pnt3f(-1,  0,  1)); 
     102        pnts->addValue(Pnt3f( 1,  0,  1)); 
     103        pnts->addValue(Pnt3f( 1,  0, -1)); 
     104     
     105        // the gable 
     106        pnts->addValue(Pnt3f( 0,  1, -1)); 
     107        pnts->addValue(Pnt3f( 0,  1,  1)); 
     108     
     109        /* 
     110            The first new part: Colors. 
     111             
     112            In parallel to the Positions every vertex can also have a separate 
     113            color. 
     114             
     115            Colors also have their own types, they are neither Points nor Vectors. 
     116        */ 
     117        GeoVec3fPropertyRefPtr colors = GeoVec3fProperty::create(); 
     118        // the base 
     119        colors->addValue(Color3f(1, 1, 0)); 
     120        colors->addValue(Color3f(1, 0, 0)); 
     121        colors->addValue(Color3f(1, 0, 0)); 
     122        colors->addValue(Color3f(1, 1, 0)); 
     123     
     124        // the roof base 
     125        colors->addValue(Color3f(0, 1, 1)); 
     126        colors->addValue(Color3f(1, 0, 1)); 
     127        colors->addValue(Color3f(1, 0, 1)); 
     128        colors->addValue(Color3f(0, 1, 1)); 
     129     
     130        // the gable 
     131        colors->addValue(Color3f( 0,  1,  1)); 
     132        colors->addValue(Color3f( 1,  1,  0)); 
     133     
     134        /* 
     135            The second new part: Indices. 
     136             
     137            The Indices are positioned between the primitives and the positions 
     138            (and other attribute data like colors). So in this example the polygon 
     139            does not use the first 4 elements from the positions property, it used 
     140            the first 4 elements from the indices property, which define the 
     141            positions to be used. The same 4 indices are used to select the colors 
     142            for the vertices. 
     143        */ 
     144        GeoUInt32PropertyRefPtr indices = GeoUInt32Property::create(); 
     145        // indices for the polygon 
     146        indices->addValue(0); 
     147        indices->addValue(1); 
     148        indices->addValue(2); 
     149        indices->addValue(3); 
     150             
     151        // indices for the triangles 
     152        indices->addValue(7); 
     153        indices->addValue(4); 
     154        indices->addValue(8); 
     155     
     156        indices->addValue(5); 
     157        indices->addValue(6); 
     158        indices->addValue(9); 
     159             
     160        // indices for the quads 
     161        indices->addValue(1); 
     162        indices->addValue(2); 
     163        indices->addValue(6); 
     164        indices->addValue(5); 
     165     
     166        indices->addValue(3); 
     167        indices->addValue(0); 
     168        indices->addValue(4); 
     169        indices->addValue(7); 
     170         
     171        /* 
     172        Put it all together into a Geometry NodeCore. 
     173        */ 
     174        GeometryRefPtr geo = Geometry::create(); 
     175        geo-