Exemple #1
0
const osg::Vec3f Stars::xyzTristimulus(const osg::Vec2f planckianLocus)
{
    // (http://en.wikipedia.org/wiki/CIE_1931_color_space)
    // and (The Colors of the Stars - Olson - 1998)

    const float Y = 1.0;
    
    const float X = Y / planckianLocus.y() * planckianLocus.x();
    const float Z = Y / planckianLocus.y() * (1.0 - planckianLocus.x() - planckianLocus.y());

    return osg::Vec3f(X, Y, Z);
}
//the following 2 functions are no longer being used to and real extent, but were left in to avoid errors in the functions that use them
osg::Vec3f Render::calculateForceDirections(float force, osg::Vec2f direction){
	Vector2 vector = Vector2::Vector2(direction.x(), direction.y());
	float viewHeight = viewer.getCamera()->getViewport()->height();
	float viewWidth = viewer.getCamera()->getViewport()->width();
	
	float relationship = (viewHeight<viewWidth)?15/(viewHeight/4):15/(viewWidth/4);
	
	float theta = osg::DegreesToRadians(vector.Length()*relationship);
	float phi = atan2(direction.y(), direction.x());

	Logger::getInstance()->log("Theta: " + f2s(theta) + " Phi: " + f2s(phi));
	return osg::Vec3f(-(force*sin(theta)*cos(phi)), -(force*sin(theta)*sin(phi)),(force*cos(theta)));
}
osg::Vec3f Render::calculateForceDirections(float force, osg::Vec2f direction){
	Vector2 vector = Vector2::Vector2(direction.x(), direction.y());
	float viewHeight = viewer.getCamera()->getViewport()->height();
	float viewWidth = viewer.getCamera()->getViewport()->width();
	
	float relationship = (viewHeight<viewWidth)?15/(viewHeight/4):15/(viewWidth/4);

	std::cout << "Relationship: " << relationship << std::endl;
	
	float theta = osg::DegreesToRadians(vector.Length()*relationship);
	float phi = atan2(direction.y(), direction.x());

	std::cout << "Theta: " << theta << std::endl;
	std::cout << "Phi: " << phi << std::endl;

	return osg::Vec3f(-(force*sin(theta)*cos(phi)), -(force*sin(theta)*sin(phi)),(force*cos(theta)));
}
void DistortionSurface::build( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture )
{
    osg::notify(osg::INFO) << "DistortionSurface::build()"<< std::endl;

    _angle = 0.f;

    removeDrawables( 0, getNumDrawables() );

    osg::Geometry* geom = 
        osg::createTexturedQuadGeometry( corner, osg::Vec3(dims.x(),0.f,0.f), 
                                         osg::Vec3f(0.f,dims.y(),0.f), 
                                         texture->getTextureWidth(), texture->getTextureHeight() );
    addDrawable(geom);

    osg::StateSet* ss = new osg::StateSet;

    osg::ref_ptr<osg::Program> program = createShader();

    if(program.valid())
        ss->setAttributeAndModes( program.get(), osg::StateAttribute::ON );
    else
        osg::notify(osg::WARN) << "DistortionSurface::build() Invalid Shader"<< std::endl;
    
    ss->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON);

    ss->addUniform( new osg::Uniform( "osgOcean_FrameBuffer",  0 ) );
    ss->addUniform( new osg::Uniform( "osgOcean_Frequency",    2.f ) );
    ss->addUniform( new osg::Uniform( "osgOcean_Offset",       0.f ) );
    ss->addUniform( new osg::Uniform( "osgOcean_Speed",        1.f ) );
    ss->addUniform( new osg::Uniform( "osgOcean_ScreenRes",    dims ) );

    ss->setMode(GL_LIGHTING,    osg::StateAttribute::OFF);
    ss->setMode(GL_DEPTH_TEST,  osg::StateAttribute::OFF);

    setStateSet(ss);

    setUserData( new DistortionDataType(*this) );
    setUpdateCallback( new DistortionCallback );
}
Exemple #5
0
void
Control::calcPos(const ControlContext& cx, const osg::Vec2f& cursor, const osg::Vec2f& parentSize)
{
    if ( _x.isSet() )
    {
        _renderPos.x() = cursor.x() + margin().left() + *x();
    }
    else
    {
        if ( _halign == ALIGN_CENTER )
        {
            _renderPos.x() = cursor.x() + 0.5*(parentSize.x() - _renderSize.x());
        }
        else if ( _halign == ALIGN_RIGHT )
        {
            _renderPos.x() = cursor.x() + parentSize.x() - margin().right() - _renderSize.x();
        }
        else
        {
            _renderPos.x() = cursor.x() + margin().left();
        }
    }

    if ( _y.isSet() )
    {
        _renderPos.y() = cursor.y() + margin().top() + *y();
    }
    else
    {
        if ( _valign == ALIGN_CENTER )
        {
            _renderPos.y() = cursor.y() + 0.5*(parentSize.y() - _renderSize.y());
        }
        else if ( _valign == ALIGN_BOTTOM )
        {
            _renderPos.y() = cursor.y() + parentSize.y() - margin().bottom() - _renderSize.y();
        }
        else
        {
            _renderPos.y() = cursor.y() + margin().top();
        }
    }
}
 void onClick( Control* control, const osg::Vec2f& pos, int mouseButtonMask )
 {
     OE_NOTICE << "You clicked at (" << pos.x() << ", " << pos.y() << ") within the control."
         << std::endl;
 }
