more work on the ndof system.
authorJean-Luc Peurière <jlp@nerim.net>
Sun, 29 Jul 2007 18:03:36 +0000 (18:03 +0000)
committerJean-Luc Peurière <jlp@nerim.net>
Sun, 29 Jul 2007 18:03:36 +0000 (18:03 +0000)
turntable code should work reasonabilly well now.
fly code need works but is no more insane on Os X.
transform object is not present here.

if you find the movements a bit slow, you can speed
it in the preferences up to 2x in the view & controls
panel.

button1 (left) of the device let you switch between
the 3 modes. button2 let you switch between
unconstrained and dominant mode.

the plugin must be named 3DxNdofBlender.plug
and be placed in a folder named plugins in same
folder as executable

check no scaling is done in the plugin

please check it works ok on 3 platforms

intern/ghost/GHOST_Types.h
intern/ghost/intern/GHOST_SystemCarbon.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
source/blender/include/BSE_view.h
source/blender/include/mydevice.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/src/ghostwinlay.c
source/blender/src/header_view3d.c
source/blender/src/space.c
source/blender/src/transform.c
source/blender/src/view.c

index 0de4c162ab87de075ec049cbdccd2761b1ddadd6..379b3323f53c0fe9db074a459942e16fc70c8926 100644 (file)
@@ -137,7 +137,8 @@ typedef enum {
        GHOST_kEventButtonUp,           /// Mouse button event
        GHOST_kEventWheel,                      /// Mouse wheel event
 
-       GHOST_kEventNDOFMotion, /// N degree of freedom device motion event
+       GHOST_kEventNDOFMotion,         /// N degree of freedom device motion event
+       GHOST_kEventNDOFButton,         /// N degree of freedom device button event
 
        GHOST_kEventKeyDown,
        GHOST_kEventKeyUp,
index 056addddeb12f2a9f6d75f816efce886bed5eb72..756de42f227d519be31be04ec3d64f37d9cf08d8 100644 (file)
@@ -984,7 +984,7 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
                        GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
                        if (::TrackGoAway(window, mousePos))
                        {
-                               // todo: add option-close, because itØs in the HIG
+                               // todo: add option-close, because itÿs in the HIG
                                // if (event.modifiers & optionKey) {
                                        // Close the clean documents, others will be confirmed one by one.
                                //}
@@ -1069,6 +1069,7 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
     OSStatus err = eventNotHandledErr;
        GHOST_IWindow* window;
        GHOST_TEventNDOFData data;
+       UInt32 kind;
        
     switch (::GetEventClass(event))
     {
@@ -1090,7 +1091,19 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
                case kEventClassBlender :
                        window = sys->m_windowManager->getActiveWindow();
                        sys->m_ndofManager->GHOST_NDOFGetDatas(data);
-                       sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFMotion, window, data));
+                       kind = ::GetEventKind(event);
+                       
+                       switch (kind)
+                       {
+                               case 1:
+                                       sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFMotion, window, data));
+       //                              printf("motion\n");
+                                       break;
+                               case 2:
+                                       sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFButton, window, data));
+//                                     printf("button\n");
+                                       break;
+                       }
                        err = noErr;
                        break;
                default : 
