void CHapticViewerView::updateGLView(Mesh* pMesh)
{
    wglMakeCurrent(m_hDC,m_hRC);

    static const double kPI = 3.1415926535897932384626433832795;
    static const double kFovY = 50;
    
    glViewport(0, 0, m_windowWidth, m_windowHeight);

    // Compute the viewing parameters based on a fixed fov and viewing
    // a canonical [-1..1] box centered at the origin.
    const double halfBox = 1.0;

    double nearDist = halfBox/tan((kFovY / 2.0) * kPI / 180.0);
    double farDist = nearDist + 2*halfBox;
    double aspect = (double) m_windowWidth / m_windowHeight;

    // Move near dist back to avoid clipping front face.
    nearDist *= 0.9;
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
        
    gluPerspective(kFovY, aspect, nearDist, farDist);

    m_cameraPosWC[0] = 0;
    m_cameraPosWC[1] = 0;
    m_cameraPosWC[2] = nearDist + halfBox;
        
    updateGLCamera();

    updateWorkspace();
}
예제 #2
0
/*******************************************************************************
 GLUT callback for reshaping the window.  This is the main place where the
 viewing and workspace transforms get initialized.
*******************************************************************************/
void glutReshape(int width, int height)
{
    static const double kPI = 3.1415926535897932384626433832795;
    static const double kFovY = 40;
    double nearDist, farDist, aspect;

    glViewport(0, 0, width, height);

// Compute the viewing parameters based on a fixed fov and viewing
// a canonical box centered at the origin.

    nearDist = 1.0 / tan((kFovY / 2.0) * kPI / 180.0);
    farDist = nearDist + 2.0;
    aspect = (double) width / height;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45, aspect, 0.1, farDist);

// Place the camera down the Z axis looking at the origin.

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(0, 0, -1.0+farDist,
        0, 0, 0,
        0, 1, 0);

    updateWorkspace();
}
예제 #3
0
/*******************************************************************************
 The main routine for displaying the scene.  Gets the latest snapshot of state
 from the haptic thread and uses it to display a 3D cursor.
*******************************************************************************/
void drawSceneGraphics()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

// place camera/eye
    glTranslatef(xTranslate ,yTranslate ,zDepth);
    glRotatef(-yRotation, 1.0,0.0,0.0);
    glRotatef(-xRotation, 0.0,1.0,0.0);
    glDisable(GL_TEXTURE_2D);

    drawCursor();

    glEnable(GL_TEXTURE_2D);
    glPushMatrix();
    glCallList(objList);                      //Displays regular OBJ model

//	glCallList(bumpList); //Displays displacement mapped OBJ model
    glPopMatrix();

//Uncomment to see the Entry Point
    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT);
    glDisable(GL_TEXTURE_2D);
    glPushMatrix();
    glPointSize(15.0);
    glTranslatef(0.0, 0.0, 1.0);
    glBegin(GL_POINTS);
    glEnable(GL_COLOR_MATERIAL);
    glColor3f(0.0,0.0,1.0);
    glVertex3f(0.05,-0.175,0.975);
    glEnd();

    glPopMatrix();
    glPopAttrib();
    DisplayInfo();
    glEnable(GL_TEXTURE_2D);
    updateWorkspace();
}
void CHapticViewerView::OnMButtonUp(UINT nFlags, CPoint point)
{
    m_isTranslatingCamera = false;
    updateWorkspace();
}
void CHapticViewerView::OnRButtonUp(UINT nFlags, CPoint point)
{
    m_isScalingCamera = false;
    updateWorkspace();
}
예제 #6
0
파일: HapticsSim.cpp 프로젝트: EQ4/dimple
void HapticsSim::step()
{
    cMeta3dofPointer *cursor = m_cursor->object();
    cursor->updatePose();

    cVector3d pos = cursor->m_deviceGlobalPos;
    updateWorkspace(pos);

    pos.copyto(cursor->m_deviceGlobalPos);
    pos.copyto(m_cursor->m_position);
    cursor->m_deviceGlobalVel.copyto(m_cursor->m_velocity);

    if (m_pGrabbedObject) {
        cursor->m_lastComputedGlobalForce.set(0,0,0);
        m_cursor->addCursorGrabbedForce(m_pGrabbedObject);
    } else {
        cursor->computeForces();
        m_cursor->addCursorMassForce();
    }

    m_cursor->addCursorExtraForce();

    cursor->applyForces();

    m_counter++;

    int update_sim = Simulation::ST_VISUAL;
    if (m_pGrabbedObject)
        update_sim |= Simulation::ST_PHYSICS;

    if (update_sim)
    {
        /* If in contact with an object, display the cursor at the
         * proxy location instead of the device location, so that it
         * does not show it penetrating the object. */
        cProxyPointForceAlgo *algo =
            (cProxyPointForceAlgo*) cursor->m_pointForceAlgos[0];
        if (algo->getContactObject())
            pos = algo->getProxyGlobalPosition();

        sendtotype(update_sim, true,
                   "/world/cursor/position","fff",
                   pos.x, pos.y, pos.z);
    }

    findContactObject();

    if (m_pContactObject) {
        sendtotype(Simulation::ST_PHYSICS, true,
                   (m_pContactObject->path()+"/push").c_str(), "ffffff",
                   -m_lastForce.x,
                   -m_lastForce.y,
                   -m_lastForce.z,
                   m_lastContactPoint.x,
                   m_lastContactPoint.y,
                   m_lastContactPoint.z);

        bool co1 = m_pContactObject->collidedWith(m_cursor, m_counter);
        bool co2 = m_cursor->collidedWith(m_pContactObject, m_counter);
        if ( (co1 || co2) && m_collide.m_value ) {
            lo_send(address_send, "/world/collide", "ssf",
                    m_pContactObject->c_name(), m_cursor->c_name(),
                    (double)(m_pContactObject->m_velocity
                             - m_cursor->m_velocity).length());
        }
    }
}