comparison src/haptic/win32/SDL_syshaptic.c @ 2606:bb175d957174 gsoc2008_force_feedback

Some correctness, especially on axes.
author Edgar Simo <bobbens@gmail.com>
date Tue, 05 Aug 2008 16:33:50 +0000
parents 0ea3be6e81a7
children e0ca521516f6
comparison
equal deleted inserted replaced
2605:0ea3be6e81a7 2606:bb175d957174
64 * Haptic system hardware data. 64 * Haptic system hardware data.
65 */ 65 */
66 struct haptic_hwdata 66 struct haptic_hwdata
67 { 67 {
68 LPDIRECTINPUTDEVICE2 device; 68 LPDIRECTINPUTDEVICE2 device;
69 DWORD axes[3];
69 /* DIDEVCAPS capabilities; */ 70 /* DIDEVCAPS capabilities; */
70 }; 71 };
71 72
72 73
73 /* 74 /*
231 { 232 {
232 SDL_Haptic *haptic = (SDL_Haptic *) pvRef; 233 SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
233 234
234 if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) { 235 if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
235 236
237 haptic->hwdata->axes[haptic->naxes] = dev->dwOfs;
236 haptic->naxes++; 238 haptic->naxes++;
237 239
238 /* Currently using the artificial limit of 3 axes. */ 240 /* Currently using the artificial limit of 3 axes. */
239 if (haptic->naxes >= 3) { 241 if (haptic->naxes >= 3) {
240 return DIENUM_STOP; 242 return DIENUM_STOP;
343 if (FAILED(ret)) { 345 if (FAILED(ret)) {
344 DI_SetError("Resetting device",ret); 346 DI_SetError("Resetting device",ret);
345 goto acquire_err; 347 goto acquire_err;
346 } 348 }
347 349
348
349 /* Enabling actuators. */ 350 /* Enabling actuators. */
350 ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device, 351 ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
351 DISFFC_SETACTUATORSON ); 352 DISFFC_SETACTUATORSON );
352 if (FAILED(ret)) { 353 if (FAILED(ret)) {
353 DI_SetError("Enabling actuators",ret); 354 DI_SetError("Enabling actuators",ret);
372 dipdw.diph.dwObj = 0; 373 dipdw.diph.dwObj = 0;
373 dipdw.diph.dwHow = DIPH_DEVICE; 374 dipdw.diph.dwHow = DIPH_DEVICE;
374 dipdw.dwData = 10000; 375 dipdw.dwData = 10000;
375 ret = IDirectInputDevice2_SetProperty( haptic->hwdata->device, 376 ret = IDirectInputDevice2_SetProperty( haptic->hwdata->device,
376 DIPROP_FFGAIN, &dipdw.diph ); 377 DIPROP_FFGAIN, &dipdw.diph );
377 if (FAILED(ret)) { 378 if (!FAILED(ret)) { /* Gain is supported. */
378 if (ret != DIERR_UNSUPPORTED) {
379 DI_SetError("Checking gain",ret);
380 goto acquire_err;
381 }
382 }
383 else { /* Gain is supported. */
384 haptic->supported |= SDL_HAPTIC_GAIN; 379 haptic->supported |= SDL_HAPTIC_GAIN;
385 } 380 }
386 dipdw.diph.dwObj = 0; 381 dipdw.diph.dwObj = 0;
387 dipdw.diph.dwHow = DIPH_DEVICE; 382 dipdw.diph.dwHow = DIPH_DEVICE;
388 dipdw.dwData = DIPROPAUTOCENTER_OFF; 383 dipdw.dwData = DIPROPAUTOCENTER_OFF;
389 ret = IDirectInputDevice2_SetProperty( haptic->hwdata->device, 384 ret = IDirectInputDevice2_SetProperty( haptic->hwdata->device,
390 DIPROP_AUTOCENTER, &dipdw.diph ); 385 DIPROP_AUTOCENTER, &dipdw.diph );
391 if (FAILED(ret)) { 386 if (!FAILED(ret)) { /* Autocenter is supported. */
392 if (ret != DIERR_UNSUPPORTED) {
393 DI_SetError("Checking autocenter",ret);
394 goto acquire_err;
395 }
396 }
397 else { /* Autocenter is supported. */
398 haptic->supported |= SDL_HAPTIC_AUTOCENTER; 387 haptic->supported |= SDL_HAPTIC_AUTOCENTER;
399 } 388 }
400
401 389
402 /* Check maximum effects. */ 390 /* Check maximum effects. */
403 haptic->neffects = 128; /* TODO actually figure this out. */ 391 haptic->neffects = 128; /* TODO actually figure this out. */
404 haptic->nplaying = 128; 392 haptic->nplaying = 128;
405
406 393
407 /* Prepare effects memory. */ 394 /* Prepare effects memory. */
408 haptic->effects = (struct haptic_effect *) 395 haptic->effects = (struct haptic_effect *)
409 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); 396 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
410 if (haptic->effects == NULL) { 397 if (haptic->effects == NULL) {
632 axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); 619 axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
633 if (axes == NULL) { 620 if (axes == NULL) {
634 SDL_OutOfMemory(); 621 SDL_OutOfMemory();
635 return -1; 622 return -1;
636 } 623 }
637 axes[0] = DIJOFS_X; /* Always at least one axis. */ 624 axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
638 if (dest->cAxes > 1) { 625 if (dest->cAxes > 1) {
639 axes[1] = DIJOFS_Y; 626 axes[1] = haptic->hwdata->axes[1];
640 } 627 }
641 if (dest->cAxes > 2) { 628 if (dest->cAxes > 2) {
642 axes[2] = DIJOFS_Z; 629 axes[2] = haptic->hwdata->axes[2];
643 } 630 }
644 dest->rgdwAxes = axes; 631 dest->rgdwAxes = axes;
645 } 632 }
646 633
647 634