Index: intern/ghost/intern/GHOST_SystemX11.cpp =================================================================== --- intern/ghost/intern/GHOST_SystemX11.cpp (revisão 33984) +++ intern/ghost/intern/GHOST_SystemX11.cpp (cópia de trabalho) @@ -632,9 +632,11 @@ } else #endif if (sNdofInfo.currValues) { + static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0}; if (xcme.message_type == sNdofInfo.motionAtom) { + //printf("motion ndof event\n"); data.changed = 1; data.delta = xcme.data.s[8] - data.time; data.time = xcme.data.s[8]; @@ -648,6 +650,7 @@ GHOST_kEventNDOFMotion, window, data); } else if (xcme.message_type == sNdofInfo.btnPressAtom) { + //printf("BUTTON ndof event\n"); data.changed = 2; data.delta = xcme.data.s[8] - data.time; data.time = xcme.data.s[8]; Index: source/blender/makesdna/DNA_windowmanager_types.h =================================================================== --- source/blender/makesdna/DNA_windowmanager_types.h (revisão 33984) +++ source/blender/makesdna/DNA_windowmanager_types.h (cópia de trabalho) @@ -172,6 +172,8 @@ short lastcursor; /* for temp waitcursor */ short addmousemove; /* internal: tag this for extra mousemove event, makes cursors/buttons active on UI switching */ short pad2[2]; + float ndof[7]; + short ndofAlign[2]; struct wmEvent *eventstate; /* storage for event system */ Index: source/blender/windowmanager/intern/wm_window.c =================================================================== --- source/blender/windowmanager/intern/wm_window.c (revisão 33984) +++ source/blender/windowmanager/intern/wm_window.c (cópia de trabalho) @@ -66,6 +66,7 @@ #include "GPU_draw.h" #include "GPU_extensions.h" +#include "PIL_dynlib.h" /* the global to talk to ghost */ GHOST_SystemHandle g_system= NULL; @@ -297,6 +298,96 @@ } } +/*************** ndof *************************/ +#ifdef _WIN32 +#define PATH_SEP "\\" +#else +#define PATH_SEP "/" +#endif + +void wm_open_ndof(bContext *C, GHOST_WindowHandle ghostwin) +{ + char *inst_path, *plug_path; + const char *plug_dir = "plugins"; + const char *plug_name = "3DxNdofBlender.plug"; + PILdynlib *ndofLib; + + // build the plugin path + plug_path = NULL; + inst_path = get_install_dir(); // path to main blender exec/bundle + if (inst_path) { + // assume the ndof plugin is located in the plug-in dir + size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2 + + strlen(plug_name) + 1; + plug_path = MEM_mallocN(len, "ndofpluginpath"); + if (plug_path) { + strncpy(plug_path, inst_path, len); + strcat(plug_path, PATH_SEP); + strcat(plug_path, plug_dir); + strcat(plug_path, PATH_SEP); + strcat(plug_path, plug_name); + } + MEM_freeN(inst_path); + } + + ndofLib = PIL_dynlib_open(plug_path); + + /* On systems where blender is installed in /usr/bin/blender, ~/.blender/plugins/ is a better place to look */ + /* Lookup only on install dir because BLI_gethome() not avaliable*/ + /*if (ndofLib==NULL) { + + if (plug_path) { + MEM_freeN(plug_path); + } + + inst_path = BLI_gethome(); + if (inst_path) { + size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2 + + strlen(plug_name) + 1; + + if (!strstr(inst_path, ".blender")) { + len += strlen(".blender") + strlen(PATH_SEP); + } + + plug_path = MEM_mallocN(len, "ndofpluginpath"); + if (plug_path) { + strncpy(plug_path, inst_path, len); + strcat(plug_path, PATH_SEP); + if (!strstr(inst_path, ".blender")) { + strcat(plug_path, ".blender"); + strcat(plug_path, PATH_SEP); + } + strcat(plug_path, plug_dir); + strcat(plug_path, PATH_SEP); + strcat(plug_path, plug_name); + } + } + + ndofLib = PIL_dynlib_open(plug_path); + }*/ + + + +#if 1 + fprintf(stderr, "plugin path=%s; ndofLib=%p\n", plug_path, (void*)ndofLib); +#endif + + if (plug_path) + MEM_freeN(plug_path); + + if (ndofLib) { + G.ndofdevice = 0 - GHOST_OpenNDOF(g_system, ghostwin , + PIL_dynlib_find_symbol(ndofLib, "ndofInit"), + PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"), + PIL_dynlib_find_symbol(ndofLib, "ndofOpen")); + + } else { + GHOST_OpenNDOF(g_system, ghostwin, 0, 0, 0); + G.ndofdevice = -1; + } + } + + /* belongs to below */ static void wm_window_add_ghostwindow(bContext *C, const char *title, wmWindow *win) { @@ -329,6 +420,7 @@ 0 /* no AA */); if (ghostwin) { + /* needed so we can detect the graphics card below */ GPU_extensions_init(); @@ -340,7 +432,13 @@ if(win->eventstate==NULL) win->eventstate= MEM_callocN(sizeof(wmEvent), "window event state"); - + + //if (initial_state != GHOST_kWindowStateNormal) { + // begin ndof + wm_open_ndof(C, ghostwin); + //} + + /* until screens get drawn, make it nice grey */ glClearColor(.55, .55, .55, 0.0); /* Crash on OSS ATI: bugs.launchpad.net/ubuntu/+source/mesa/+bug/656100 */ @@ -759,7 +857,34 @@ } break; } - + + case GHOST_kEventNDOFMotion: { + // update ndof device data, and dispatch motion event + + GHOST_TEventNDOFData *sb= data; + + // no scaling per sfgoros patch + + win->ndof[0] = sb->tx; + win->ndof[1] = sb->ty; + win->ndof[2] = sb->tz; + win->ndof[3] = sb->rx; + win->ndof[4] = sb->ry; + win->ndof[5] = sb->rz; + win->ndof[6] = sb->delta; + //printf(" motion capted %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f \n", win->ndof[0], win->ndof[1], win->ndof[2], + // win->ndof[3], win->ndof[4], win->ndof[5], win->ndof[6]); + + wm_event_add_ghostevent(wm, win, type, time, data); + wm_window_make_drawable(C, win); + WM_event_add_notifier(C, NC_WINDOW, NULL); + //window_handle(win, NDOFMOTION, 1); + //printf("ok\n"); + // } + + break; + } + case GHOST_kEventOpenMainFile: { PointerRNA props_ptr; @@ -943,16 +1068,18 @@ /* **************** init ********************** */ + void wm_ghost_init(bContext *C) { if (!g_system) { GHOST_EventConsumerHandle consumer= GHOST_CreateEventConsumer(ghost_event_proc, C); g_system= GHOST_CreateSystem(); - GHOST_AddEventConsumer(g_system, consumer); + GHOST_AddEventConsumer(g_system, consumer); } } + void wm_ghost_exit(void) { if(g_system) @@ -1186,3 +1313,9 @@ } } +void WM_get_ndof(wmWindow* win, float* sbval) { + int i; + for (i = 0; i < 7; ++i) { + *sbval++ = win->ndof[i]; + } +} Index: source/blender/windowmanager/intern/wm_event_system.c =================================================================== --- source/blender/windowmanager/intern/wm_event_system.c (revisão 33984) +++ source/blender/windowmanager/intern/wm_event_system.c (cópia de trabalho) @@ -2243,7 +2243,7 @@ /* windows store own event queues, no bContext here */ /* time is in 1000s of seconds, from ghost */ -void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int UNUSED(time), void *customdata) +void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int time, void *customdata) { wmWindow *owin; wmEvent event, *evt= win->eventstate; @@ -2252,6 +2252,38 @@ event= *evt; switch (type) { + + /* ndof */ + case GHOST_kEventNDOFMotion:{ + + View3D *v3d = NULL; + ScrArea *sa = NULL; + ARegion *arTmp = NULL; + ARegion *ar = NULL; + ScrArea *saFound = NULL; + RegionView3D *rv3d = NULL; + Scene *scene = win->screen->scene; + + for(sa= win->screen->areabase.first; sa; sa= sa->next) { + SpaceLink *sl; + for(sl= sa->spacedata.first; sl; sl= sl->next) { + if(sl->spacetype==SPACE_VIEW3D) { + v3d= (View3D*) sl; + saFound = sa; + } + } + } + + for(arTmp=saFound->regionbase.first; arTmp; arTmp= arTmp->next) { + if(arTmp->regiontype == RGN_TYPE_WINDOW) { + ar = arTmp; + } + } + rv3d = ar->regiondata; + viewmoveNDOF(scene, ar, v3d, 0, win); + + break; + } /* mouse move */ case GHOST_kEventCursorMove: { if(win->active) { Index: source/blender/windowmanager/WM_api.h =================================================================== --- source/blender/windowmanager/WM_api.h (revisão 33984) +++ source/blender/windowmanager/WM_api.h (cópia de trabalho) @@ -343,6 +343,7 @@ /* progress */ void WM_progress_set(struct wmWindow *win, float progress); void WM_progress_clear(struct wmWindow *win); +void WM_get_ndof(wmWindow* win, float* sbval); #ifdef WIN32 /* Windows System Console */ Index: source/blender/windowmanager/wm_event_types.h =================================================================== --- source/blender/windowmanager/wm_event_types.h (revisão 33984) +++ source/blender/windowmanager/wm_event_types.h (cópia de trabalho) @@ -41,6 +41,7 @@ #define EVT_DATA_TIMER 3 #define EVT_DATA_LISTBASE 4 + /* tablet active, matches GHOST_TTabletMode */ #define EVT_TABLET_NONE 0 #define EVT_TABLET_STYLUS 1 @@ -84,6 +85,10 @@ #define TIMERJOBS 0x0114 /* timer event, internal use */ #define TIMERAUTOSAVE 0x0115 /* timer event, internal use */ +/* N-degre of freedom device : 500 */ +#define NDOFMOTION 500 +#define NDOFBUTTON 501 + /* standard keyboard */ #define AKEY 'a' #define BKEY 'b' Index: source/blender/editors/space_view3d/view3d_edit.c =================================================================== --- source/blender/editors/space_view3d/view3d_edit.c (revisão 33984) +++ source/blender/editors/space_view3d/view3d_edit.c (cópia de trabalho) @@ -2727,8 +2727,12 @@ // 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 +void getndof(float *sbval, wmWindow *win) +{ + //winlay_process_events(0); + WM_get_ndof(win, sbval); +} - float ndof_axis_scale[6] = { +0.01, // Tx +0.01, // Tz @@ -2758,7 +2762,7 @@ int dz_flag = 0; float m_dist; -void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int UNUSED(mode)) +void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int UNUSED(mode), wmWindow *win) { RegionView3D *rv3d= ar->regiondata; int i; @@ -2780,16 +2784,17 @@ // fetch the current state of the ndof device -// XXX getndof(dval); + getndof(dval, win); - if (v3d->ndoffilter) + + if (v3d->ndoffilter) filterNDOFvalues(fval); // Scale input values // if(dval[6] == 0) return; // guard against divide by zero - for(i=0;i<6;i++) { + for(i=0;i<6;i++) { // user scaling dval[i] = dval[i] * ndof_axis_scale[i]; @@ -2811,7 +2816,7 @@ // until the first draw and doesn't update the menu // to reflect persp mode. - rv3d->persp = RV3D_PERSP; + rv3d->persp = RV3D_PERSP; // Correct the distance jump if rv3d->dist != 0 @@ -2826,16 +2831,16 @@ // movement devices must subtract this from their // view transformations. - if(rv3d->dist != 0.0) { + if(rv3d->dist != 0.0) { dz_flag = 1; m_dist = rv3d->dist; upvec[0] = upvec[1] = 0; upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - sub_v3_v3(rv3d->ofs, upvec); - rv3d->dist = 0.0; - } + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + sub_v3_v3(rv3d->ofs, upvec); + //rv3d->dist = 0.0; + } // Apply rotation @@ -2856,7 +2861,9 @@ phi = normalize_v3(rvec); if(phi != 0) { axis_angle_to_quat(q1,rvec,phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + printf("\n quat: %f %f %f %f \n", q1[0],q1[1],q1[2],q1[3]); + // + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); } @@ -2875,7 +2882,7 @@ // translate the view - sub_v3_v3(rv3d->ofs, tvec); + sub_v3_v3(rv3d->ofs, tvec); /*---------------------------------------------------- @@ -2887,10 +2894,12 @@ // XXX BIF_view3d_previewrender_signal(ar, PR_DBASE|PR_DISPRECT); } -void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int UNUSED(mode)) + + +void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int UNUSED(mode), wmWindow *win) { - RegionView3D *rv3d= ar->regiondata; - float fval[7]; + RegionView3D *rv3d= ar->regiondata; + float fval[7]; float dvec[3]; float sbadjust = 1.0f; float len; @@ -2958,7 +2967,7 @@ // sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */ /* fetch the current state of the ndof device & enforce dominant mode if selected */ -// XXX getndof(fval); + getndof(fval, win); if (v3d->ndoffilter) filterNDOFvalues(fval); @@ -3089,7 +3098,7 @@ /*---------------------------------------------------- * refresh the screen */ -// XXX scrarea_do_windraw(curarea); + // scrarea_do_windraw(curarea); } /* give a 4x4 matrix from a perspective view, only needs viewquat, ofs and dist Index: source/blender/editors/include/ED_view3d.h =================================================================== --- source/blender/editors/include/ED_view3d.h (revisão 33984) +++ source/blender/editors/include/ED_view3d.h (cópia de trabalho) @@ -172,5 +172,8 @@ unsigned int ED_viewedit_datamask(struct bScreen *screen); +void viewmoveNDOF(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode, struct wmWindow *win); +void viewmoveNDOFfly(struct ARegion *ar, struct View3D *v3d, int mode, struct wmWindow *win); + #endif /* ED_VIEW3D_H */