Okay, with this version joined, we have two tabs (not added dynamically,
sure, but it's a beginning...) with animation rendered correctly...

The only issue left is the mouse handling problem:
I added a trackballmanipulator on the view1 on each tab, assigned an
handling function to the corresponding wxGLCanvas each time, and this
function is indeed called when I drag on the view1 BUT nothing moves...
:-(...

I'm using view->getEventQueue()... could it be somehow "disconnected" ?
nothing happens either if I use the corresponding
graphicswindow->getEventQueue()... so what's left ??

Manu.


2007/10/26, Emmanuel Roche <[EMAIL PROTECTED]>:
>
> Indeed, we are in a situation where the CompositeViewers don't share the
> GraphicsWindows and everything happen in the same thread... yet, it's
> currently not working for me:
>
> as soon as I had a second tab only the last compositeviewer gets updated
> and drawn, the others are frozen... :-(...
>
> I keep investigating...
>
> Manu.
>
> 2007/10/26, Robert Osfield <[EMAIL PROTECTED]>:
> >
> > On 10/26/07, Alberto Luaces <[EMAIL PROTECTED]> wrote:
> > > If I recall correctly, you can have as many CompositeViewers as you
> > like/need.
> >
> > If the different viewers don't share any GaphicsWindows then it should
> > be fine to have multiple Viewer/CompositeViewers.
> >
> > However, If all the viewers run in different threads then sharing a
> > single scene graph between them would be problematic.  Such usage
> > would lead to one viewers update running in parallel with another
> > viewer's cull/draw.
> >
> > Robert.
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
>
>
#include "wx/wx.h"
#include "wx/glcanvas.h"
#include "wx/notebook.h"

#include "osg/ref_ptr"
#include "osg/Vec3"
#include "osg/GraphicsContext"
#include "osgViewer/GraphicsWindow"
#include "osgViewer/CompositeViewer"
#include "osgViewer/Viewer"
#include "osgViewer/View"
#include "osgDB/ReadFile"
#include "osgGA/TrackballManipulator"

#include <iostream>

osg::State *st2;
osg::State *st1;

//osgViewer::CompositeViewer* currentViewer;

class programa: public wxApp
{
        public:
                bool OnInit();
};

DECLARE_APP( programa)
IMPLEMENT_APP( programa)

class ventanaOSGWX: public osgViewer::GraphicsWindow
{
        public:
                ventanaOSGWX( wxGLCanvas *wx): wxGL( wx)
                {
                }
                bool makeCurrentImplementation()
                {
                        if(!wxGL->GetParent()->IsShown())
                                return false;

                        wxGL->SetCurrent();
                        return true;
                }
                void swapBuffersImplementation()
                {
                        wxGL->SwapBuffers();
                }
                bool realizeImplementation()
                {
                        return true;
                }
                bool valid() const
                {
                        return true;
                }
                bool isRealizedImplementation() const
                {
                        return true;
                }
                void closeImplementation()
                {
                }
                bool releaseContextImplementation()
                {
                        return true;
                }
                void grabFocus()
                {
                        wxGL->SetFocus();
                }
                void grabFocusIfPointerInWindow()
                {
                        wxGL->SetFocus();
                }
        private:
                wxGLCanvas *wxGL;
};

class ventana: public wxPanel
{
        public:
                ventana( wxWindow *p, const std::string &objeto);

                void OnPaint( wxPaintEvent &e);

                osgViewer::CompositeViewer* getViewer() { return cViewer; }
        private:
                osg::ref_ptr<ventanaOSGWX> v1, v2;
                osgViewer::CompositeViewer *cViewer;
                osgViewer::View *view1, *view2;
                DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE( ventana, wxPanel)
        EVT_PAINT( ventana::OnPaint)
        
END_EVENT_TABLE()

class MouseHandler : public wxEvtHandler
{
private:
        DECLARE_EVENT_TABLE();
        osgViewer::View* view;
        ventanaOSGWX* gw;

public:
        MouseHandler(osgViewer::View* v, ventanaOSGWX* graphicswindow) : 
view(v), gw(graphicswindow) {};

        void OnMouse(wxMouseEvent& event);
};

BEGIN_EVENT_TABLE(MouseHandler,wxEvtHandler)
        EVT_MOUSE_EVENTS(MouseHandler::OnMouse)
END_EVENT_TABLE()

bool programa::OnInit()
{
        //currentViewer = NULL;
        wxFrame *v = new wxFrame(0, wxID_ANY, wxT("Dos vistas con OSG"), 
wxDefaultPosition, wxSize( 540,305)); /* No vale con el ctor por defecto */
        wxNotebook *nb = new wxNotebook(v,wxID_ANY);
        ventana *panel1 = new ventana( nb, "cow.osg");
        ventana *panel2 = new ventana( nb, "cessna.osg");
        nb->AddPage( panel1, wxT("Primero"), true);
        nb->AddPage( panel2, wxT("Segundo"), false);
        v->Show();
        //currentViewer = panel1->getViewer();
        return true;
}

ventana::ventana( wxWindow *p, const std::string &objeto): wxPanel( p)
{
        wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
        SetSizer( sizer);
        wxGLCanvas *w1, *w2;
        wxGLContext *wxglc;
        
        cViewer = new osgViewer::CompositeViewer;

        w1 = new wxGLCanvas( this, 1, wxDefaultPosition, wxSize(256,256));
        Show(); /* Para que se cree de manera efectiva el contexto de OpenGL */
        
        /* Genera una advertencia de GTK acerca de un widget todavía no 
constuído, posiblemente porque */
        /* se ordena mostrar el "wxFrame" cuando todavía no se ha salido de su 
constructor. Una solución */
        /* posiblemente más limpia sería crear la segunda ventana en el 
primer evento de redibujado, */
        /* mediante un bool que indique si ya estaba creado o no. */
        
        wxglc = w1->GetContext();

        w2 = new wxGLCanvas( this, wxglc, 2, wxDefaultPosition, 
wxSize(256,256));


        sizer->Add( w1, 0, wxALL, 5);
        sizer->Add( w2, 0, wxALL, 5);
        
        sizer->Fit( this);

        v1 = new ventanaOSGWX( w1);
        v2 = new ventanaOSGWX( w2);
        
        
        view1 = new osgViewer::View;
        view2 = new osgViewer::View;


        st1 = new osg::State;
        st2 = new osg::State;
        
        st1->setContextID( osg::GraphicsContext::createNewContextID());
//      Si st2 usa el mismo ID  que st1, hay que llamar a 
incrementContextIDUsageCount
        st2->setContextID( osg::GraphicsContext::createNewContextID());
        
        v1->setState( st1);
        st1->setGraphicsContext( v1.get());
        
        v2->setState( st2);
        st2->setGraphicsContext( v2.get());

        view1->getCamera()->setGraphicsContext( v1.get());
        view1->setCameraManipulator(new osgGA::TrackballManipulator);
        view2->getCamera()->setGraphicsContext( v2.get());
        //view2->setCameraManipulator(new osgGA::TrackballManipulator);
        
        view1->getCamera()->setViewport(0,0,256,256);
        //view1->getCamera()->setProjectionMatrixAsPerspective(30.0f, 1.0, 1.0, 
1000.0);
        //view1->getCamera()->setViewMatrixAsLookAt(osg::Vec3(-10,-10,-10), 
osg::Vec3(0,0,0),osg::Vec3(0,0,1));
        
        view2->getCamera()->setViewport(0,0,256,256);
        view2->getCamera()->setProjectionMatrixAsPerspective(30.0f, 1.0, 1.0, 
1000.0);
        view2->getCamera()->setViewMatrixAsLookAt(osg::Vec3(-10,+10,-10), 
osg::Vec3(0,0,0),osg::Vec3(0,0,1));
        
        osg::Node *nodo = osgDB::readNodeFile( objeto);
        
        view1->setSceneData( nodo);
        view2->setSceneData( nodo);
        
        cViewer->addView( view1);
        cViewer->addView( view2);

        w1->PushEventHandler(new MouseHandler(view1,v1.get()));
        //w2->PushEventHandler(new MouseHandler(view2,v2.get()));
}

void ventana::OnPaint( wxPaintEvent &e)
{
        static double t = 0.0;
        wxPaintDC dc(this);
        cViewer->frame();

        
//view1->getCamera()->setViewMatrixAsLookAt(osg::Vec3(-10*cos(t),-10*sin(t),-10),
 osg::Vec3(0,0,0),osg::Vec3(0,0,1));
        
view2->getCamera()->setViewMatrixAsLookAt(osg::Vec3(-10*cos(-t),-10*sin(-t),-10),
 osg::Vec3(0,0,0),osg::Vec3(0,0,1));
        t+=0.1;
        Refresh(true);
}

void MouseHandler::OnMouse(wxMouseEvent& event)
{
    if (event.ButtonDown()) {
        int button = event.GetButton();
        view->getEventQueue()->mouseButtonPress(event.GetX(), event.GetY(), 
button);
    }
    else if (event.ButtonUp()) {
        int button = event.GetButton();
        view->getEventQueue()->mouseButtonRelease(event.GetX(), event.GetY(), 
button);
    }
    else if (event.Dragging()) {
        view->getEventQueue()->mouseMotion(event.GetX(), event.GetY());
    }
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to