Example #1
0
/*******************************************************************************
 The main routine for rendering scene haptics.
*******************************************************************************/
void drawSceneHaptics()
{
    hlGetDoublev(HL_PROXY_TOUCH_NORMAL, proxyNormal);
    hlGetDoublev(HL_PROXY_POSITION, proxyPosition);

// Start haptic frame.  (Must do this before rendering any haptic shapes.)
    hlBeginFrame();
    hlPushMatrix();
    hlTouchModel(HL_CONTACT);

// Set material properties for the shapes to be drawn.
    hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, 0.9f);
    hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, 0.0f);
    hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, 0.1);
    hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION,0.1 );
    hlHinti(HL_SHAPE_FEEDBACK_BUFFER_VERTICES, objmodel->numvertices);
    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gShapeId);

// Render haptic shape
    glPushMatrix();
    glCallList(bumpList);
    glPopMatrix();

// End the shape.
    hlEndShape();
    hlPopMatrix();
    hlPushMatrix();
    hlTouchModel(HL_CONSTRAINT);
    hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, 0.4f);
    hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, 0.3f);
    hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, 0.1);
    hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION,0.1 );

    if (touchedHole && force[2] > -0.1 )
    {
        hlTouchModelf(HL_SNAP_DISTANCE, 300.0);
    }
    else
    {
        hlTouchModelf(HL_SNAP_DISTANCE, 3.0);
    }

    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gPointId);
    glPushMatrix();
    glPointSize(5.0);
    glTranslatef(0.0, 0.0, 1.0);
    glBegin(GL_POINTS);
    glVertex3f(0.05,-0.175,-0.975);
    glEnd();

    glPopMatrix();
    hlEndShape();
    hlPopMatrix();

// End the haptic frame.
    hlEndFrame();
}
Example #2
0
	HDCallbackCode HDCALLBACK CybPhantom::calibrationServoLoop(void *pUserData)
	{
		CalibrationState *state = (CalibrationState *) pUserData;
	
		hlBeginFrame();
		state->calibrationStatus = hdCheckCalibration();
		hlEndFrame();
	
		return HD_CALLBACK_DONE;
	}