index e3d4ee405e8b1347441167b893d501a90790c0f9..f3891995f54f793c2b8a432ebdd8c57717f52c73 100755 (executable)
@@ -462,25 +462,21 @@ GHOST_SystemX11::processEvent(XEvent *xe)
                        } else 
 #endif
                        if (sNdofInfo.currValues) {
-                               sNdofInfo.currValues->changed = 1;
-                               sNdofInfo.currValues->delta = xcme.data.s[8] - sNdofInfo.currValues->time;
-                               sNdofInfo.currValues->time = xcme.data.s[8];
-                               sNdofInfo.currValues->tx = xcme.data.s[2] >> 4;
-                               sNdofInfo.currValues->ty = xcme.data.s[3] >> 4;
-                               sNdofInfo.currValues->tz = xcme.data.s[4] >> 4;
-                               sNdofInfo.currValues->rx = xcme.data.s[5];
-                               sNdofInfo.currValues->ry = xcme.data.s[6];
-                               sNdofInfo.currValues->rz = xcme.data.s[7];
-
-                               /*fprintf(stderr, "ClientMessage: [%d %d %d][%d %d %d] t=%llu\n",
-                                       sNdofInfo.currValues->tx, sNdofInfo.currValues->ty, 
-                                       sNdofInfo.currValues->tz, sNdofInfo.currValues->rx, 
-                                       sNdofInfo.currValues->ry, sNdofInfo.currValues->rz, 
-                                               sNdofInfo.currValues->time); */
+                               GHOST_TEventNDOFData data;
+                               data.changed = 1;
+                               data.delta = xcme.data.s[8] - data.time;
+                               data.time = xcme.data.s[8];
+                               data.tx = xcme.data.s[2] >> 4;
+                               data.ty = xcme.data.s[3] >> 4;
+                               data.tz = xcme.data.s[4] >> 4;
+                               data.rx = xcme.data.s[5];
+                               data.ry = xcme.data.s[6];
+                               data.rz = xcme.data.s[7];
+
+                               g_event = new GHOST_EventNDOF(getMilliSeconds(),
+                                GHOST_kEventNDOFMotion,
+                                window, data);
                                
-                               g_event = new GHOST_EventNDOF(getMilliSeconds(), 
-                                                             GHOST_kEventNDOFMotion, 
-                                                             window, *sNdofInfo.currValues);
                        } else {
                                /* Unknown client message, ignore */
                        }
index d625cbab595bf753c8a36a8ac03b0002a574740a..94834d2c771e4209dbe51e4f6d387b79af351de4 100644 (file)
@@ -76,6 +76,7 @@ void sdrawbox(short x1, short y1, short x2, short y2);
 void calctrackballvecfirst(struct rcti *area, short *mval, float *vec);
 void calctrackballvec(struct rcti *area, short *mval, float *vec);
 void viewmove(int mode);
+void viewmoveNDOFfly(int mode);
 void viewmoveNDOF(int mode);
 
 int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
index af20c093a162b8b7a11cccd94d09ee3a4b63ee83..9a8d154e030947d2ed6182aa3ad749894627d777 100644 (file)
@@ -72,6 +72,7 @@
 
 /* N-degre of freedom device : 500 */
 #define NDOFMOTION 500
+#define NDOFBUTTON 501
 
 /* standard keyboard */
 
index 27cd20c3210778585109bf158d6daa153240f41e..8734e504cf43bd38300324aafcbb34c4cfc392b2 100644 (file)
@@ -139,7 +139,8 @@ typedef struct View3D {
        
        short snap_target;
        
-       short pad2;
+       char ndofmode;          /* mode of transform for 6DOF devices 0 normal, 1 fly, 2 ob transform */
+       char ndoffilter;                /*filter for 6DOF devices 0 normal, 1 dominant */
        
        void *properties_storage;       /* Nkey panel stores stuff here, not in file */
 
index f960356d7b50fc334d6aafd879c71c5269047bbf..907d0320b57518d46004189f6a60e715ecd08b87 100644 (file)
@@ -586,7 +586,13 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
 ;
           break;
         }
