void CybPhantom::HLIdleFunc() { HLerror error; while (HL_ERROR(error = hlGetError())) { fprintf(stderr, "Error: %s\n", error.errorCode); if (error.errorCode == HL_DEVICE_ERROR) { hduPrintError(stderr, &error.errorInfo, "Error during haptic rendering\n"); } } if(cybCore->phantomOn && !flagWorkspaceUpdate){ hapticWorkspaceCalibration(); flagWorkspaceUpdate = true; } else if(!cybCore->phantomOn) { flagWorkspaceUpdate = false; } }
//******************************************************************************* void HapticEffect::stopEffect() { if (m_IsActive) { hlStopEffect(m_EffectID); if (HL_INVALID_OPERATION == hlGetError().errorCode) { // nur zum Debuggen benötigt int bla = 1; } m_IsActive = false; } }
/******************************************************************************* GLUT callback for idle state. Use this as an opportunity to request a redraw. Checks for HLAPI errors that have occurred since the last idle check. *******************************************************************************/ void glutIdle() { HLerror error; while (HL_ERROR(error = hlGetError())) { fprintf(stderr, "HL Error: %s\n", error.errorCode); if (error.errorCode == HL_DEVICE_ERROR) { hduPrintError(stderr, &error.errorInfo, "Error during haptic rendering\n"); } } glutPostRedisplay(); }
//******************************************************************************* void HapticEffect::startEffect() { if (m_IsActive) { return; } // Effekt mit den in der abstrakten Methode renderProperties() spezifizierten // Eigenschaften starten renderProperties(); hlStartEffect(m_EffectType, m_EffectID); if (!(HL_NO_ERROR == hlGetError().errorCode)) { // nur zum Debuggen benötigt int bla = 1; } m_IsActive = true; }
/******************************************************************************* GLUT callback for idle state. Use this as an opportunity to request a redraw. Checks for HLAPI errors that have occurred since the last idle check. *******************************************************************************/ void glutIdle() { HLerror error; while (HL_ERROR(error = hlGetError())) { fprintf(stderr, "HL Error: %s\n", error.errorCode); if (error.errorCode == HL_DEVICE_ERROR) { hduPrintError(stderr, &error.errorInfo, "Error during haptic rendering\n"); } } char title[40]; sprintf(title, "Haptic Displacement Mapping %4.1f fps", DetermineFPS()); glutSetWindowTitle(title); glutPostRedisplay(); }
/******************************************************************************* 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; }