osg::Node* AnnotationUtils::createHemisphere( float r, const osg::Vec4& color, float maxAngle ) { osg::Geometry* geom = new osg::Geometry(); geom->setUseVertexBufferObjects(true); osg::Vec3Array* v = new osg::Vec3Array(); v->reserve(5); v->push_back( osg::Vec3(0,0,r) ); // top v->push_back( osg::Vec3(-r,0,0) ); // left v->push_back( osg::Vec3(r,0,0) ); // right v->push_back( osg::Vec3(0,r,0) ); // back v->push_back( osg::Vec3(0,-r,0) ); // front geom->setVertexArray(v); if ( v->getVertexBufferObject() ) v->getVertexBufferObject()->setUsage(GL_STATIC_DRAW_ARB); osg::DrawElementsUByte* b = new osg::DrawElementsUByte(GL_TRIANGLES); b->reserve(12); b->push_back(0); b->push_back(2); b->push_back(3); b->push_back(0); b->push_back(3); b->push_back(1); b->push_back(0); b->push_back(1); b->push_back(4); b->push_back(0); b->push_back(4); b->push_back(2); geom->addPrimitiveSet( b ); osg::Vec3Array* n = new osg::Vec3Array(); n->reserve(5); n->push_back( osg::Vec3(0,0,1) ); n->push_back( osg::Vec3(-1,0,0) ); n->push_back( osg::Vec3(1,0,0) ); n->push_back( osg::Vec3(0,1,0) ); n->push_back( osg::Vec3(0,-1,0) ); geom->setNormalArray(n); geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); MeshSubdivider ms; ms.run( *geom, osg::DegreesToRadians(maxAngle), GEOINTERP_GREAT_CIRCLE ); osg::Vec4Array* c = new osg::Vec4Array(1); (*c)[0] = color; geom->setColorArray( c ); geom->setColorBinding( osg::Geometry::BIND_OVERALL ); osg::Geode* geode = new osg::Geode(); geode->addDrawable( geom ); // need 2-pass alpha so you can view it properly from below. if ( color.a() < 1.0f ) return installTwoPassAlpha( geode ); else return geode; }
void ImageOverlay::init() { OpenThreads::ScopedLock< OpenThreads::Mutex > lock(_mutex); double height = 0; osg::Geometry* geometry = new osg::Geometry(); osg::Vec3d ll; _ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_lowerLeft.y()), osg::DegreesToRadians(_lowerLeft.x()), height, ll.x(), ll.y(), ll.z()); osg::Vec3d lr; _ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_lowerRight.y()), osg::DegreesToRadians(_lowerRight.x()), height, lr.x(), lr.y(), lr.z()); osg::Vec3d ur; _ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_upperRight.y()), osg::DegreesToRadians(_upperRight.x()), height, ur.x(), ur.y(), ur.z()); osg::Vec3d ul; _ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_upperLeft.y()), osg::DegreesToRadians(_upperLeft.x()), height, ul.x(), ul.y(), ul.z()); osg::Vec3Array* verts = new osg::Vec3Array(4); (*verts)[0] = ll; (*verts)[1] = lr; (*verts)[2] = ur; (*verts)[3] = ul; geometry->setVertexArray( verts ); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0] = osg::Vec4(1,1,1,_alpha); geometry->setColorArray( colors ); geometry->setColorBinding( osg::Geometry::BIND_OVERALL ); GLuint tris[6] = { 0, 1, 2, 0, 2, 3 }; geometry->addPrimitiveSet(new osg::DrawElementsUInt( GL_TRIANGLES, 6, tris ) ); bool flip = false; if (_image.valid()) { //Create the texture osg::Texture2D* texture = new osg::Texture2D(_image.get()); texture->setResizeNonPowerOfTwoHint(false); _geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); flip = _image->getOrigin()==osg::Image::TOP_LEFT; } osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,flip ? 1.0 : 0.0f); (*texcoords)[1].set(1.0f,flip ? 1.0 : 0.0f); (*texcoords)[2].set(1.0f,flip ? 0.0 : 1.0f); (*texcoords)[3].set(0.0f,flip ? 0.0 : 1.0f); geometry->setTexCoordArray(0, texcoords); MeshSubdivider ms; ms.run(osg::DegreesToRadians(5.0), *geometry); _geode->removeDrawables(0, _geode->getNumDrawables() ); _geode->addDrawable( geometry ); _geometry = geometry; _dirty = false; }