Eclipse ViewPart with GLCanvas + mouse + rotate camera

Started by Stefano.Cottafavi, September 01, 2009, 12:22:54

Previous topic - Next topic

Stefano.Cottafavi

Hi,
as for the subject I'm developing an Eclipse plugin that contribute an additional view (ViewPart) with GLCanvas into it. The canvas is used to display a 3D object I would like to "fly around and over" . Actually I'm using succesfully an implementation of rotations and translations around the x,y axes but it's not what I'm lookong for especially when one of the axis is upside down.

I want to implement camera movement controlled by mouse mouvement but seems to me a bit tricky to let Mouse from lwjgl work with mouse listeners from Eclipse/SWT.

There's some of you who already experimented on this?

Cheers,
Stefano

shine_angelic

I managed to control openGL canvas' view with mouse using a swt.Tracker and two annidated Listeners. It's a bit tricky, but it works for me:



....(Main class and Shell stuff)
//Chiamata del render OPENGL
      
         final GLRunner child = new GLRunner(canvas, display, country);
         display.asyncExec(child);
      
      
      /*
       * LISTENERS
   
       *
       */
      Listener glcanvaslistener = new Listener() {
         Point point = null;

         public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.MouseDown:
               point = new Point(event.x, event.y);
               
               break;
            case SWT.MouseMove:
               if (point == null)
                  return;

               /*
                * Tracker invisibile per la tracciatura del mouse'
                * chiama lui la oneRender() e prende il controllo
                */
               Tracker tracker = new Tracker(upShell, SWT.NONE);

               Listener listener2 = new Listener() {

                  boolean firstgo =true;
                  int previousx =0;
                  int previousy =0;
                  
                  public void handleEvent(Event event2) {
                     switch (event2.type) {
                     
                     case SWT.Move:
                        int wherex = event2.x-previousx;
                        int wherey = event2.y-previousy;
                        
                        if (point == null)
                           return;
                        /* QUI SETTA LA PROSPETTIVA */
                        
                        previousx=event2.x;
                        previousy=event2.y;
                     }
                  }
               };
               tracker.addListener(SWT.Move, listener2);
               //chiama un tracker invisibile per muovere il 3D
               tracker.open();
               
            case SWT.MouseUp:
               point = null;
               break;
            }
         }
      };
      canvas.addListener(SWT.MouseDown, glcanvaslistener);
      canvas.addListener(SWT.MouseMove, glcanvaslistener);
      canvas.addListener(SWT.MouseUp, glcanvaslistener);
...(other listeners)