void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); // Enable depth buffering to provide depth information for OpenHaptics. glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); // OpenHaptics setup follows: // Create a haptic device instance. HDErrorInfo error; HHD hHD = hdInitDevice(HD_DEFAULT_DEVICE); if (HD_DEVICE_ERROR(error = hdGetError())) { hduPrintError(stderr, &error, "Failed to initialize haptic device"); fprintf(stderr, "Press any key to exit"); getchar(); exit(-1); } if (HD_SUCCESS != hdGetError().errorCode) { fprintf(stderr, "Erorr initializing haptic device.\nPress any key to exit"); getchar(); exit(-1); } // Create a haptic rendering context and activate it. HHLRC hHLRC = hlCreateContext(hHD); hlMakeCurrent(hHLRC); // Reserve an id for the shape gMyShapeId = hlGenShapes(1); // Specify the boundaries for the workspace of the haptic device // in millimeters in the cordinates of the haptic device. // The haptics engine will map the view volume to this workspace hlWorkspace (-80, -80, -70, 80, 80, 20); // Specify the haptic view volume (in this case it will be // the same as the graphic view volume). hlMatrixMode(HL_TOUCHWORKSPACE); hlLoadIdentity(); hlOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0); }
void CybPhantom::hapticWorkspaceCalibration() { GLdouble projection[16]; GLdouble modelview[16]; GLint viewport[4]; glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetIntegerv(GL_VIEWPORT, viewport); hlWorkspace(-90,-60,-50,90,60,50); hlMatrixMode(HL_TOUCHWORKSPACE); hduMapWorkspaceModel(modelview, projection, workspacemodel); /* Compute the scale needed to display the cursor of a particular size in screen coordinates. */ scaleFactor = hduScreenToWorkspaceScale(modelview, projection, viewport, workspacemodel); scaleFactor *= cursor_size_pixel; }