/* Function: InitHL Usage: InitHL(); --------------------------------------------------------------------------- Initializes haptic device and haptic rendering library. */ void InitHL() { HDErrorInfo error; 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); } // Create a haptic context for the device. The haptic context maintains // the state that persists between frame intervals and is used for // haptic rendering. hHLRC = hlCreateContext(hHD); hlMakeCurrent(hHLRC); // generate a shape id to hold the haptic surface rep mSurfaceShapeId = hlGenShapes(1); // add a callback to handle motion while touching surface hlAddEventCallback(HL_EVENT_TOUCH, mSurfaceShapeId, HL_CLIENT_THREAD, OnTouchSurface, NULL); hlAddEventCallback(HL_EVENT_UNTOUCH, mSurfaceShapeId, HL_CLIENT_THREAD, OnTouchSurface, NULL); // set motion tolerance to 0 so we get motion event when // when not moving. hlEventd(HL_EVENT_MOTION_LINEAR_TOLERANCE, 0); hlAddEventCallback(HL_EVENT_MOTION, mSurfaceShapeId, HL_CLIENT_THREAD, OnDragSurface, NULL); }
void CybPhantom::genShapeIdList(int num) { shapeId = new HLuint[num]; for(int i = 0; i < num; i++){ shapeId[i] = hlGenShapes(1); } }
//******************************************************************************* HapticObject::HapticObject() : m_HLShapeID(hlGenShapes(1)) { // defaultmäßig ein Constraint definieren, aber deaktivieren m_pHapticConstraint = new HapticConstraint(1.0); m_pHapticConstraint->disable(); // Position beim Erzeugen des Objektes ist immer [0.0, 0.0, 0.0] m_transformMatrix.makeIdentity(); }
/******************************************************************************* Initialize the HDAPI. This involves initing a device configuration, enabling forces, and scheduling a haptic thread callback for servicing the device. *******************************************************************************/ void initHL() { HDErrorInfo error; ghHD = 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); } /************************************************************* ADDED *************************************************************/ hdScheduleAsynchronous(hdBeginCB, 0, HD_MAX_SCHEDULER_PRIORITY); hdScheduleAsynchronous(hdEndCB, 0, HD_MIN_SCHEDULER_PRIORITY); /************************************************************* END ADDED *************************************************************/ ghHLRC = hlCreateContext(ghHD); hlMakeCurrent(ghHLRC); // Enable optimization of the viewing parameters when rendering // geometry for OpenHaptics. hlEnable(HL_HAPTIC_CAMERA_VIEW); // Generate id for the shape. gShapeId = hlGenShapes(1); gPointId = hlGenShapes(1); hlTouchableFace(HL_FRONT); hlAddEventCallback(HL_EVENT_TOUCH,gPointId , HL_COLLISION_THREAD, hlTouchCB, 0); hlAddEventCallback(HL_EVENT_UNTOUCH,gPointId , HL_COLLISION_THREAD, hlUnTouchCB, 0); }
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); }
RigidBody::RigidBody(const char *name) : massInv(0), x(0,0,0), q(), P(0,0,0), L(0,0,0), v(0,0,0), omega(0,0,0), force(0,0,0), torque(0,0,0) { zeroMatrix(Ibody); zeroMatrix(Ibodyinv); zeroMatrix(Iinv); zeroMatrix(R); setName(name); shapeId = hlGenShapes(1); }
//******************************************************************************* HapticConstraint::HapticConstraint( HLfloat snapDist ) : m_HLConstraintID(hlGenShapes(1)) { m_SnapDistance = snapDist; m_Enabled = true; }
/******************************************************************************* Initialize the HDAPI. This involves initing a device configuration, enabling forces, and scheduling a haptic thread callback for servicing the device. *******************************************************************************/ void initHL() { HDErrorInfo error; 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); } hHLRC = hlCreateContext(hHD); hlMakeCurrent(hHLRC); // Enable optimization of the viewing parameters when rendering // geometry for OpenHaptics. hlEnable(HL_HAPTIC_CAMERA_VIEW); // Generate id's for the three shapes. gSphereShapeId = hlGenShapes(1); gTorusShapeId = hlGenShapes(1); gTeapotShapeId = hlGenShapes(1); // Setup event callbacks. hlAddEventCallback(HL_EVENT_TOUCH, HL_OBJECT_ANY, HL_CLIENT_THREAD, &touchShapeCallback, NULL); hlAddEventCallback(HL_EVENT_UNTOUCH, HL_OBJECT_ANY, HL_CLIENT_THREAD, &untouchShapeCallback, NULL); hlAddEventCallback(HL_EVENT_TOUCH, gSphereShapeId, HL_CLIENT_THREAD, &touchSphereCallback, NULL); hlAddEventCallback(HL_EVENT_UNTOUCH, gSphereShapeId, HL_CLIENT_THREAD, &untouchSphereCallback, NULL); hlAddEventCallback(HL_EVENT_TOUCH, gTorusShapeId, HL_CLIENT_THREAD, &touchTorusCallback, NULL); hlAddEventCallback(HL_EVENT_UNTOUCH, gTorusShapeId, HL_CLIENT_THREAD, &untouchTorusCallback, NULL); hlAddEventCallback(HL_EVENT_TOUCH, gTeapotShapeId, HL_CLIENT_THREAD, &touchTeapotCallback, NULL); hlAddEventCallback(HL_EVENT_UNTOUCH, gTeapotShapeId, HL_CLIENT_THREAD, &untouchTeapotCallback, NULL); hlAddEventCallback(HL_EVENT_1BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button1DownCallback, NULL); hlAddEventCallback(HL_EVENT_1BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button1UpCallback, NULL); hlAddEventCallback(HL_EVENT_2BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button2DownCallback, NULL); hlAddEventCallback(HL_EVENT_2BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button2UpCallback, NULL); hlAddEventCallback(HL_EVENT_3BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button3DownCallback, NULL); hlAddEventCallback(HL_EVENT_3BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, &button3UpCallback, NULL); hlAddEventCallback(HL_EVENT_1BUTTONDOWN, gSphereShapeId, HL_CLIENT_THREAD, &button1DownSphereCallback, NULL); hlAddEventCallback(HL_EVENT_1BUTTONUP, gSphereShapeId, HL_CLIENT_THREAD, &button1UpSphereCallback, NULL); hlAddEventCallback(HL_EVENT_MOTION, HL_OBJECT_ANY, HL_CLIENT_THREAD, &motionCallback, NULL); hlAddEventCallback(HL_EVENT_MOTION, gSphereShapeId, HL_CLIENT_THREAD, &motionOnSphereCallback, NULL); hlAddEventCallback(HL_EVENT_CALIBRATION_UPDATE, HL_OBJECT_ANY, HL_CLIENT_THREAD, &calibrationCallback, NULL); hlAddEventCallback(HL_EVENT_CALIBRATION_INPUT, HL_OBJECT_ANY, HL_CLIENT_THREAD, &calibrationCallback, NULL); }