CProtoHapticDoc::~CProtoHapticDoc()
{	
	// Render an empty scene and syc, so that shape callbacks
	// (which access shape data about to be deleted) are not called by rendering thread
	// after data has been deleted by client thread
	hlBeginFrame ();
	hlEndFrame ();

	clean();
	//dWorldDestroy(m_worldID);
	//dSpaceDestroy(m_spaceID);
}
Example #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();

}
BOOL CProtoHapticDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	
	POSITION pos = GetFirstViewPosition();
	while (pos != NULL)
	{
		CView* pView = GetNextView(pos);
		((CProtoHapticView*)pView)->Pause();
		((CProtoHapticView*)pView)->Deselect();
	}

	// Render an empty scene and syc, so that shape callbacks
	// (which access shape data about to be deleted) are not called by rendering thread
	// after data has been deleted by client thread
	hlBeginFrame ();
	hlEndFrame ();

	clean(); //Destroy existing document

	m_shapeCount= 0;
	m_memoCount= 0;
	m_historyCount= 0;
	m_gravity= 0;
	m_airResistance= 0.5;
	m_simSpeed= 0.3;

	OutputDebugString("NewDocument");

	//dWorldDestroy(m_worldID);
	//dSpaceDestroy(m_spaceID);
	m_worldID= dWorldCreate();
	m_spaceID= dHashSpaceCreate( 0 );

	pos = GetFirstViewPosition();
	while (pos != NULL)
	{
		CView* pView = GetNextView(pos);
		((CProtoHapticView*)pView)->Play();
	}

	return TRUE;
}
int CHapticViewerView::drawSceneHL(Mesh* pObj)
{
    int triDrawCount = 0;
 
    hlBeginFrame();
    
    hlCheckEvents();

    HLboolean buttDown;
    hlGetBooleanv(HL_BUTTON1_STATE, &buttDown);

    if (buttDown && pObj->isDragging)
    {
        updateDragObjectTransform(pObj);
    }
        
    if (m_bHapticCameraView)
        hlEnable(HL_HAPTIC_CAMERA_VIEW);
    else
        hlDisable(HL_HAPTIC_CAMERA_VIEW);
    
    if (m_bHapticAdaptiveViewport)
        hlEnable(HL_ADAPTIVE_VIEWPORT);
    else
        hlDisable(HL_ADAPTIVE_VIEWPORT);
    
    if (m_bShapeDepthBuffer)
        hlBeginShape(HL_SHAPE_DEPTH_BUFFER, pObj->shapeId);
    else
        hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, pObj->shapeId);
    
    const bool isHapticView = true;
    triDrawCount = drawSceneGL(pObj, isHapticView);
    
    hlEndShape();

    hlEndFrame();
    
    return triDrawCount;
}
Example #7
0
void Window::hapticRendering()
{
	hlBeginFrame();

	hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, haptic.getStiffness());
	hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, haptic.getDamping());
	hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, haptic.getStaticFriction());
	hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, haptic.getDynamicFriction());
	hlMaterialf(HL_FRONT_AND_BACK, HL_POPTHROUGH, haptic.getPopthroughValue());

	hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, haptic.getShapeID());
	//vertexArrayObject.bind();
	shaderProgram->bind();
	shaderProgram->setUniformValue("translateFactor", -1.0f, -1.0f, 0.0f);
	shaderProgram->setUniformValue("mvp", QMatrix4x4(glm::value_ptr(mvp)));
	glDrawElements(GL_TRIANGLES, mesh->getNumberOfIndices(), GL_UNSIGNED_INT,
		0);
	//vertexArrayObject.release();
	shaderProgram->release();
	hlEndShape();

	hlEndFrame();
}
Example #8
0
void display(void) 
{
    // Start a haptic frame.
    hlBeginFrame();
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    
    // Start the haptic shape.
    hlBeginShape(HL_SHAPE_DEPTH_BUFFER, gMyShapeId);
    glBegin(GL_POLYGON);
    glVertex3f(0.25, 0.25, 0.0);
    glVertex3f(0.75, 0.25, 0.0);
    glVertex3f(0.75, 0.75, 0.0);
    glVertex3f(0.25, 0.75, 0.0);
    glEnd();
    
    // End the haptic shape.
    hlEndShape();
    
    // End the haptic frame.
    hlEndFrame();
}
Example #9
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();
}
void CProtoHapticDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar << m_shapeCount;
		int i;
		for (i= 0; i<m_shapeCount; i++) {
			ar << m_shapes[i]->getType();
			m_shapes[i]->Serialize(ar);
		}

		ar << m_memoCount;
		for (i= 0; i<m_memoCount; i++) {
			m_memos[i]->Serialize(ar);
		}
		ar << m_simSpeed
		   << m_airResistance
		   << m_gravity;
		if(m_hideMemos) ar << 1; else ar << 0;

		if(m_dynamicSurfaceChange) ar << 1; else ar << 0;
	}
	else
	{
		POSITION pos = GetFirstViewPosition();
		while (pos != NULL)
		{
			CView* pView = GetNextView(pos);
			((CProtoHapticView*)pView)->Pause();
			((CProtoHapticView*)pView)->Deselect();
			((CProtoHapticView*)pView)->Play();
		}
		
		// Render an empty scene and syc, so that shape callbacks
		// (which access shape data about to be deleted) are not called by rendering thread
		// after data has been deleted by client thread
		hlBeginFrame ();
		hlEndFrame ();

		clean(); //Destroy existing document

		m_historyCount= 0;
		m_shapeCount= 0;
		m_memoCount= 0;

		dWorldDestroy(m_worldID);
		m_worldID= dWorldCreate();

		//dSpaceDestroy(m_spaceID);
		m_spaceID= dHashSpaceCreate(0);

		int count;
		ar >> count;
		int i;
		for (i= 0; i<count; i++)
		{	
			int shapeType;
			CShape* s= NULL;
			ar >> shapeType;
			if(shapeType==SHAPE_CUBE)		s= new CCube(1,1,1);
			if(shapeType==SHAPE_SPHERE)		s= new CSphere(1,1,1);
			if(shapeType==SHAPE_CYLINDER)	s= new CCylinder(1,1,1);
			if(shapeType==SHAPE_COMPOSITE)	s= new CComposite();
			if(shapeType==SHAPE_TRIANGLE)	s= new CTriangle();
			if(shapeType==SHAPE_TORUS)		s= new CTorus();
			
			// Unknown shape type
			if ( s == NULL )
			{
				MessageBox ( 0, "There was an error whilst reading the specified file: Unknown Shape.", "Error", MB_OK );
				return;
			}
			else
			{
				s->Serialize(ar);
				AddShape(s);
			}
		}

		ar >> count;
		for(i= 0; i<count; i++)
		{
			CMemo* m;
			m= new CMemo();
			m->Serialize(ar);
			addMemo(m);
		}
		ar >> m_simSpeed
		   >> m_airResistance
		   >> m_gravity;
		ar >> i;
		if(i==1) 
			m_hideMemos= true; 
		else 
			m_hideMemos= false;

		// Dynamic surface change in view mode (Version > 4)
		ar >> i;
		if(i==1) 
			m_dynamicSurfaceChange= true; 
		else 
			m_dynamicSurfaceChange= false;

		pos = GetFirstViewPosition();
		while (pos != NULL)
		{
			CView* pView = GetNextView(pos);
			((CProtoHapticView*)pView)->CenterCamera();
		} 
	}
}
Example #11
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();
	}
Example #12
0
/*******************************************************************************
 Main function.
*******************************************************************************/
int main(int argc, char *argv[])
{
    HHD hHD;
    HHLRC hHLRC;
    HDErrorInfo error;
    HLuint spring;

    /* The code snippet provided to you by SensAble should be executed near 
       application startup.  Once a deployment license has been validated, 
       it will remain in effect until the application is shutdown.
    
       Be sure to place the HD deployment license code before the call 
       to hdInitDevice, and the HL deployment license code before the call 
       to hlCreateContext.
     
       NOTE THAT THE FOLLOWING IS FOR DEMONSTRATION ONLY. THE LICENSES 
       ARE NOT VALID. */

    hdDeploymentLicense(
        "ABC Software, Inc.",
        "HapticsGold",
        "F1312D97ECCC754D5BE4BEE7E831BC27ACF809E9B850D9576F1A856AF70DD3A879B4D3DC7F922BDB2C639DA4A565CA5FC598D8AF34EA010B13A8C232B78F22C");

    hlDeploymentLicense(
        "ABC Software, Inc.",
        "HapticsGold",
        "A653A1EEAFF7B87C952754672FDB1AA16A9035ADE1CFCA6394FE869BAFECE0B7A32251502DDF220B7BA27979695041AE59DCEA007605027D471801F4BF26C24");

    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);

    printf("Press and hold the primary stylus button to feel the spring effect.\n");
    printf("Press any key to quit.\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();
    }

    hlDeleteEffects(spring, 1);

    hlDeleteContext(hHLRC);
    hdDisableDevice(hHD);

    return 0;
}
/*******************************************************************************
 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;
}