Esempio n. 1
0
/*******************************************************************************
 Use the current OpenGL viewing transforms to initialize a transform for the
 haptic device workspace so that it's properly mapped to world coordinates.
*******************************************************************************/
void updateWorkspace()
{
    GLdouble modelview[16];
    GLdouble projection[16];
    GLint viewport[4];

//	HLdouble minn[3]={-0.5,-0.5, 0.5};
//	HLdouble maxx[3]={0.5,0.35,1.5};

    HLdouble minn[3]={-0.4,-0.5, -0.4};
    HLdouble maxx[3]={0.4,0.5,0.4};

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    hlMatrixMode(HL_TOUCHWORKSPACE);
    hlLoadIdentity();
    hluFitWorkspaceBox(modelview, minn, maxx);

// Compute cursor scale.
    gCursorScale = hluScreenToModelScale(modelview, projection, viewport);
    gCursorScale *= CURSOR_SIZE_PIXELS;
    hlMatrixMode(HL_MODELVIEW);
    hlLoadMatrixd(modelview);
}
Esempio n. 2
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);
}
void CHapticViewerView::updateWorkspace()
{
    GLdouble modelview[16];
    GLdouble projection[16];
    GLint viewport[4];

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    hlMatrixMode(HL_TOUCHWORKSPACE);
    hlLoadIdentity();
    
    // Fit haptic workspace to view volume.
    hluFitWorkspace(projection);

    // Compute cursor scale.
    m_cursorScale = hluScreenToModelScale(modelview, projection, viewport);
    m_cursorScale *= CURSOR_SIZE_PIXELS;
}
Esempio n. 4
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; 
	
	}
Esempio n. 5
0
/*
 	Function:	UpdateHapticMapping
 	Usage:		UpdateHapticMapping(); 
 	---------------------------------------------------------------------------
 Use the current OpenGL viewing transforms to initialize a transform for the
 haptic device workspace so that it's properly mapped to world coordinates.
 */
void UpdateHapticMapping(void)
{
    GLdouble modelview[16];
    GLdouble projection[16];
    GLint viewport[4];

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    hlMatrixMode(HL_TOUCHWORKSPACE);
    hlLoadIdentity();
    
    /* fit haptic workspace to the bound of the deformable surface */
    hduVector3Dd minPt(-kSurfaceSize / 2.0, -kSurfaceSize / 2.0, -kSurfaceSize / 2.0);
    hduVector3Dd maxPt(kSurfaceSize / 2.0, kSurfaceSize / 2.0, kSurfaceSize / 2.0);
    hluFitWorkspaceBox(modelview, minPt, maxPt);

    /* compute cursor scale */
    mCursorScale = hluScreenToModelScale(modelview, projection, viewport);
    const int CURSOR_SIZE_PIXELS = 20;
    mCursorScale *= CURSOR_SIZE_PIXELS;
}