int main(int argc, char *argv[])
{
    // Init the OpenSG subsystem
    OSG::osgInit(argc, argv);

    {
        // We create a GLUT Window (that is almost the same for most applications)
        int winid = setupGLUT(&argc, argv);
        OSG::GLUTWindowRecPtr gwin = OSG::GLUTWindow::create();
        gwin->setGlutId(winid);
        gwin->init();
    
        // Create the face
        std::string family = "SANS";
        OSG::TextFace::Style style = OSG::TextFace::STYLE_PLAIN;
        OSG::UInt32 size = 32;
        OSG::TextPixmapFaceRefPtr face = 
            OSG::TextPixmapFace::create(family, style, size);
        if (face == 0)
        {
            std::cerr << "ERROR: Cannot create face object!" << std::endl;
            return -1;
        }
    
        // Lay out one single line of text
        std::string text = "Hello World!"; // Use UTF-8 encoding!
        OSG::TextLayoutParam layoutParam;
        layoutParam.horizontal = true;
        layoutParam.leftToRight = true;
        layoutParam.topToBottom = true;
        layoutParam.majorAlignment = OSG::TextLayoutParam::ALIGN_FIRST;
        layoutParam.minorAlignment = OSG::TextLayoutParam::ALIGN_FIRST;
        layoutParam.spacing = 1.f;
        layoutParam.length.push_back(0.f);
        layoutParam.maxExtend = 0.f;
        OSG::TextLayoutResult layoutResult;
        face->layout(text, layoutParam, layoutResult);
    
        // Render the text into an OpenSG image
        OSG::Vec2f offset;
        OSG::UInt32 border = 1;
        OSG::ImageRecPtr imagePtr = face->makeImage(layoutResult, offset, border);
        
        // Create the geometry which we will assign the texture to
        OSG::Real32 width = imagePtr->getWidth();
        OSG::Real32 height = imagePtr->getHeight();
        OSG::NodeRecPtr plane = OSG::makePlane(width, height, 1, 1);
    
        // Create the texture that will hold the image
        OSG::SimpleTexturedMaterialRecPtr tex = 
            OSG::SimpleTexturedMaterial::create();
        tex->setImage(imagePtr);
        tex->setEnvMode(GL_MODULATE);
        tex->setDiffuse(OSG::Color3f(1, 0, 0));
    
        // Assign the texture to the geometry
        OSG::GeometryRecPtr geo =
            dynamic_cast<OSG::Geometry *>(plane->getCore());
        geo->setMaterial(tex);
    
        // Transform the geometry so that the origin of the text is at
        // the origin of the world coordinate system
        OSG::NodeRecPtr scene = OSG::Node::create();
        OSG::TransformRecPtr transformPtr = OSG::Transform::create();
        OSG::Matrix m;
        m.setTranslate(offset.x() + width / 2, offset.y() - height / 2, 0);
        transformPtr->setMatrix(m);
        
        scene->setCore(transformPtr);
        scene->addChild(plane);
        
        // Create and setup the SSM
        mgr = new OSG::SimpleSceneManager;
        mgr->setWindow(gwin);
        mgr->setRoot(scene);
    
        // Create a blue background
        OSG::SolidBackgroundRecPtr bg = OSG::SolidBackground::create();
        bg->setColor(OSG::Color3f(0.1, 0.1, 0.5));
        
        gwin->getPort(0)->setBackground(bg);
        
        mgr->showAll();
        
        OSG::commitChanges();
    }

    // Give Control to the GLUT Main Loop
    glutMainLoop();

    return 0;
}