Ejemplo n.º 1
0
osgToy::OctoStrip::OctoStrip()
{
    osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() );

    osg::Vec3Array* nAry = dynamic_cast<osg::Vec3Array*>( getNormalArray() );
    setNormalBinding( osg::Geometry::BIND_PER_VERTEX );

    osg::Vec4Array* cAry = dynamic_cast<osg::Vec4Array*>( getColorArray() );
    setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    osg::Vec3 xp( 1, 0, 0);   osg::Vec4 red(1,0,0,1);
    osg::Vec3 xn(-1, 0, 0);   osg::Vec4 cyan(0,1,1,1);
    osg::Vec3 yp( 0, 1, 0);   osg::Vec4 green(0,1,0,1);
    osg::Vec3 yn( 0,-1, 0);   osg::Vec4 magenta(1,0,1,1);
    osg::Vec3 zp( 0, 0, 1);   osg::Vec4 blue(0,0,1,1);
    osg::Vec3 zn( 0, 0,-1);   osg::Vec4 yellow(1,1,0,1);

    vAry->push_back(zp); nAry->push_back(zp); cAry->push_back(blue);
    vAry->push_back(yp); nAry->push_back(yp); cAry->push_back(green);
    vAry->push_back(xn); nAry->push_back(xn); cAry->push_back(cyan);
    vAry->push_back(zn); nAry->push_back(zn); cAry->push_back(yellow);
    vAry->push_back(yn); nAry->push_back(yn); cAry->push_back(magenta);
    vAry->push_back(xp); nAry->push_back(xp); cAry->push_back(red);
    vAry->push_back(zp); nAry->push_back(zp); cAry->push_back(blue);
    vAry->push_back(yp); nAry->push_back(yp); cAry->push_back(green);

    addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLE_STRIP, 0, vAry->size() ) );
}
Ejemplo n.º 2
0
void osgToy::ColorOriginTetra::addTriangle(
        const osg::Vec3& v0, const osg::Vec3& v1, const osg::Vec3& v2 )
{
    osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() );
    osg::Vec3Array* nAry = dynamic_cast<osg::Vec3Array*>( getNormalArray() );
    osg::Vec4Array* cAry = dynamic_cast<osg::Vec4Array*>( getColorArray() );

    osg::Vec3 norm = (v1-v0) ^ (v2-v0);
    norm.normalize();
    nAry->push_back( norm );

    vAry->push_back( v0 );  cAry->push_back( osg::Vec4(v0,1) );
    vAry->push_back( v1 );  cAry->push_back( osg::Vec4(v1,1) );
    vAry->push_back( v2 );  cAry->push_back( osg::Vec4(v2,1) );
}
Ejemplo n.º 3
0
osgToy::TetraStrip::TetraStrip()
{
    osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() );

    osg::Vec3Array* nAry = dynamic_cast<osg::Vec3Array*>( getNormalArray() );
    setNormalBinding( osg::Geometry::BIND_PER_VERTEX );

    osg::Vec4Array* cAry = dynamic_cast<osg::Vec4Array*>( getColorArray() );
    setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    osg::Vec3 ppp(  1,  1,  1);   osg::Vec4 white(1,1,1,1);
    osg::Vec3 nnp( -1, -1,  1);   osg::Vec4 blue(0,0,1,1);
    osg::Vec3 pnn(  1, -1, -1);   osg::Vec4 red(1,0,0,1);
    osg::Vec3 npn( -1,  1, -1);   osg::Vec4 green(0,1,0,1);
    osg::Vec3 ppn(  1,  1, -1);   osg::Vec4 yellow(1,1,0,1);
    osg::Vec3 pnp(  1, -1,  1);   osg::Vec4 magenta(1,0,1,1);
    osg::Vec3 nnn( -1, -1, -1);   osg::Vec4 black(0,0,0,1);
    osg::Vec3 npp( -1,  1,  1);   osg::Vec4 cyan(0,1,1,1);

#if 1
    vAry->push_back(ppp); nAry->push_back(ppp); cAry->push_back(white);
    vAry->push_back(nnp); nAry->push_back(nnp); cAry->push_back(blue);
    vAry->push_back(pnn); nAry->push_back(pnn); cAry->push_back(red);
    vAry->push_back(npn); nAry->push_back(npn); cAry->push_back(green);
    vAry->push_back(ppp); nAry->push_back(ppp); cAry->push_back(white);
    vAry->push_back(nnp); nAry->push_back(nnp); cAry->push_back(blue);
#else
    vAry->push_back(ppn); nAry->push_back(ppn); cAry->push_back(yellow);
    vAry->push_back(pnp); nAry->push_back(pnp); cAry->push_back(magenta);
    vAry->push_back(nnn); nAry->push_back(nnn); cAry->push_back(black);
    vAry->push_back(npp); nAry->push_back(npp); cAry->push_back(cyan);
    vAry->push_back(ppn); nAry->push_back(ppn); cAry->push_back(yellow);
    vAry->push_back(pnp); nAry->push_back(pnp); cAry->push_back(magenta);
#endif

    addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLE_STRIP, 0, vAry->size() ) );
}
deprecated_osg::Geometry::AttributeBinding deprecated_osg::Geometry::getNormalBinding() const { return static_cast<AttributeBinding>(osg::getBinding(getNormalArray())); }