/******************************************************************************* 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(); }
int CHapticViewerView::drawSceneGL(Mesh* pObj, bool isHapticView) { int triCount = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glMultMatrixd(pObj->transform); hduVector3Dd* currFrustum = m_graphicFrustum; if (isHapticView) { // haptic render pass if (!m_bSinglePassRender) { getViewVolumeInModelCoord(m_hapticCameraFrustum); if (m_bHapticCameraView) currFrustum = m_hapticCameraFrustum; if (!m_bShapeDepthBuffer) { // FEEDBACK_BUFFER shape, // count number of tris and send hint int triCount = pObj->numTri(currFrustum); hlHinti(HL_SHAPE_FEEDBACK_BUFFER_VERTICES, triCount*3); } } } glEnable(GL_COLOR_MATERIAL); glColor3f(0.5, 0.5, 0.5); triCount = pObj->drawGL(currFrustum); glPopMatrix(); return triCount; }
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(); }