Show
Ignore:
Timestamp:
01/23/07 18:42:43 (7 years ago)
Author:
robert
Message:

Added cube test model.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp

    r6039 r6043  
    130130}; 
    131131 
    132  
     132osg::Node* createTestModel() 
     133{ 
     134    osg::Geode* geode = new osg::Geode; 
     135     
     136    osg::Geometry* geometry = new osg::Geometry; 
     137    geode->addDrawable(geometry); 
     138     
     139    osg::Vec3Array* vertices = new osg::Vec3Array; 
     140    geometry->setVertexArray(vertices); 
     141     
     142    osg::Vec3Array* normals = new osg::Vec3Array; 
     143    geometry->setNormalArray(normals); 
     144    geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 
     145     
     146    osg::Vec4Array* colours = new osg::Vec4Array; 
     147    geometry->setColorArray(colours); 
     148    geometry->setColorBinding(osg::Geometry::BIND_OVERALL); 
     149    colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 
     150     
     151     
     152    osg::Vec3 origin(0.0f,0.0f,0.0f); 
     153    osg::Vec3 dx(2.0f,0.0f,0.0f); 
     154    osg::Vec3 dy(0.0f,1.0f,0.0f); 
     155    osg::Vec3 dz(0.0f,0.0f,1.0f); 
     156     
     157    osg::Vec3 px(1.0f,0.0,0.0f); 
     158    osg::Vec3 nx(-1.0f,0.0,0.0f); 
     159    osg::Vec3 py(0.0f,1.0f,0.0f); 
     160    osg::Vec3 ny(0.0f,-1.0f,0.0f); 
     161    osg::Vec3 pz(0.0f,0.0f,1.0f); 
     162    osg::Vec3 nz(0.0f,0.0f,-1.0f); 
     163 
     164    // front face     
     165    vertices->push_back(origin); 
     166    vertices->push_back(origin+dx); 
     167    vertices->push_back(origin+dx+dz); 
     168    vertices->push_back(origin+dz); 
     169    normals->push_back(ny); 
     170    normals->push_back(ny); 
     171    normals->push_back(ny); 
     172    normals->push_back(ny); 
     173     
     174    // front face     
     175    vertices->push_back(origin+dy); 
     176    vertices->push_back(origin+dy+dz); 
     177    vertices->push_back(origin+dy+dx+dz); 
     178    vertices->push_back(origin+dy+dx); 
     179    normals->push_back(py); 
     180    normals->push_back(py); 
     181    normals->push_back(py); 
     182    normals->push_back(py); 
     183     
     184    // left face     
     185    vertices->push_back(origin+dy); 
     186    vertices->push_back(origin); 
     187    vertices->push_back(origin+dz); 
     188    vertices->push_back(origin+dy+dz); 
     189    normals->push_back(nx); 
     190    normals->push_back(nx); 
     191    normals->push_back(nx); 
     192    normals->push_back(nx); 
     193 
     194    // right face     
     195    vertices->push_back(origin+dx+dy); 
     196    vertices->push_back(origin+dx+dy+dz); 
     197    vertices->push_back(origin+dx+dz); 
     198    vertices->push_back(origin+dx); 
     199    normals->push_back(px); 
     200    normals->push_back(px); 
     201    normals->push_back(px); 
     202    normals->push_back(px); 
     203 
     204    // top face     
     205    vertices->push_back(origin+dz); 
     206    vertices->push_back(origin+dz+dx); 
     207    vertices->push_back(origin+dz+dx+dy); 
     208    vertices->push_back(origin+dz+dy); 
     209    normals->push_back(pz); 
     210    normals->push_back(pz); 
     211    normals->push_back(pz); 
     212    normals->push_back(pz); 
     213 
     214    // bottom face     
     215    vertices->push_back(origin); 
     216    vertices->push_back(origin+dy); 
     217    vertices->push_back(origin+dx+dy); 
     218    vertices->push_back(origin+dx); 
     219    normals->push_back(nz); 
     220    normals->push_back(nz); 
     221    normals->push_back(nz); 
     222    normals->push_back(nz); 
     223 
     224    geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); 
     225 
     226    return geode; 
     227} 
    133228 
    134229int main(int argc, char** argv) 
     
    234329    if (!model) 
    235330    { 
    236         osg::notify(osg::NOTICE)<<"No model loaded, please specify a model to load."<<std::endl; 
    237         return 1; 
     331        model = createTestModel(); 
    238332    } 
    239333