forked from bartvdbraak/blender
more work on the ndof system.
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
This commit is contained in:
parent
288e07b649
commit
bfa77f611f
@ -137,7 +137,8 @@ typedef enum {
|
|||||||
GHOST_kEventButtonUp, /// Mouse button event
|
GHOST_kEventButtonUp, /// Mouse button event
|
||||||
GHOST_kEventWheel, /// Mouse wheel 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_kEventKeyDown,
|
||||||
GHOST_kEventKeyUp,
|
GHOST_kEventKeyUp,
|
||||||
|
@ -984,7 +984,7 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
|
|||||||
GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
|
GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
|
||||||
if (::TrackGoAway(window, mousePos))
|
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) {
|
// if (event.modifiers & optionKey) {
|
||||||
// Close the clean documents, others will be confirmed one by one.
|
// 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;
|
OSStatus err = eventNotHandledErr;
|
||||||
GHOST_IWindow* window;
|
GHOST_IWindow* window;
|
||||||
GHOST_TEventNDOFData data;
|
GHOST_TEventNDOFData data;
|
||||||
|
UInt32 kind;
|
||||||
|
|
||||||
switch (::GetEventClass(event))
|
switch (::GetEventClass(event))
|
||||||
{
|
{
|
||||||
@ -1090,7 +1091,19 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
|
|||||||
case kEventClassBlender :
|
case kEventClassBlender :
|
||||||
window = sys->m_windowManager->getActiveWindow();
|
window = sys->m_windowManager->getActiveWindow();
|
||||||
sys->m_ndofManager->GHOST_NDOFGetDatas(data);
|
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;
|
err = noErr;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
@ -462,25 +462,21 @@ GHOST_SystemX11::processEvent(XEvent *xe)
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (sNdofInfo.currValues) {
|
if (sNdofInfo.currValues) {
|
||||||
sNdofInfo.currValues->changed = 1;
|
GHOST_TEventNDOFData data;
|
||||||
sNdofInfo.currValues->delta = xcme.data.s[8] - sNdofInfo.currValues->time;
|
data.changed = 1;
|
||||||
sNdofInfo.currValues->time = xcme.data.s[8];
|
data.delta = xcme.data.s[8] - data.time;
|
||||||
sNdofInfo.currValues->tx = xcme.data.s[2] >> 4;
|
data.time = xcme.data.s[8];
|
||||||
sNdofInfo.currValues->ty = xcme.data.s[3] >> 4;
|
data.tx = xcme.data.s[2] >> 4;
|
||||||
sNdofInfo.currValues->tz = xcme.data.s[4] >> 4;
|
data.ty = xcme.data.s[3] >> 4;
|
||||||
sNdofInfo.currValues->rx = xcme.data.s[5];
|
data.tz = xcme.data.s[4] >> 4;
|
||||||
sNdofInfo.currValues->ry = xcme.data.s[6];
|
data.rx = xcme.data.s[5];
|
||||||
sNdofInfo.currValues->rz = xcme.data.s[7];
|
data.ry = xcme.data.s[6];
|
||||||
|
data.rz = xcme.data.s[7];
|
||||||
|
|
||||||
/*fprintf(stderr, "ClientMessage: [%d %d %d][%d %d %d] t=%llu\n",
|
g_event = new GHOST_EventNDOF(getMilliSeconds(),
|
||||||
sNdofInfo.currValues->tx, sNdofInfo.currValues->ty,
|
GHOST_kEventNDOFMotion,
|
||||||
sNdofInfo.currValues->tz, sNdofInfo.currValues->rx,
|
window, data);
|
||||||
sNdofInfo.currValues->ry, sNdofInfo.currValues->rz,
|
|
||||||
sNdofInfo.currValues->time); */
|
|
||||||
|
|
||||||
g_event = new GHOST_EventNDOF(getMilliSeconds(),
|
|
||||||
GHOST_kEventNDOFMotion,
|
|
||||||
window, *sNdofInfo.currValues);
|
|
||||||
} else {
|
} else {
|
||||||
/* Unknown client message, ignore */
|
/* Unknown client message, ignore */
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ void sdrawbox(short x1, short y1, short x2, short y2);
|
|||||||
void calctrackballvecfirst(struct rcti *area, short *mval, float *vec);
|
void calctrackballvecfirst(struct rcti *area, short *mval, float *vec);
|
||||||
void calctrackballvec(struct rcti *area, short *mval, float *vec);
|
void calctrackballvec(struct rcti *area, short *mval, float *vec);
|
||||||
void viewmove(int mode);
|
void viewmove(int mode);
|
||||||
|
void viewmoveNDOFfly(int mode);
|
||||||
void viewmoveNDOF(int mode);
|
void viewmoveNDOF(int mode);
|
||||||
|
|
||||||
int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
|
int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
|
|
||||||
/* N-degre of freedom device : 500 */
|
/* N-degre of freedom device : 500 */
|
||||||
#define NDOFMOTION 500
|
#define NDOFMOTION 500
|
||||||
|
#define NDOFBUTTON 501
|
||||||
|
|
||||||
/* standard keyboard */
|
/* standard keyboard */
|
||||||
|
|
||||||
|
@ -139,7 +139,8 @@ typedef struct View3D {
|
|||||||
|
|
||||||
short snap_target;
|
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 */
|
void *properties_storage; /* Nkey panel stores stuff here, not in file */
|
||||||
|
|
||||||
|
@ -586,7 +586,13 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
|
|||||||
;
|
;
|
||||||
break;
|
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: {
|
case GHOST_kEventCursorMove: {
|
||||||
if(win->active == 1) {
|
if(win->active == 1) {
|
||||||
GHOST_TEventCursorData *cd= data;
|
GHOST_TEventCursorData *cd= data;
|
||||||
|
@ -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)");
|
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)) {
|
if (ob && (ob->flag & OB_POSEMODE)) {
|
||||||
xco+= XIC/2;
|
xco+= XIC/2;
|
||||||
uiBlockBeginAlign(block);
|
uiBlockBeginAlign(block);
|
||||||
|
@ -1567,10 +1567,29 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
|||||||
doredraw= 1;
|
doredraw= 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NDOFMOTION:
|
case NDOFMOTION:
|
||||||
viewmoveNDOF(1);
|
if (G.vd->ndofmode == 0) {
|
||||||
|
viewmoveNDOF(1);
|
||||||
|
} else if (G.vd->ndofmode == 1) {
|
||||||
|
viewmoveNDOFfly(1);
|
||||||
|
} else {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
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:
|
case ONEKEY:
|
||||||
if(G.qual==LR_CTRLKEY) {
|
if(G.qual==LR_CTRLKEY) {
|
||||||
flip_subdivison(1);
|
flip_subdivison(1);
|
||||||
@ -2584,6 +2603,7 @@ static void initview3d(ScrArea *sa)
|
|||||||
vd->gridflag &= ~V3D_SHOW_Z;
|
vd->gridflag &= ~V3D_SHOW_Z;
|
||||||
|
|
||||||
vd->depths= NULL;
|
vd->depths= NULL;
|
||||||
|
vd->ndofmode=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -726,9 +726,9 @@ static void transformEvent(unsigned short event, short val) {
|
|||||||
else view_editmove(event);
|
else view_editmove(event);
|
||||||
Trans.redraw= 1;
|
Trans.redraw= 1;
|
||||||
break;
|
break;
|
||||||
case NDOFMOTION:
|
// case NDOFMOTION:
|
||||||
viewmoveNDOF(0);
|
// viewmoveNDOF(1);
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
Trans.redraw |= handleNumInput(&(Trans.num), event);
|
Trans.redraw |= handleNumInput(&(Trans.num), event);
|
||||||
Trans.redraw |= handleSnapping(&Trans, event);
|
Trans.redraw |= handleSnapping(&Trans, event);
|
||||||
@ -1075,9 +1075,9 @@ void ManipulatorTransform()
|
|||||||
case RETKEY:
|
case RETKEY:
|
||||||
Trans.state = TRANS_CONFIRM;
|
Trans.state = TRANS_CONFIRM;
|
||||||
break;
|
break;
|
||||||
case NDOFMOTION:
|
// case NDOFMOTION:
|
||||||
viewmoveNDOF(0);
|
// viewmoveNDOF(1);
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
if(val) {
|
if(val) {
|
||||||
switch(event) {
|
switch(event) {
|
||||||
|
@ -545,13 +545,24 @@ void calctrackballvec(rcti *area, short *mval, float *vec)
|
|||||||
// can be increased for improved response from
|
// can be increased for improved response from
|
||||||
// small deflections of the device input.
|
// 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] = {
|
float ndof_axis_scale[6] = {
|
||||||
+2.0, // Tx
|
+0.01, // Tx
|
||||||
+2.0, // Tz
|
+0.01, // Tz
|
||||||
+2.0, // Ty
|
+0.01, // Ty
|
||||||
+0.25, // Rx
|
+0.0015, // Rx
|
||||||
+0.25, // Rz
|
+0.0015, // Rz
|
||||||
+0.25 // Ry
|
+0.0015 // Ry
|
||||||
};
|
};
|
||||||
|
|
||||||
// statics for controlling G.vd->dist corrections.
|
// statics for controlling G.vd->dist corrections.
|
||||||
@ -563,10 +574,20 @@ float m_dist;
|
|||||||
|
|
||||||
void getndof(float *sbval);
|
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 viewmoveNDOFfly(int mode)
|
||||||
void viewmoveNDOF(int mode)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float phi;
|
float phi;
|
||||||
@ -589,16 +610,18 @@ void viewmoveNDOF(int mode)
|
|||||||
// fetch the current state of the ndof device
|
// fetch the current state of the ndof device
|
||||||
getndof(dval);
|
getndof(dval);
|
||||||
|
|
||||||
for(i=0;i<7;i++) printf("%f ",dval[i]);
|
if (G.vd->ndoffilter)
|
||||||
printf("\n");
|
filterNDOFvalues(fval);
|
||||||
|
|
||||||
|
// for(i=0;i<7;i++) printf("%f ",dval[i]);
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
|
||||||
// Scale input values
|
// 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++) {
|
for(i=0;i<6;i++) {
|
||||||
dval[i] = dval[i] / dval[6]; // this should be moved to device specific
|
|
||||||
|
|
||||||
// user scaling
|
// user scaling
|
||||||
dval[i] = dval[i] * ndof_axis_scale[i];
|
dval[i] = dval[i] * ndof_axis_scale[i];
|
||||||
@ -695,7 +718,6 @@ void viewmoveNDOF(int mode)
|
|||||||
/*----------------------------------------------------
|
/*----------------------------------------------------
|
||||||
* refresh the screen
|
* refresh the screen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
scrarea_do_windraw(curarea);
|
scrarea_do_windraw(curarea);
|
||||||
screen_swapbuffers();
|
screen_swapbuffers();
|
||||||
|
|
||||||
@ -704,8 +726,6 @@ void viewmoveNDOF(int mode)
|
|||||||
BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
|
BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void viewmove(int mode)
|
void viewmove(int mode)
|
||||||
{
|
{
|
||||||
Object *ob = OBACT;
|
Object *ob = OBACT;
|
||||||
@ -994,10 +1014,6 @@ void viewmove(int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef USE_NEW_NDOFMOVE
|
|
||||||
|
|
||||||
|
|
||||||
void viewmoveNDOF(int mode)
|
void viewmoveNDOF(int mode)
|
||||||
{
|
{
|
||||||
static double prevTime = 0.0;
|
static double prevTime = 0.0;
|
||||||
@ -1057,19 +1073,31 @@ void viewmoveNDOF(int mode)
|
|||||||
|
|
||||||
/* fetch the current state of the ndof device */
|
/* fetch the current state of the ndof device */
|
||||||
getndof(fval);
|
getndof(fval);
|
||||||
// printf(" motion command %f %f %f %f %f %f %f \n", fval[0], fval[1], fval[2],
|
// 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]);
|
// fval[3], fval[4], fval[5], fval[6]);
|
||||||
|
if (G.vd->ndoffilter)
|
||||||
|
filterNDOFvalues(fval);
|
||||||
|
|
||||||
|
|
||||||
// put scaling back here, was previously in ghostwinlay
|
// put scaling back here, was previously in ghostwinlay
|
||||||
fval[0] = fval[0] * (1.0f/1024.0f);
|
fval[0] = fval[0] * (1.0f/1024.0f);
|
||||||
fval[1] = fval[1] * (1.0f/1024.0f);
|
fval[1] = fval[1] * (1.0f/1024.0f);
|
||||||
fval[2] = fval[2] * (1.0f/1024.0f);
|
fval[2] = fval[2] * (1.0f/1024.0f);
|
||||||
fval[3] = fval[3] * 0.00003f;
|
fval[3] = fval[3] * 0.00005f;
|
||||||
fval[4] = fval[4] * 0.00003f;
|
fval[4] = fval[4] * 0.00005f;
|
||||||
fval[5] = fval[5] * 0.00003f;
|
fval[5] = fval[5] * 0.00005f;
|
||||||
fval[6] = fval[6] / 1000000.0f;
|
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 */
|
/* set object offset */
|
||||||
if (ob) {
|
if (ob) {
|
||||||
@ -1169,7 +1197,6 @@ void viewmoveNDOF(int mode)
|
|||||||
screen_swapbuffers();
|
screen_swapbuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Gets the lens and clipping values from a camera of lamp type object */
|
/* Gets the lens and clipping values from a camera of lamp type object */
|
||||||
|
Loading…
Reference in New Issue
Block a user