Changeset 8247

Show
Ignore:
Timestamp:
04/28/08 00:51:55
Author:
robert
Message:

Set up geometry exercises

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/04_geometry/4a_Geometry/4a_Geometry.cpp

    r8049 r8247  
    3838#include <iostream> 
    3939 
    40 // This demos uses the illustrates how to creates the various different types of geometry that 
    41 // the osg::Geometry class can represent.  This demos uses the OpenGL red books diagram of different  
    42 // OpenGL Primitives as a template for all the equivalent OpenSceneGraph Primitives.  The OpenSceneGraph  
    43 // wraps OpenGL very thinly so uses all the same enum and naming conventions. The coordinate data is also  
    44 // wrapped around OpenGL's vertex arrays and draw arrays/elements calls.  Familiarity with 
    45 // OpenGL will help understand the the osg::Geometry class which encapsulate all this, or if you 
    46 // havn't learned OpenGL yet, learning osg::Geometry will help you understand how OpenGL 
    47 // works! 
     40osg::Node* createScene() 
     41
     42    osg::Geode* geode = new osg::Geode; 
     43     
     44    { 
     45        // create cube geometry 
     46        // with per vertex colours and normals 
     47    } 
    4848 
    49 // The osg::Geometry class "is a" subclass of osg::Drawable base class, so is an object that provides 
    50 // a draw method for drawing objects in the scene.  osg::Geometry contains all the vertex, normal 
    51 // color and texture coordinate arrays required to specify the coordinates of your objects, and the 
    52 // primitives join these coordinates together as the points, lines or surfaces that you will see 
    53 // rendered on your screen.  
    54 // 
    55 // This demo is split into two functions, the createScene() function which creates the scene graph 
    56 // with the various primitives in it, and the main() which sets up a basic viewer window and 
    57 // adds to the it the scene generated by createScene(). 
    58  
    59  
    60 struct NormalPrint 
    61 
    62     void operator() (const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec3& v3, bool) const  
    63     { 
    64         osg::Vec3 normal = (v2-v1)^(v3-v2); 
    65         normal.normalize(); 
    66         std::cout << "\t("<<v1<<") ("<<v2<<") ("<<v3<<") "<<") normal ("<<normal<<")"<<std::endl; 
    67     } 
    68 }; 
    69  
    70 // decompose Drawable primitives into triangles, print out these triangles and computed normals. 
    71 void printTriangles(const std::string& name, osg::Drawable& drawable) 
    72 
    73     std::cout<<name<<std::endl; 
    74      
    75     osg::TriangleFunctor<NormalPrint> tf; 
    76     drawable.accept(tf); 
    77   
    78     std::cout<<std::endl; 
     49    return geode; 
    7950} 
    8051 
    8152 
    82 osg::Node* createScene() 
    83 { 
    84     // create the Geode (Geometry Node) to contain all our osg::Geometry objects. 
    85     osg::Geode* geode = new osg::Geode(); 
    86  
    87     // follows are separate blocks for creating POINTS, LINES, LINE_STRIP, LINE_LOOP, POLYGON, QUADS, 
    88     // QUAD_STRIP, TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN primitives.  A image of these primitives 
    89     // are provided in the distribution : OpenSceneGraph-Data/Images/primitives.gif. 
    90  
    91  
    92     // create POINTS 
    93     { 
    94         // create Geometry object to store all the vertices and points primitive. 
    95         osg::Geometry* pointsGeom = new osg::Geometry(); 
    96          
    97         // create a Vec3Array and add to it all my coordinates. 
    98         // Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg::Array  
    99         // and std::vector<>.  osg::Array's are reference counted and hence sharable, 
    100         // which std::vector<> provides all the convenience, flexibility and robustness 
    101         // of the most popular of all STL containers. 
    102         osg::Vec3Array* vertices = new osg::Vec3Array; 
    103         vertices->push_back(osg::Vec3(-1.02168, -2.15188e-09, 0.885735)); 
    104         vertices->push_back(osg::Vec3(-0.976368, -2.15188e-09, 0.832179)); 
    105         vertices->push_back(osg::Vec3(-0.873376, 9.18133e-09, 0.832179)); 
    106         vertices->push_back(osg::Vec3(-0.836299, -2.15188e-09, 0.885735)); 
    107         vertices->push_back(osg::Vec3(-0.790982, 9.18133e-09, 0.959889)); 
    108          
    109         // pass the created vertex array to the points geometry object. 
    110         pointsGeom->setVertexArray(vertices); 
    111          
    112          
    113          
    114         // create the color of the geometry, one single for the whole geometry. 
    115         // for consistency of design even one single color must added as an element 
    116         // in a color array. 
    117         osg::Vec4Array* colors = new osg::Vec4Array; 
    118         // add a white color, colors take the form r,g,b,a with 0.0 off, 1.0 full on. 
    119         colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
    120          
    121         // pass the color array to points geometry, note the binding to tell the geometry 
    122         // that only use one color for the whole object. 
    123         pointsGeom->setColorArray(colors); 
    124         pointsGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    125          
    126          
    127         // set the normal in the same way color. 
    128         osg::Vec3Array* normals = new osg::Vec3Array; 
    129         normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    130         pointsGeom->setNormalArray(normals); 
    131         pointsGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    132  
    133  
    134         // create and add a DrawArray Primitive (see include/osg/Primitive).  The first 
    135         // parameter passed to the DrawArrays constructor is the Primitive::Mode which 
    136         // in this case is POINTS (which has the same value GL_POINTS), the second 
    137         // parameter is the index position into the vertex array of the first point 
    138         // to draw, and the third parameter is the number of points to draw. 
    139         pointsGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,vertices->size())); 
    140          
    141          
    142         // add the points geometry to the geode. 
    143         geode->addDrawable(pointsGeom); 
    144     } 
    145  
    146     // create LINES 
    147     { 
    148         // create Geometry object to store all the vertices and lines primitive. 
    149         osg::Geometry* linesGeom = new osg::Geometry(); 
    150          
    151         // this time we'll preallocate the vertex array to the size we 
    152         // need and then simple set them as array elements, 8 points 
    153         // makes 4 line segments. 
    154         osg::Vec3Array* vertices = new osg::Vec3Array(8); 
    155         (*vertices)[0].set(-1.13704, -2.15188e-09, 0.40373); 
    156         (*vertices)[1].set(-0.856897, -2.15188e-09, 0.531441); 
    157         (*vertices)[2].set(-0.889855, -2.15188e-09, 0.444927); 
    158         (*vertices)[3].set(-0.568518, -2.15188e-09, 0.40373); 
    159         (*vertices)[4].set(-1.00933, -2.15188e-09, 0.370773); 
    160         (*vertices)[5].set(-0.716827, -2.15188e-09, 0.292498); 
    161         (*vertices)[6].set(-1.07936, 9.18133e-09, 0.317217); 
    162         (*vertices)[7].set(-0.700348, 9.18133e-09, 0.362533); 
    163  
    164          
    165         // pass the created vertex array to the points geometry object. 
    166         linesGeom->setVertexArray(vertices); 
    167          
    168         // set the colors as before, plus using the above 
    169         osg::Vec4Array* colors = new osg::Vec4Array; 
    170         colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
    171         linesGeom->setColorArray(colors); 
    172         linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    173          
    174  
    175         // set the normal in the same way color. 
    176         osg::Vec3Array* normals = new osg::Vec3Array; 
    177         normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    178         linesGeom->setNormalArray(normals); 
    179         linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    180  
    181  
    182         // This time we simply use primitive, and hardwire the number of coords to use  
    183         // since we know up front, 
    184         linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8)); 
    185          
    186          
    187         // add the points geometry to the geode. 
    188         geode->addDrawable(linesGeom); 
    189     } 
    190      
    191     // create LINE_STRIP 
    192     { 
    193         // create Geometry object to store all the vertices and lines primitive. 
    194         osg::Geometry* linesGeom = new osg::Geometry(); 
    195          
    196         // this time we'll preallocate the vertex array to the size  
    197         // and then use an iterator to fill in the values, a bit perverse 
    198         // but does demonstrate that we have just a standard std::vector underneath. 
    199         osg::Vec3Array* vertices = new osg::Vec3Array(5); 
    200         osg::Vec3Array::iterator vitr = vertices->begin(); 
    201         (vitr++)->set(-0.0741545, -2.15188e-09, 0.416089); 
    202         (vitr++)->set(0.234823, -2.15188e-09, 0.259541); 
    203         (vitr++)->set(0.164788, -2.15188e-09, 0.366653); 
    204         (vitr++)->set(-0.0288379, -2.15188e-09, 0.333695); 
    205         (vitr++)->set(-0.0453167, -2.15188e-09, 0.280139); 
    206         
    207         // pass the created vertex array to the points geometry object. 
    208         linesGeom->setVertexArray(vertices); 
    209          
    210         // set the colors as before, plus using the above 
    211         osg::Vec4Array* colors = new osg::Vec4Array; 
    212         colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
    213         linesGeom->setColorArray(colors); 
    214         linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    215  
    216  
    217         // set the normal in the same way color. 
    218         osg::Vec3Array* normals = new osg::Vec3Array; 
    219         normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    220         linesGeom->setNormalArray(normals); 
    221         linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    222  
    223  
    224         // This time we simply use primitive, and hardwire the number of coords to use  
    225         // since we know up front, 
    226         linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,5)); 
    227          
    228          
    229         // add the points geometry to the geode. 
    230         geode->addDrawable(linesGeom); 
    231     } 
    232  
    233     // create LINE_LOOP 
    234     { 
    235         // create Geometry object to store all the vertices and lines primitive. 
    236         osg::Geometry* linesGeom = new osg::Geometry(); 
    237          
    238         // this time we'll a C arrays to initialize the vertices. 
    239          
    240         osg::Vec3 myCoords[] = 
    241         { 
    242             osg::Vec3(0.741546, -2.15188e-09, 0.453167), 
    243             osg::Vec3(0.840418, -2.15188e-09, 0.304858), 
    244             osg::Vec3(1.12468, -2.15188e-09, 0.300738), 
    245             osg::Vec3(1.03816, 9.18133e-09, 0.453167), 
    246             osg::Vec3(0.968129, -2.15188e-09, 0.337815), 
    247             osg::Vec3(0.869256, -2.15188e-09, 0.531441) 
    248         }; 
    249          
    250         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    251          
    252         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); 
    253         
    254         // pass the created vertex array to the points geometry object. 
    255         linesGeom->setVertexArray(vertices); 
    256          
    257         // set the colors as before, plus using the above 
    258         osg::Vec4Array* colors = new osg::Vec4Array; 
    259         colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
    260         linesGeom->setColorArray(colors); 
    261         linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    262          
    263  
    264         // set the normal in the same way color. 
    265         osg::Vec3Array* normals = new osg::Vec3Array; 
    266         normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    267         linesGeom->setNormalArray(normals); 
    268         linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    269          
    270  
    271         // This time we simply use primitive, and hardwire the number of coords to use  
    272         // since we know up front, 
    273         linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,numCoords)); 
    274          
    275          
    276         // add the points geometry to the geode. 
    277         geode->addDrawable(linesGeom); 
    278     } 
    279  
    280  
    281  
    282  
    283     // now we'll stop creating separate normal and color arrays 
    284     // since we are using the same values all the time, we'll just 
    285     // share the same ColorArray and NormalArrays.. 
    286  
    287     // set the colors as before, use a ref_ptr rather than just 
    288     // standard C pointer, as that in the case of it not being 
    289     // assigned it will still be cleaned up automatically. 
    290     osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array; 
    291     shared_colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
    292  
    293     // same trick for shared normal. 
    294     osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array; 
    295     shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    296  
    297  
    298  
    299     // Note on vertex ordering. 
    300     // While the OpenGL diagram should vertices specified in a clockwise direction 
    301     // in reality you need to specify coords for polygons into a anticlockwise direction 
    302     // for their front face to be pointing towards your, get this wrong and you could 
    303     // find back face culling removing the wrong faces of your models.  The OpenGL diagram  
    304     // is just plain wrong, but its nice diagram so we'll keep it for now! 
    305  
    306     // create POLYGON 
    307     { 
    308         // create Geometry object to store all the vertices and lines primitive. 
    309         osg::Geometry* polyGeom = new osg::Geometry(); 
    310          
    311         // this time we'll a C arrays to initialize the vertices. 
    312         // note, anticlockwise ordering. 
    313         // note II, OpenGL polygons must be convex plan polygons, otherwise  
    314         // undefined results will occur.  If you have concave polygons or ones 
    315         // that cross over themselves then use the osgUtil::Tessellator to fix 
    316         // the polygons into a set of valid polygons. 
    317         osg::Vec3 myCoords[] = 
    318         { 
    319             osg::Vec3(-1.0464, 0.0f, -0.193626), 
    320             osg::Vec3(-1.0258, 0.0f, -0.26778), 
    321             osg::Vec3(-0.807461, 0.0f, -0.181267), 
    322             osg::Vec3(-0.766264, 0.0f, -0.0576758), 
    323             osg::Vec3(-0.980488, 0.0f, -0.094753) 
    324         }; 
    325          
    326         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    327          
    328         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); 
    329         
    330         // pass the created vertex array to the points geometry object. 
    331         polyGeom->setVertexArray(vertices); 
    332          
    333         // use the shared color array. 
    334         polyGeom->setColorArray(shared_colors.get()); 
    335         polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    336          
    337  
    338         // use the shared normal array. 
    339         polyGeom->setNormalArray(shared_normals.get()); 
    340         polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    341          
    342  
    343         // This time we simply use primitive, and hardwire the number of coords to use  
    344         // since we know up front, 
    345         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords)); 
    346  
    347         printTriangles("Polygon",*polyGeom); 
    348          
    349         // add the points geometry to the geode. 
    350         geode->addDrawable(polyGeom); 
    351     } 
    352  
    353  
    354     // create QUADS 
    355     { 
    356         // create Geometry object to store all the vertices and lines primitive. 
    357         osg::Geometry* polyGeom = new osg::Geometry(); 
    358          
    359         // note, anticlockwise ordering. 
    360         osg::Vec3 myCoords[] = 
    361         { 
    362             osg::Vec3(0.0247182, 0.0f, -0.156548), 
    363             osg::Vec3(0.0247182, 0.0f, -0.00823939), 
    364             osg::Vec3(-0.160668, 0.0f, -0.0453167), 
    365             osg::Vec3(-0.222464, 0.0f, -0.13183), 
    366  
    367             osg::Vec3(0.238942, 0.0f, -0.251302), 
    368             osg::Vec3(0.333696, 0.0f, 0.0329576), 
    369             osg::Vec3(0.164788, 0.0f, -0.0453167), 
    370             osg::Vec3(0.13595,  0.0f, -0.255421) 
    371         }; 
    372          
    373         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    374          
    375         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); 
    376         
    377         // pass the created vertex array to the points geometry object. 
    378         polyGeom->setVertexArray(vertices); 
    379          
    380         // use the shared color array. 
    381         polyGeom->setColorArray(shared_colors.get()); 
    382         polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    383          
    384  
    385         // use the shared normal array. 
    386         polyGeom->setNormalArray(shared_normals.get()); 
    387         polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    388          
    389  
    390         // This time we simply use primitive, and hardwire the number of coords to use  
    391         // since we know up front, 
    392         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords)); 
    393          
    394          
    395         printTriangles("Quads",*polyGeom); 
    396  
    397         // add the points geometry to the geode. 
    398         geode->addDrawable(polyGeom); 
    399     } 
    400  
    401     // create QUAD_STRIP 
    402     { 
    403         // create Geometry object to store all the vertices and lines primitive. 
    404         osg::Geometry* polyGeom = new osg::Geometry(); 
    405          
    406         // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. 
    407         osg::Vec3 myCoords[] = 
    408         { 
    409             osg::Vec3(0.733306, -2.15188e-09, -0.0741545), 
    410             osg::Vec3(0.758024, -2.15188e-09, -0.205985), 
    411  
    412             osg::Vec3(0.885735, -2.15188e-09, -0.0576757), 
    413             osg::Vec3(0.885735, -2.15188e-09, -0.214224), 
    414  
    415             osg::Vec3(0.964009, 9.18133e-09, -0.0370773), 
    416             osg::Vec3(1.0464, 9.18133e-09, -0.173027), 
    417  
    418             osg::Vec3(1.11232, -2.15188e-09, 0.0123591), 
    419             osg::Vec3(1.12468, 9.18133e-09, -0.164788), 
    420         }; 
    421          
    422         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    423          
    424         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); 
    425         
    426         // pass the created vertex array to the points geometry object. 
    427         polyGeom->setVertexArray(vertices); 
    428          
    429         // use the shared color array. 
    430         polyGeom->setColorArray(shared_colors.get()); 
    431         polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    432          
    433  
    434         // use the shared normal array. 
    435         polyGeom->setNormalArray(shared_normals.get()); 
    436         polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    437          
    438  
    439         // This time we simply use primitive, and hardwire the number of coords to use  
    440         // since we know up front, 
    441         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,numCoords)); 
    442          
    443          
    444         printTriangles("Quads strip",*polyGeom); 
    445  
    446         // add the points geometry to the geode. 
    447         geode->addDrawable(polyGeom); 
    448     } 
    449  
    450     // create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/ 
    451     { 
    452         // create Geometry object to store all the vertices and lines primitive. 
    453         osg::Geometry* polyGeom = new osg::Geometry(); 
    454          
    455         // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. 
    456         osg::Vec3 myCoords[] = 
    457         { 
    458             // TRIANGLES 6 vertices, v0..v5 
    459             // note in anticlockwise order. 
    460             osg::Vec3(-1.12056, -2.15188e-09, -0.840418), 
    461             osg::Vec3(-0.95165, -2.15188e-09, -0.840418), 
    462             osg::Vec3(-1.11644, 9.18133e-09, -0.716827), 
    463  
    464             // note in anticlockwise order. 
    465             osg::Vec3(-0.840418, 9.18133e-09, -0.778623), 
    466             osg::Vec3(-0.622074, 9.18133e-09, -0.613835), 
    467             osg::Vec3(-1.067, 9.18133e-09, -0.609715), 
    468  
    469             // TRIANGLE STRIP 6 vertices, v6..v11 
    470             // note defined top point first,  
    471             // then anticlockwise for the next two points, 
    472             // then alternating to bottom there after. 
    473             osg::Vec3(-0.160668, -2.15188e-09, -0.531441), 
    474             osg::Vec3(-0.160668, -2.15188e-09, -0.749785), 
    475             osg::Vec3(0.0617955, 9.18133e-09, -0.531441), 
    476             osg::Vec3(0.168908, -2.15188e-09, -0.753905), 
    477             osg::Vec3(0.238942, -2.15188e-09, -0.531441), 
    478             osg::Vec3(0.280139, -2.15188e-09, -0.823939), 
    479  
    480             // TRIANGLE FAN 5 vertices, v12..v16 
    481             // note defined in anticlockwise order. 
    482             osg::Vec3(0.844538, 9.18133e-09, -0.712708), 
    483             osg::Vec3(1.0258, 9.18133e-09, -0.799221), 
    484             osg::Vec3(1.03816, -2.15188e-09, -0.692109), 
    485             osg::Vec3(0.988727, 9.18133e-09, -0.568518), 
    486             osg::Vec3(0.840418, -2.15188e-09, -0.506723), 
    487  
    488         }; 
    489          
    490         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    491          
    492         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); 
    493         
    494         // pass the created vertex array to the points geometry object. 
    495         polyGeom->setVertexArray(vertices); 
    496          
    497         // use the shared color array. 
    498         polyGeom->setColorArray(shared_colors.get()); 
    499         polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    500          
    501  
    502         // use the shared normal array. 
    503         polyGeom->setNormalArray(shared_normals.get()); 
    504         polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    505          
    506  
    507         // This time we simply use primitive, and hardwire the number of coords to use  
    508         // since we know up front, 
    509         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6)); 
    510         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,6,6)); 
    511         polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,12,5)); 
    512          
    513         // polygon stipple 
    514         osg::StateSet* stateSet = new osg::StateSet(); 
    515         polyGeom->setStateSet(stateSet); 
    516         osg::PolygonStipple* polygonStipple = new osg::PolygonStipple; 
    517         stateSet->setAttributeAndModes(polygonStipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); 
    518          
    519         printTriangles("Triangles/Strip/Fan",*polyGeom); 
    520  
    521         // add the points geometry to the geode. 
    522         geode->addDrawable(polyGeom); 
    523     } 
    524      
    525     return geode;    
    526 } 
    527  
    528  
    529 // define a node callback to animation a transform as a cycle along the y axis, between 0 and 2.0. 
    530 class MyTransformCallback : public osg::NodeCallback 
    531 { 
    532  
    533     public: 
    534  
    535         MyTransformCallback(float angularVelocity) 
    536         { 
    537             _angular_velocity = angularVelocity; 
    538         } 
    539  
    540         virtual void operator() (osg::Node* node, osg::NodeVisitor* nv) 
    541         { 
    542             osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node);                 
    543             if (nv && transform && nv->getFrameStamp()) 
    544             { 
    545                 double time = nv->getFrameStamp()->getSimulationTime(); 
    546                 transform->setMatrix(osg::Matrix::translate(0.0f,1.0f+cosf(time*_angular_velocity),0.0f)); 
    547             } 
    548              
    549             // must continue subgraph traversal. 
    550             traverse(node,nv);             
    551              
    552         } 
    553          
    554     protected: 
    555      
    556         float               _angular_velocity; 
    557  
    558 }; 
    559  
    560  
    561 osg::Node* createBackground() 
    562 {     
    563  
    564     // we'll create a texture mapped quad to sit behind the Geometry  
    565     osg::Image* image = osgDB::readImageFile("Images/primitives.gif"); 
    566     if (!image) return NULL; 
    567      
    568   
    569     // create Geometry object to store all the vertices and lines primitive. 
    570     osg::Geometry* polyGeom = new osg::Geometry(); 
    571  
    572     // note, anticlockwise ordering. 
    573     osg::Vec3 myCoords[] = 
    574     { 
    575         osg::Vec3(-1.22908f,0.0f,1.0f), 
    576         osg::Vec3(-1.22908f,0.0f,-1.0f), 
    577         osg::Vec3(1.22908f,0.0f,-1.0f), 
    578         osg::Vec3(1.22908f,0.0f,1.0f) 
    579     }; 
    580  
    581     int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); 
    582  
    583     // pass the created vertex array to the points geometry object. 
    584     polyGeom->setVertexArray(new osg::Vec3Array(numCoords,myCoords)); 
    585  
    586     osg::Vec4Array* colors = new osg::Vec4Array; 
    587     colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 
    588     polyGeom->setColorArray(colors); 
    589     polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    590  
    591  
    592     // set the normal in the same way color. 
    593     osg::Vec3Array* normals = new osg::Vec3Array; 
    594     normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); 
    595     polyGeom->setNormalArray(normals); 
    596     polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); 
    597  
    598     osg::Vec2 myTexCoords[] = 
    599     { 
    600         osg::Vec2(0,1), 
    601         osg::Vec2(0,0), 
    602         osg::Vec2(1,0), 
    603         osg::Vec2(1,1) 
    604     }; 
    605  
    606     int numTexCoords = sizeof(myTexCoords)/sizeof(osg::Vec2); 
    607  
    608     // pass the created tex coord array to the points geometry object, 
    609     // and use it to set texture unit 0. 
    610     polyGeom->setTexCoordArray(0,new osg::Vec2Array(numTexCoords,myTexCoords)); 
    611  
    612     // well use indices and DrawElements to define the primitive this time. 
    613     unsigned short myIndices[] = 
    614     { 
    615         0, 
    616         1, 
    617         2, 
    618         3 
    619     }; 
    620  
    621     int numIndices = sizeof(myIndices)/sizeof(unsigned short); 
    622  
    623     // There are three variants of the DrawElements osg::Primitive, UByteDrawElements which 
    624     // contains unsigned char indices, UShortDrawElements which contains unsigned short indices, 
    625     // and UIntDrawElements which contains ... unsigned int indices.   
    626     // The first parameter to DrawElements is  
    627     polyGeom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::QUADS,numIndices,myIndices)); 
    628  
    629     // new we need to add the texture to the Drawable, we do so by creating a  
    630     // StateSet to contain the Texture2D StateAttribute. 
    631     osg::StateSet* stateset = new osg::StateSet; 
    632  
    633     // set up the texture. 
    634     osg::Texture2D* texture = new osg::Texture2D; 
    635     texture->setImage(image); 
    636  
    637     stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); 
    638  
    639     polyGeom->setStateSet(stateset); 
    640  
    641   
    642     // create the Geode (Geometry Node) to contain all our osg::Geometry objects. 
    643     osg::Geode* geode = new osg::Geode(); 
    644  
    645     // add the points geometry to the geode. 
    646     geode->addDrawable(polyGeom); 
    647  
    648     //return geode; 
    649  
    650     // create a transform to move the background back and forward with. 
    651   
    652     osg::MatrixTransform* transform = new osg::MatrixTransform(); 
    653     transform->setUpdateCallback(new MyTransformCallback(1.0f)); 
    654     transform->addChild(geode); 
    655  
    656     return transform; 
    657 } 
    658  
    65953int main(int, char **) 
    66054{ 
    661     // create the model 
    662     osg::Group* root = new osg::Group; 
    663     root->addChild( createScene() ); 
    664     root->addChild( createBackground() ); 
    665  
    666     //osgDB::writeNodeFile(*root,"geoemtry.osg"); 
    667  
    66855    osgViewer::Viewer viewer; 
    66956 
    67057    // add model to viewer. 
    671     viewer.setSceneData( root ); 
     58    viewer.setSceneData( createScene() ); 
    67259 
    67360    return viewer.run(); 
  • OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/04_geometry/4b_ShapeDrawable/4b_ShapeDrawable.cpp

    r8049 r8247  
    3232    osg::Geode* geode = new osg::Geode(); 
    3333 
    34     // --------------------------------------- 
    35     // Set up a StateSet to texture the objects 
    36     // --------------------------------------- 
    37     osg::StateSet* stateset = new osg::StateSet(); 
     34    { 
     35        // add a sphere, center 0,0,0, radius 1 
     36    } 
    3837 
    39     osg::Image* image = osgDB::readImageFile( "Images/lz.rgb" ); 
     38    { 
     39        // add a box, center 3,0,0, sides 1 
     40    } 
    4041 
    41     if (image) 
    4242    { 
    43         osg::Texture2D* texture = new osg::Texture2D; 
    44         texture->setImage(image); 
    45         stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 
     43        // add a cone, center 6,0,0, base radius 1, height 2 
    4644    } 
    47      
    48     geode->setStateSet( stateset ); 
    49      
    50     float radius = 0.8f; 
    51     float height = 1.0f; 
    52      
    53     osg::TessellationHints* hints = new osg::TessellationHints; 
    54     hints->setDetailRatio(0.5f); 
    55      
    56     geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius),hints)); 
    57     geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(2.0f,0.0f,0.0f),2*radius),hints)); 
    58     geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),radius,height),hints)); 
    59     geode->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(6.0f,0.0f,0.0f),radius,height),hints)); 
    60     geode->addDrawable(new osg::ShapeDrawable(new osg::Capsule(osg::Vec3(8.0f,0.0f,0.0f),radius,height),hints)); 
    61      
    62     osg::ConvexHull* mesh = new osg::ConvexHull; 
    63     osg::Vec3Array* vertices = new osg::Vec3Array(4); 
    64     (*vertices)[0].set(9.0+0.0f,-1.0f+2.0f,-1.0f+0.0f); 
    65     (*vertices)[1].set(9.0+1.0f,-1.0f+0.0f,-1.0f+0.0f); 
    66     (*vertices)[2].set(9.0+2.0f,-1.0f+2.0f,-1.0f+0.0f); 
    67     (*vertices)[3].set(9.0+1.0f,-1.0f+1.0f,-1.0f+2.0f); 
    68     osg::UByteArray* indices = new osg::UByteArray(12); 
    69     (*indices)[0]=0; 
    70     (*indices)[1]=2; 
    71     (*indices)[2]=1; 
    72     (*indices)[3]=0; 
    73     (*indices)[4]=1; 
    74     (*indices)[5]=3; 
    75     (*indices)[6]=1; 
    76     (*indices)[7]=2; 
    77     (*indices)[8]=3; 
    78     (*indices)[9]=2; 
    79     (*indices)[10]=0; 
    80     (*indices)[11]=3; 
    81     mesh->setVertices(vertices); 
    82     mesh->setIndices(indices); 
    83     geode->addDrawable(new osg::ShapeDrawable(mesh)); 
    84      
     45 
    8546    return geode; 
    8647} 
  • OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/04_geometry/4c_CustomDrawable/4c_CustomDrawable.cpp

    r8049 r8247  
    2525#include <osgViewer/Viewer> 
    2626 
     27#include <iostream> 
    2728 
    28 // The classic OpenGL teapot... taken form glut-3.7/lib/glut/glut_teapot.c 
    29  
    30 /* Copyright (c) Mark J. Kilgard, 1994. */ 
    31  
    32 /** 
    33 (c) Copyright 1993, Silicon Graphics, Inc. 
    34  
    35 ALL RIGHTS RESERVED 
    36  
    37 Permission to use, copy, modify, and distribute this software 
    38 for any purpose and without fee is hereby granted, provided 
    39 that the above copyright notice appear in all copies and that 
    40 both the copyright notice and this permission notice appear in 
    41 supporting documentation, and that the name of Silicon 
    42 Graphics, Inc. not be used in advertising or publicity 
    43 pertaining to distribution of the software without specific, 
    44 written prior permission. 
    45  
    46 THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU 
    47 "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR 
    48 OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF 
    49 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  IN NO 
    50 EVENT SHALL SILICON GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE 
    51 ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR 
    52 CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, 
    53 INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, 
    54 SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR 
    55 NOT SILICON GRAPHICS, INC.  HAS BEEN ADVISED OF THE POSSIBILITY 
    56 OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
    57 ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR 
    58 PERFORMANCE OF THIS SOFTWARE. 
    59  
    60 US Government Users Restricted Rights 
    61  
    62 Use, duplication, or disclosure by the Government is subject to 
    63 restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 
    64 (c)(1)(ii) of the Rights in Technical Data and Computer 
    65 Software clause at DFARS 252.227-7013 and/or in similar or 
    66 successor clauses in the FAR or the DOD or NASA FAR 
    67 Supplement.  Unpublished-- rights reserved under the copyright 
    68 laws of the United States.  Contractor/manufacturer is Silicon 
    69 Graphics, Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 
    70 94039-7311. 
    71  
    72 OpenGL(TM) is a trademark of Silicon Graphics, Inc. 
    73 */ 
     29namespace MyNameSpace 
     30
    7431 
    7532 
    76 /* Rim, body, lid, and bottom data must be reflected in x and 
    77    y; handle and spout data across the y axis only.  */ 
    78  
    79 static int patchdata[][16] = 
    80 
    81     /* rim */ 
    82   {102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 
    83     12, 13, 14, 15}, 
    84     /* body */ 
    85   {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 
    86     24, 25, 26, 27}, 
    87   {24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 
    88     37, 38, 39, 40}, 
    89     /* lid */ 
    90   {96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 
    91     101, 0, 1, 2, 3,}, 
    92   {0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 
    93     113, 114, 115, 116, 117}, 
    94     /* bottom */ 
    95   {118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 
    96     125, 120, 40, 39, 38, 37}, 
    97     /* handle */ 
    98   {41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 
    99     53, 54, 55, 56}, 
    100   {53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 
    101     28, 65, 66, 67}, 
    102     /* spout */ 
    103   {68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 
    104     80, 81, 82, 83}, 
    105   {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 
    106     92, 93, 94, 95} 
    107 }; 
    108 /* *INDENT-OFF* */ 
    109  
    110 static float cpdata[][3] = 
    111 
    112     {0.2, 0, 2.7}, {0.2, -0.112, 2.7}, {0.112, -0.2, 2.7}, {0, 
    113     -0.2, 2.7}, {1.3375, 0, 2.53125}, {1.3375, -0.749, 2.53125}, 
    114     {0.749, -1.3375, 2.53125}, {0, -1.3375, 2.53125}, {1.4375, 
    115     0, 2.53125}, {1.4375, -0.805, 2.53125}, {0.805, -1.4375, 
    116     2.53125}, {0, -1.4375, 2.53125}, {1.5, 0, 2.4}, {1.5, -0.84, 
    117     2.4}, {0.84, -1.5, 2.4}, {0, -1.5, 2.4}, {1.75, 0, 1.875}, 
    118     {1.75, -0.98, 1.875}, {0.98, -1.75, 1.875}, {0, -1.75, 
    119     1.875}, {2, 0, 1.35}, {2, -1.12, 1.35}, {1.12, -2, 1.35}, 
    120     {0, -2, 1.35}, {2, 0, 0.9}, {2, -1.12, 0.9}, {1.12, -2, 
    121     0.9}, {0, -2, 0.9}, {-2, 0, 0.9}, {2, 0, 0.45}, {2, -1.12, 
    122     0.45}, {1.12, -2, 0.45}, {0, -2, 0.45}, {1.5, 0, 0.225}, 
    123     {1.5, -0.84, 0.225}, {0.84, -1.5, 0.225}, {0, -1.5, 0.225}, 
    124     {1.5, 0, 0.15}, {1.5, -0.84, 0.15}, {0.84, -1.5, 0.15}, {0, 
    125     -1.5, 0.15}, {-1.6, 0, 2.025}, {-1.6, -0.3, 2.025}, {-1.5, 
    126     -0.3, 2.25}, {-1.5, 0, 2.25}, {-2.3, 0, 2.025}, {-2.3, -0.3, 
    127     2.025}, {-2.5, -0.3, 2.25}, {-2.5, 0, 2.25}, {-2.7, 0, 
    128     2.025}, {-2.7, -0.3, 2.025}, {-3, -0.3, 2.25}, {-3, 0, 
    129     2.25}, {-2.7, 0, 1.8}, {-2.7, -0.3, 1.8}, {-3, -0.3, 1.8}, 
    130     {-3, 0, 1.8}, {-2.7, 0, 1.575}, {-2.7, -0.3, 1.575}, {-3, 
    131     -0.3, 1.35}, {-3, 0, 1.35}, {-2.5, 0, 1.125}, {-2.5, -0.3, 
    132     1.125}, {-2.65, -0.3, 0.9375}, {-2.65, 0, 0.9375}, {-2, 
    133     -0.3, 0.9}, {-1.9, -0.3, 0.6}, {-1.9, 0, 0.6}, {1.7, 0, 
    134     1.425}, {1.7, -0.66, 1.425}, {1.7, -0.66, 0.6}, {1.7, 0, 
    135     0.6}, {2.6, 0, 1.425}, {2.6, -0.66, 1.425}, {3.1, -0.66, 
    136     0.825}, {3.1, 0, 0.825}, {2.3, 0, 2.1}, {2.3, -0.25, 2.1}, 
    137     {2.4, -0.25, 2.025}, {2.4, 0, 2.025}, {2.7, 0, 2.4}, {2.7, 
    138     -0.25, 2.4}, {3.3, -0.25, 2.4}, {3.3, 0, 2.4}, {2.8, 0, 
    139     2.475}, {2.8, -0.25, 2.475}, {3.525, -0.25, 2.49375}, 
    140     {3.525, 0, 2.49375}, {2.9, 0, 2.475}, {2.9, -0.15, 2.475}, 
    141     {3.45, -0.15, 2.5125}, {3.45, 0, 2.5125}, {2.8, 0, 2.4}, 
    142     {2.8, -0.15, 2.4}, {3.2, -0.15, 2.4}, {3.2, 0, 2.4}, {0, 0, 
    143     3.15}, {0.8, 0, 3.15}, {0.8, -0.45, 3.15}, {0.45, -0.8, 
    144     3.15}, {0, -0.8, 3.15}, {0, 0, 2.85}, {1.4, 0, 2.4}, {1.4, 
    145     -0.784, 2.4}, {0.784, -1.4, 2.4}, {0, -1.4, 2.4}, {0.4, 0, 
    146     2.55}, {0.4, -0.224, 2.55}, {0.224, -0.4, 2.55}, {0, -0.4, 
    147     2.55}, {1.3, 0, 2.55}, {1.3, -0.728, 2.55}, {0.728, -1.3, 
    148     2.55}, {0, -1.3, 2.55}, {1.3, 0, 2.4}, {1.3, -0.728, 2.4}, 
    149     {0.728, -1.3, 2.4}, {0, -1.3, 2.4}, {0, 0, 0}, {1.425, 
    150     -0.798, 0}, {1.5, 0, 0.075}, {1.425, 0, 0}, {0.798, -1.425, 
    151     0}, {0, -1.5, 0.075}, {0, -1.425, 0}, {1.5, -0.84, 0.075}, 
    152     {0.84, -1.5, 0.075} 
    153 }; 
    154  
    155 static float tex[2][2][2] = 
    156 
    157   { {0, 0}, 
    158     {1, 0}}, 
    159   { {0, 1}, 
    160     {1, 1}} 
    161 }; 
    162  
    163 /* *INDENT-ON* */ 
    164  
    165 static void 
    166 teapot(GLint grid, GLenum type) 
    167 
    168   float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3]; 
    169   long i, j, k, l; 
    170  
    171   glPushAttrib(GL_ENABLE_BIT | GL_EVAL_BIT); 
    172   glEnable(GL_AUTO_NORMAL); 
    173   glEnable(GL_NORMALIZE); 
    174   glEnable(GL_MAP2_VERTEX_3); 
    175   glEnable(GL_MAP2_TEXTURE_COORD_2); 
    176   for (i = 0; i < 10; i++) { 
    177     for (j = 0; j < 4; j++) { 
    178       for (k = 0; k < 4; k++) { 
    179         for (l = 0; l < 3; l++) { 
    180           p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; 
    181           q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; 
    182           if (l == 1) 
    183             q[j][k][l] *= -1.0; 
    184           if (i < 6) { 
    185             r[j][k][l] = 
    186               cpdata[patchdata[i][j * 4 + (3 - k)]][l]; 
    187             if (l == 0) 
    188               r[j][k][l] *= -1.0; 
    189             s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; 
    190             if (l == 0) 
    191               s[j][k][l] *= -1.0; 
    192             if (l == 1) 
    193               s[j][k][l] *= -1.0; 
    194           } 
    195         } 
    196       } 
    197     } 
    198     glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, 
    199       &tex[0][0][0]); 
    200     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, 
    201       &p[0][0][0]); 
    202     glMapGrid2f(grid, 0.0, 1.0, grid, 0.0, 1.0); 
    203     glEvalMesh2(type, 0, grid, 0, grid); 
    204     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, 
    205       &q[0][0][0]); 
    206     glEvalMesh2(type, 0, grid, 0, grid); 
    207     if (i < 6) { 
    208       glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, 
    209         &r[0][0][0]); 
    210       glEvalMesh2(type, 0, grid, 0, grid); 
    211       glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, 
    212         &s[0][0][0]); 
    213       glEvalMesh2(type, 0, grid, 0, grid); 
    214     } 
    215   } 
    216   glPopAttrib(); 
    217 
    218  
    219  
    220 // Now the OSG wrapper for the above OpenGL code, the most complicated bit is computing 
    221 // the bounding box for the above example, normally you'll find this the easy bit. 
    222 class Teapot : public osg::Drawable 
     33// Fill in the drawImplementation and computeBound methods 
     34// to render a cube with center 0,0,0, sides 1. 
     35class CustomDrawable : public osg::Drawable 
    22336{ 
    22437    public: 
    225         Teapot() {} 
     38        CustomDrawable() {} 
    22639 
    22740        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ 
    228         Teapot(const Teapot& teapot,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): 
    229             osg::Drawable(teapot,copyop) {} 
     41        CustomDrawable(const CustomDrawable& draw,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): 
     42            osg::Drawable(draw,copyop) {} 
    23043 
    231         META_Object(myTeapotApp,Teapot
     44        META_Object(myNameSpace,CustomDrawable
    23245 
    23346 
     
    23649        virtual void drawImplementation(osg::RenderInfo&) const 
    23750        { 
    238             // teapot(..) doens't use vertex arrays at all so we don't need to toggle their state 
    239             // if we did we'd need to something like following call 
    240             // state.disableAllVertexArrays(), see src/osg/Geometry.cpp for the low down. 
    241          
    242             // just call the OpenGL code. 
    243             teapot(14,GL_FILL); 
     51            std::cout<<"CustomDrawable::drawImplemenaton() - Not implemenated yet."<<std::endl; 
    24452        } 
    24553         
     
    25159            osg::BoundingBox bbox; 
    25260 
    253             // follow is some truely horrible code required to calculate the  
    254             // bounding box of the teapot.  Have used the original code above to do 
    255             // help compute it. 
    256             float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3]; 
    257             long i, j, k, l; 
    258  
    259             for (i = 0; i < 10; i++) { 
    260               for (j = 0; j < 4; j++) { 
    261                 for (k = 0; k < 4; k++) { 
    262                  
    263                   for (l = 0; l < 3; l++) { 
    264                     p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; 
    265                     q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; 
    266                     if (l == 1) 
    267                       q[j][k][l] *= -1.0; 
    268                        
    269                     if (i < 6) { 
    270                       r[j][k][l] = 
    271                         cpdata[patchdata[i][j * 4 + (3 - k)]][l]; 
    272                       if (l == 0) 
    273                         r[j][k][l] *= -1.0; 
    274                       s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; 
    275                       if (l == 0) 
    276                         s[j][k][l] *= -1.0; 
    277                       if (l == 1) 
    278                         s[j][k][l] *= -1.0; 
    279                     } 
    280                   } 
    281                    
    282                   bbox.expandBy(osg::Vec3(p[j][k][0],p[j][k][1],p[j][k][2])); 
    283                   bbox.expandBy(osg::Vec3(q[j][k][0],q[j][k][1],q[j][k][2])); 
    284  
    285                   if (i < 6) 
    286                   { 
    287                     bbox.expandBy(osg::Vec3(r[j][k][0],r[j][k][1],r[j][k][2])); 
    288                     bbox.expandBy(osg::Vec3(s[j][k][0],s[j][k][1],s[j][k][2])); 
    289                   } 
    290                    
    291                    
    292                 } 
    293               } 
    294             } 
     61            std::cout<<"CustomDrawable::computeBound() - Not implemenated yet."<<std::endl; 
    29562 
    29663            return bbox; 
    &helli