-
+        case GHOST_kEventNDOFButton: {
+                       GHOST_TEventNDOFData *sb= data;
+                       
+//                     printf("this is a button %i\n", sb->buttons);
+                       window_handle(win, NDOFBUTTON, sb->buttons);
+                       break;
+        }
                case GHOST_kEventCursorMove: {
                        if(win->active == 1) {
                                GHOST_TEventCursorData *cd= data;
index 0178ae25e8949a9c7218105d74d68c6214721578..5688b514a95ed217301a0d367038ce4c8acec37b 100644 (file)
@@ -5258,7 +5258,28 @@ void view3d_buttons(void)
                }
 
                uiDefIconBut(block, BUT, B_VIEWRENDER, ICON_SCENE_DEHLT, xco,0,XIC,YIC, NULL, 0, 1.0, 0, 0, "Render this window (hold CTRL for anim)");
-       
+               
+               {
+                       char tempstring[256];
+                       switch (G.vd->ndofmode) {               
+                               case 0:
+                                       sprintf(tempstring,"6dof : %s %s", "turntable",((G.vd->ndoffilter==1) ? "dominant" : ""));
+                                       break;
+                               case 1:
+                                       sprintf(tempstring,"6dof : %s %s", "fly",((G.vd->ndoffilter==1) ? "dominant" : ""));
+                                       break;
+                               case 2:
+                                       sprintf(tempstring,"6dof : %s %s", "transform",((G.vd->ndoffilter==1) ? "dominant" : ""));
+                                       break;
+                               default:
+                                       tempstring[0]=0;
+                                       break;
+                       }
+                       uiDefBut(block, LABEL,0,tempstring,
+                                        xco+=XIC*2,0,150,YIC, 0, 1.0, 0, 0, 0, 
+                                        "");
+                       
+               }
                if (ob && (ob->flag & OB_POSEMODE)) {
                        xco+= XIC/2;
                        uiBlockBeginAlign(block);
index c09f2e792431ac198b7cbf6dbe48ee4336066bec..cc3109cb57ae10771d47d6518531ad245f2723ad 100644 (file)
@@ -1567,10 +1567,29 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                doredraw= 1;
                                break;
 
-            case NDOFMOTION:
-                viewmoveNDOF(1);
+            case NDOFMOTION:           
+                               if (G.vd->ndofmode == 0) {
+                                       viewmoveNDOF(1);
+                               } else if (G.vd->ndofmode == 1) {
+                                       viewmoveNDOFfly(1);
+                               } else {
+                                       ;
+                               }
+                                       
                 break;
 
+            case NDOFBUTTON:
+                               if (val == 1) {
+                                       G.vd->ndofmode +=1;
+                                       if (G.vd->ndofmode > 2)         /* we have currently 3 modes : 0 original, 1 fly, 2 transform */
+                                               G.vd->ndofmode = 0;
+                               }
+                               if (val == 2) {
+                                       G.vd->ndoffilter =(G.vd->ndoffilter == 1 ? 0 : 1);
+                               }
+                               allqueue(REDRAWHEADERS, 0);
+                break;
+                               
                        case ONEKEY:
                                if(G.qual==LR_CTRLKEY) {
                                        flip_subdivison(1);
@@ -2584,6 +2603,7 @@ static void initview3d(ScrArea *sa)
        vd->gridflag &= ~V3D_SHOW_Z;
 
        vd->depths= NULL;
+       vd->ndofmode=0;
 }
 
 
index e2819cc369314abe50dc5823ffaddbc11f037447..9e6c1b689379f86ee926b6afb90e2c0b53132086 100755 (executable)
@@ -726,9 +726,9 @@ static void transformEvent(unsigned short event, short val) {
                        else view_editmove(event);
                        Trans.redraw= 1;
                        break;
-               case NDOFMOTION:
-            viewmoveNDOF(0);
-           break;
+//             case NDOFMOTION:
+//            viewmoveNDOF(1);
+  //         break;
                }
                Trans.redraw |= handleNumInput(&(Trans.num), event);
                Trans.redraw |= handleSnapping(&Trans, event);
@@ -1075,9 +1075,9 @@ void ManipulatorTransform()
                        case RETKEY:
                                Trans.state = TRANS_CONFIRM;
                                break;
-            case NDOFMOTION:
-                viewmoveNDOF(0);
-                break;
+   //         case NDOFMOTION:
+     //           viewmoveNDOF(1);
+     //           break;
                        }
                        if(val) {
                                switch(event) {
index c84addcf0ffcac96b1ccd4464119e390902956bc..06782b1a873706672766240b66fd49f549510f6d 100644 (file)
@@ -545,13 +545,24 @@ void calctrackballvec(rcti *area, short *mval, float *vec)
 // can be increased for improved response from
 // small deflections of the device input.
 
+
+// lukep notes : i disagree on the range.
+// the normal 3Dconnection driver give +/-400
+// on defaut range in other applications
+// and up to +/- 1000 if set to maximum
+// because i remove the scaling by delta,
+// which was a bad idea as it depend of the system
+// speed and os, i changed the scaling values, but 
+// those are still not ok
+
+
 float ndof_axis_scale[6] = {
-       +2.0,   // Tx
-       +2.0,   // Tz
-       +2.0,   // Ty
-       +0.25,  // Rx
-       +0.25,  // Rz
-       +0.25   // Ry
+       +0.01,  // Tx
+       +0.01,  // Tz
+       +0.01,  // Ty
+       +0.0015,        // Rx
+       +0.0015,        // Rz
+       +0.0015 // Ry
 };
 
 // statics for controlling G.vd->dist corrections.
@@ -563,10 +574,20 @@ float m_dist;
 
 void getndof(float *sbval);
 
-#define USE_NEW_NDOFMOVE
+static filterNDOFvalues(float *sbval)
+{
+       int i=0;
+       float max  = 0.0;
+       
+       for (i =0; i<5;i++)
+               if (fabs(sbval[i]) > max)
+                       max = fabs(sbval[i]);
+       for (i =0; i<5;i++)
+               if (fabs(sbval[i]) != max )
+                       sbval[i]=0.0;
+}
 
-#ifdef USE_NEW_NDOFMOVE
-void viewmoveNDOF(int mode)
+void viewmoveNDOFfly(int mode)
 {
     int i;
     float phi;
@@ -589,16 +610,18 @@ void viewmoveNDOF(int mode)
        // fetch the current state of the ndof device
        getndof(dval);
 
-       for(i=0;i<7;i++) printf("%f ",dval[i]);
-               printf("\n");
+       if (G.vd->ndoffilter)
+               filterNDOFvalues(fval);
+
+//     for(i=0;i<7;i++) printf("%f ",dval[i]);
+//             printf("\n");
 
 
        // Scale input values
 
-       if(dval[6] == 0) return; // guard against divide by zero
+//     if(dval[6] == 0) return; // guard against divide by zero
 
        for(i=0;i<6;i++) {
-               dval[i] = dval[i] / dval[6]; // this should be moved to device specific
 
                // user scaling
                dval[i] = dval[i] * ndof_axis_scale[i];
@@ -695,7 +718,6 @@ void viewmoveNDOF(int mode)
        /*----------------------------------------------------
      * refresh the screen
      */
-
     scrarea_do_windraw(curarea);
     screen_swapbuffers();
 
@@ -704,8 +726,6 @@ void viewmoveNDOF(int mode)
        BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
 }
 
-#endif
-
 void viewmove(int mode)
 {
        Object *ob = OBACT;
@@ -994,10 +1014,6 @@ void viewmove(int mode)
 }
 
 
-
-#ifndef USE_NEW_NDOFMOVE
-
-
 void viewmoveNDOF(int mode)
 {
     static double prevTime = 0.0;
@@ -1057,19 +1073,31 @@ void viewmoveNDOF(int mode)
 
     /* fetch the current state of the ndof device */
     getndof(fval);
-   //         printf(" motion command %f %f %f %f %f %f %f \n", fval[0], fval[1], fval[2],
-   //                                                           fval[3], fval[4], fval[5], fval[6]);
-
+ //           printf(" motion command %f %f %f %f %f %f %f \n", fval[0], fval[1], fval[2],
+ //                                                             fval[3], fval[4], fval[5], fval[6]);
+                       if (G.vd->ndoffilter)
+                               filterNDOFvalues(fval);
+       
        
        // put scaling back here, was previously in ghostwinlay
             fval[0] = fval[0]  * (1.0f/1024.0f);
             fval[1] = fval[1]  * (1.0f/1024.0f);
             fval[2] = fval[2] * (1.0f/1024.0f);
-            fval[3] = fval[3]  * 0.00003f;
-            fval[4] = fval[4]  * 0.00003f;
-            fval[5] = fval[5] * 0.00003f;
+            fval[3] = fval[3]  * 0.00005f;
+            fval[4] = fval[4]  * 0.00005f;
+            fval[5] = fval[5] * 0.00005f;
             fval[6] = fval[6]  / 1000000.0f;
-       
+                       
+       // scale more if not in perspective mode
+                       if (G.vd->persp == 0) {
+                               fval[0] = fval[0] * 0.05f;
+                               fval[1] = fval[1] * 0.05f;
+                               fval[2] = fval[2] * 0.05f;
+                               fval[3] = fval[3] * 0.9f;
+                               fval[4] = fval[4] * 0.9f;
+                               fval[5] = fval[5] * 0.9f;
+                       }
+                       
        
     /* set object offset */
        if (ob) {
@@ -1169,7 +1197,6 @@ void viewmoveNDOF(int mode)
     screen_swapbuffers();
 }
 
-#endif
 
 
 /* Gets the lens and clipping values from a camera of lamp type object */