void CHapticViewerView::initHL()
{
    HDErrorInfo error;
    m_hHD = hdInitDevice(HD_DEFAULT_DEVICE);
    if (HD_DEVICE_ERROR(error = hdGetError()))
    {
        char errorMsg[500];
        sprintf(errorMsg,
                "HD error %s\nHHD: %X\nError Code: %X\nInternalErrorCode: %d\n%s\n",
                hdGetErrorString(error.errorCode),
                error.hHD,
                error.errorCode,
                error.internalErrorCode,
                "Failed to initialize haptic device");
        MessageBox(errorMsg);
        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.
    m_hHLRC = hlCreateContext(m_hHD);
    hlMakeCurrent(m_hHLRC); 

    hlTouchableFace(HL_FRONT);
}
示例#2
0
	int CybPhantom::initHL()
	{
		//TODO HABILITAR O OUTPUT FORCE NA HD.

		HDErrorInfo error;
	
		hapticDevice = hdInitDevice(HD_DEFAULT_DEVICE);
		if(HD_DEVICE_ERROR(error = hdGetError()))
		{
			//Falta tratar o erro!
			hduPrintError(stderr, &error, "Failed to initialize haptic device");
			return -1;
		}

		checkCalibrationStatus(&stateCalibration);	
	
		hapticContext = hlCreateContext(hapticDevice);
		hlMakeCurrent(hapticContext);
	
		hlTouchableFace(HL_FRONT_AND_BACK);
	
		hlEnable(HL_HAPTIC_CAMERA_VIEW);

		//hlEnable(HL_ADAPTIVE_VIEWPORT);
	
		//hdEnable(HD_FORCE_OUTPUT);

		return 0;
	}
示例#3
0
/*******************************************************************************
 The main routine for haptically rendering the scene.
*******************************************************************************/
void drawSceneHaptics()
{
    hlBeginFrame();
    
    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gSphereShapeId);
    hlTouchableFace(HL_FRONT);
    drawSphere();
    hlEndShape();

    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gTorusShapeId);
    hlTouchableFace(HL_FRONT);
    drawTorus();
    hlEndShape();

    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gTeapotShapeId);
    hlTouchableFace(HL_BACK);
    drawTeapot();
    hlEndShape();

    hlEndFrame();

    // Call any event callbacks that have been triggered.
    hlCheckEvents();
}
示例#4
0
/* redisplaying graphics */
void Display(void)
{
    hlBeginFrame();

    hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, 0.1);
    hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, 0.8);

    hlCheckEvents();

	/* clear the display */
	//glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//materialsTest();

	if (mDrawSurface)
		mSurface.DrawSurface();

    // draw the haptic surface
    hlHintb(HL_SHAPE_DYNAMIC_SURFACE_CHANGE, HL_TRUE);
    hlTouchableFace(HL_BACK);
    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, mSurfaceShapeId);
        mSurface.DrawSurface();
    hlEndShape();
	
	glDisable(GL_LIGHTING);

	if (mDrawSystem)
		mPS.Draw();

	if (mDrawNormals)
		mSurface.DrawSurfaceNormals();

	glEnable(GL_LIGHTING);

    // draw the 3D cursor
    RedrawCursor();

	// show FPS
	if (mDrawInfo != drawInfo_None)
		DisplayInfo();

	// swap the double buffers
	glutSwapBuffers();  

    hlEndFrame();

}
示例#5
0
/*******************************************************************************
 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);
}
示例#6
0
	void CybPhantom::hapticRendering()
	{
		if(!shapeIdListIscreated)
		{
			genShapeIdList(cybCore->numLayer);
			shapeIdListIscreated = true;
		}
	
		if(habHapticLayers == NULL)
		{
			cout<<"Message Error: Haptic Layer don't exist!"<<endl;
		}
		else{
			hlBeginFrame();
	
			glPushMatrix();
	
			//cout << "Haptic layers " << numHapticLayers << endl;
			for(int j = 0; j < numHapticLayers; j++){

				if(habHapticLayers[j] == true){
	

					glTranslated(cybCore->xTrans + cybCore->layerTrans[j][0], cybCore->yTrans + cybCore->layerTrans[j][1], cybCore->zTrans + cybCore->layerTrans[j][2]);
					glScaled(cybCore->xScale * cybCore->layerSca[j][0], cybCore->yScale * cybCore->layerSca[j][1], cybCore->zScale * cybCore->layerSca[j][2]);

					glTranslated(cybCore->cX, cybCore->cY, cybCore->cZ);
					glRotated(cybCore->getXAngle() + cybCore->layerRot[j][0],1,0,0);
					glRotated(cybCore->getYAngle() + cybCore->layerRot[j][1],0,1,0);
					glRotated(cybCore->getZAngle() + cybCore->layerRot[j][2],0,0,1);
					glTranslated(-cybCore->cX, -cybCore->cY, -cybCore->cZ);


					if(materialPropertiesIsEnable){
	
						if(cybCore->materialPropertyContextCreated() && cybCore->propertyFaceModified())
							updateHapticsFaces();
	
						if(habHapticLayersMaterial == NULL)
						{
							cout<<"Message Error: Material context don't exist!"<<endl;
						}
						else{
							if(habHapticLayersMaterial[j] == true){		
								hlMaterialf(propertyFace[j][0], HL_STIFFNESS, cybCore->getMaterialPropertyValue(j, STIFFNESS));
	
								hlMaterialf(propertyFace[j][1], HL_DAMPING, cybCore->getMaterialPropertyValue(j, DAMPING));
	
								hlMaterialf(propertyFace[j][2], HL_STATIC_FRICTION, cybCore->getMaterialPropertyValue(j, STATIC_FRICTION));
	
								hlMaterialf(propertyFace[j][3], HL_DYNAMIC_FRICTION, cybCore->getMaterialPropertyValue(j, DYNAMIC_FRICTION));
	
								if(ambientPropertyIsEnable){
									hlMaterialf(HL_FRONT_AND_BACK, HL_POPTHROUGH,1);
								}
								else{
									hlMaterialf(propertyFace[j][4], HL_POPTHROUGH,cybCore->getMaterialPropertyValue(j, POPTHROUGH));
								}
							}
						}
					}
	
	
					hlHinti(HL_SHAPE_FEEDBACK_BUFFER_VERTICES, cybCore->nv[j]);				  
					hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, shapeId[j]);
	
					if(ambientPropertyIsEnable)
						hlTouchableFace(CybViscosity::ViscosityShapeAttribute[j].currentFace);
					else hlTouchableFace(HL_FRONT_AND_BACK);
	
					CybVector3D<float> v1;
	
	
					for(int i = 0; i < cybCore->nt[j]; i++){
	
						glBegin(GL_TRIANGLES);
	
						v1 = cybCore->vNormalCell[j][i];
						glNormal3f(v1[0], v1[1], v1[2]);
	
						v1 = cybCore->coordList[j][cybCore->v[j][i][0]];
						glVertex3f(v1[0], v1[1], v1[2]);
	
						v1 = cybCore->coordList[j][cybCore->v[j][i][1]];
						glVertex3f(v1[0], v1[1], v1[2]);
	
						v1 = cybCore->coordList[j][cybCore->v[j][i][2]];
						glVertex3f(v1[0], v1[1],v1[2]);		  
	
						glEnd();
						glFlush();
					}
	
					hlEndShape();
	

				}
	
				glLoadIdentity();
			}
	
			glPopMatrix();
			hlEndFrame();
		}
		hlCheckEvents();
	}