• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

How to add event (Mouse click) on the OpenGL control

Started by Low Chee Huey, September 17, 2009, 02:53:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Low Chee Huey

Hi,

    I am new here, nice to meet u o.  ;)
    i was downloading a project titled "Panorama 360", under OpenGL category from zapsolution. I wish to add some user control to that program, such as user left click mouse button on the Image (System.Windows.Forms.Panel which is later becomes OpenGL control) to restart the rotation.
          // from the sample code:
         // Create the OpenGL control
                hGLcontrol = GI.CreateControl(GL_Template, ID_CTRL);

    I have tried to add the event handler "click" on the System.Windows.Forms.Panel but it did not response to it, i guess there is another control on top on it(correct me if i am wrong).

    Can anyone give some advice how to add event handler to the control which showing the image? either is to the OpenGL control or to the System.Windows.Forms.Panel control.

    Looking forward to hear from u soon.

Thank you. n_n





Patrice Terrier

#1
Low Chee Huey

Most of us, here, are low level flat API SDK coders, thus better to ask on a DotNET forum.

However my C# Planet3D project allows you to move the planet with the mouse, see the glWndProc callback below:


       public static int glWndProc(IntPtr hWnd, int wMsg, uint wParam, uint lParam)
       {
           int x, y;
           switch (wMsg)
           {
               case Api.WM_LBUTTONDOWN:
                   if (bMousing == false)
                   {
                       x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
                       ptLastMousePositX = x;
                       ptCurrentMousePositX = x;
                       ptLastMousePositY = y;
                       ptCurrentMousePositY = y;
                       bMousing = true;
                   }
                   if (Api.GetFocus() != hWnd) Api.SetFocus(hWnd);
                   break;
               case Api.WM_LBUTTONUP:
                   bMousing = false;
                   break;
               case Api.WM_MOUSEMOVE:
                   x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
                   if (GI.IsLButtonDown() == false)
                   {
                       bMousing = false;
                   }
                   else
                   {
                       if ((GLwasX != x) || (GLwasY != y))
                       {
                           ptCurrentMousePositX = x;
                           ptCurrentMousePositY = y;
                           if (bMousing)
                           {
                               grSpinX += (ptCurrentMousePositX - ptLastMousePositX);
                               grSpinY -= (ptCurrentMousePositY - ptLastMousePositY);
                           }
                           ptLastMousePositX = ptCurrentMousePositX;
                           ptLastMousePositY = ptCurrentMousePositY;
                       }
                       GLwasX = x; GLwasY = y;
                   }
                   break;
           }
           return Api.CallWindowProc(ghGLproc, hWnd, wMsg, wParam, lParam);
       }


Note: Both Panorama and Planet3D are using polar coordinates, and they are based on sphere manipulation, in the first one the camera is inside of the sphere while in the other it is outside.

Well, it has been quite a while since i wrote that C# code  8)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com