/******************************************************************************* Main function. *******************************************************************************/ int main(int argc, char *argv[]) { HHD hHD; HHLRC hHLRC; HDErrorInfo error; HLuint friction, spring; HLerror frameError; hHD = hdInitDevice(HD_DEFAULT_DEVICE); if (HD_DEVICE_ERROR(error = hdGetError())) { hduPrintError(stderr, &error, "Failed to initialize haptic device"); fprintf(stderr, "\nPress any key to quit.\n"); getch(); return -1; } hdMakeCurrentDevice(hHD); hHLRC = hlCreateContext(hHD); hlMakeCurrent(hHLRC); hlDisable(HL_USE_GL_MODELVIEW); spring = hlGenEffects(1); /* Add a callback to handle button down in the collision thread. */ hlAddEventCallback(HL_EVENT_1BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, buttonCB, &spring); hlAddEventCallback(HL_EVENT_1BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, buttonCB, &spring); hlAddEventCallback(HL_EVENT_2BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, buttonCB, 0); /* Start an ambient friction effect. */ friction = hlGenEffects(1); hlBeginFrame(); hlEffectd(HL_EFFECT_PROPERTY_GAIN, 0.2); hlEffectd(HL_EFFECT_PROPERTY_MAGNITUDE, 0.5); hlStartEffect(HL_EFFECT_FRICTION, friction); hlEndFrame(); printf("Move around to feel the ambient stick-slip friction.\n\n"); printf("Press and hold the primary stylus button to feel the spring effect.\n\n"); printf("Press the second stylus button to trigger an impulse.\n\n"); /* Run the main loop. */ while (!_kbhit()) { hlBeginFrame(); /* Poll for events. Note that client thread event callbacks get dispatched from within a frame here, so we can safely start/stop effects from the event callback directly */ hlCheckEvents(); hlEndFrame(); /* Check for any errors. */ while (HL_ERROR(frameError = hlGetError())) { fprintf(stderr, "HL Error: %s\n", frameError.errorCode); if (frameError.errorCode == HL_DEVICE_ERROR) { hduPrintError(stderr, &frameError.errorInfo, "Error during haptic rendering\n"); } } } /* Stop the friction effect. */ hlBeginFrame(); hlStopEffect(friction); hlEndFrame(); hlDeleteEffects(friction, 1); hlDeleteEffects(spring, 1); hlDeleteContext(hHLRC); hdDisableDevice(hHD); return 0; }
/******************************************************************************* Main function. *******************************************************************************/ int main(int argc, char *argv[]) { HHD hHD; HHLRC hHLRC; HDErrorInfo error; HLuint spring; /* The code snippet provided to you by SensAble should be executed near application startup. Once a deployment license has been validated, it will remain in effect until the application is shutdown. Be sure to place the HD deployment license code before the call to hdInitDevice, and the HL deployment license code before the call to hlCreateContext. NOTE THAT THE FOLLOWING IS FOR DEMONSTRATION ONLY. THE LICENSES ARE NOT VALID. */ hdDeploymentLicense( "ABC Software, Inc.", "HapticsGold", "F1312D97ECCC754D5BE4BEE7E831BC27ACF809E9B850D9576F1A856AF70DD3A879B4D3DC7F922BDB2C639DA4A565CA5FC598D8AF34EA010B13A8C232B78F22C"); hlDeploymentLicense( "ABC Software, Inc.", "HapticsGold", "A653A1EEAFF7B87C952754672FDB1AA16A9035ADE1CFCA6394FE869BAFECE0B7A32251502DDF220B7BA27979695041AE59DCEA007605027D471801F4BF26C24"); hHD = hdInitDevice(HD_DEFAULT_DEVICE); if (HD_DEVICE_ERROR(error = hdGetError())) { hduPrintError(stderr, &error, "Failed to initialize haptic device"); fprintf(stderr, "\nPress any key to quit.\n"); getch(); return -1; } hdMakeCurrentDevice(hHD); hHLRC = hlCreateContext(hHD); hlMakeCurrent(hHLRC); hlDisable(HL_USE_GL_MODELVIEW); spring = hlGenEffects(1); // Add a callback to handle button down in the collision thread. hlAddEventCallback(HL_EVENT_1BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, buttonCB, &spring); hlAddEventCallback(HL_EVENT_1BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, buttonCB, &spring); printf("Press and hold the primary stylus button to feel the spring effect.\n"); printf("Press any key to quit.\n\n"); // Run the main loop. while (!_kbhit()) { hlBeginFrame(); // Poll for events. Note that client thread event callbacks get // dispatched from within a frame here, so we can safely start/stop // effects from the event callback directly. hlCheckEvents(); hlEndFrame(); } hlDeleteEffects(spring, 1); hlDeleteContext(hHLRC); hdDisableDevice(hHD); return 0; }
//******************************************************************************* HapticEffect::HapticEffect(HLenum type) : m_EffectID(hlGenEffects(1)) { m_EffectType = type; m_IsActive = false; }