hi everyone !!. i have a problem with return viewer in a fuction, and to add
the viewer of the fuction in de main.
#include "ventana.h"
osg::Camera* ventana::createCamera(int x, int y, int w, int h)
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->windowName = "Funcion de Ventana";
traits->windowDecoration = true;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
return camera.release();
}
osgViewer::Viewer* ventana::crearMultipleVentana(int numeroColumnas, int numeroFilas)
{
int totalWidth = 1024, totalHeight = 768;
osgViewer::Viewer viewer;
int tileWidth = totalWidth / numeroColumnas;
int tileHeight = totalHeight / numeroFilas;
//Cremos una instancia de la nueva clase para llamar a la funcion para crear la ventana
ventana* myVentana = new ventana();
for (int i = 0; i<numeroFilas; ++i)
{
for (int j = 0; j<numeroColumnas; ++j)
{
osg::Camera* camera = myVentana->createCamera(tileWidth*j, totalHeight - tileHeight*(i + 1), tileWidth - 1, tileHeight - 1);
osg::Matrix projOffset = osg::Matrix::scale(numeroColumnas, numeroFilas, 1.0) * osg::Matrix::translate(numeroColumnas - 1 - 2 * j, numeroFilas - 1 - 2 * i, 0.0);
viewer.addSlave(camera, projOffset, osg::Matrix(), true);
}
}
return &viewer;
}#ifndef H_VENTANA
#define H_VENTANA
#include <osg/Group>
#include <osgViewer/Viewer>
class ventana
{
public:
osg::Camera* ventana::createCamera(int x, int y, int w, int h);
osgViewer::Viewer* ventana::crearMultipleVentana(int
numeroColumnas, int numeroFilas);
};
#endif#include <osgDB/ReadFile>
#include "ventana.h"
using namespace std;
int main(int argc, char** argv)
{
osg::DisplaySettings::instance()->setStereoMode(osg::DisplaySettings::ANAGLYPHIC);
osg::DisplaySettings::instance()->setEyeSeparation(0.05f);
osg::DisplaySettings::instance()->setStereo(true);
//Añadimos el modelo a la variable
osg::ref_ptr<osg::Node> modelo = osgDB::readNodeFile("cessna.osg");
//Comprobamos si hemos añadido el modelo correctamente
if (!modelo)
{
cout<< "Error al leer el modelo, comprueve la ruta" <<endl;
}
//Creamos la vista
osgViewer::Viewer viewer;
//Cremos una instancia de la nueva clase para llamar a la funcion para crear la ventana
ventana* myVentana = new ventana();
//Añadimos la nueva ventana a la vista
//viewer.addSlave(myVentana->createCamera(300, 100, 900, 600));
viewer.getViews(myVentana->crearMultipleVentana(2, 2));
//Añadimos el modelo a la vista
viewer.setSceneData(modelo);
//Bucle de la simulacion de la vista
return viewer.run();
}_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org