示例#1
0
HAPIForceEffect::EffectOutput 
OpenHapticsRenderer::renderHapticsOneStep( 
                     HAPIHapticsDevice *hd,
                     const HapticShapeVector &shapes ) {
  PhantomHapticsDevice *pd = dynamic_cast< PhantomHapticsDevice * >( hd );
  if( !pd ) {
    AnyHapticsDevice *d = dynamic_cast< AnyHapticsDevice *>( hd );
    if( d ) {
      pd = dynamic_cast< PhantomHapticsDevice * >( d->getActualHapticsDevice() );
    }
    if( !pd ) return HAPIForceEffect::EffectOutput();
  }

  hdMakeCurrentDevice( pd->getDeviceHandle() );

  // add the resulting force and torque to the rendered force.
  HDdouble force[3];
  hdGetDoublev( HD_CURRENT_FORCE, force );
  
  HDdouble torque[3];
  hdGetDoublev( HD_CURRENT_TORQUE, torque );

  // add the resulting force and torque to the rendered force.
  // The force and torque from the haptics device is in local coordinates.
  // We want it in global coordinates.
  Matrix3 pos_matrix_rotation = hd->getPositionCalibration().getRotationPart();
  return HAPIForceEffect::EffectOutput( 
    pos_matrix_rotation * Vec3( force[0], force[1], force[2] ),
    pos_matrix_rotation * Vec3( torque[0], torque[1], torque[2] ) );
}
示例#2
0
HHLRC OpenHapticsRenderer::initHLLayer( HAPIHapticsDevice *hd ) {
  PhantomHapticsDevice *pd = dynamic_cast< PhantomHapticsDevice * >( hd );
  if( !pd ) {
    AnyHapticsDevice *d = dynamic_cast< AnyHapticsDevice *>( hd );
    if( d ) {
      pd = dynamic_cast< PhantomHapticsDevice * >( d->getActualHapticsDevice() );
    }
    if( !pd ) return NULL;
  }

  if( pd->getDeviceState() != HAPIHapticsDevice::UNINITIALIZED ) {
    if( context_map.find( pd ) == context_map.end() ) {
      // Create a haptic context for the device. The haptic context maintains 
      // the state that persists between frame intervals and is used for
      // haptic rendering.
      HHD jj = pd->getDeviceHandle();
      // The check of no_context and scheduler started is used to get
      // around a problem with openhaptics if the scheduler is started
      // before a hlcontext is created. Has to be made this way (only once)
      // in order to not get strange behaviour when using dual device setup.
      bool restart = false;
      if( PhantomHapticsDevice::isSchedulerStarted() && nr_of_context == 0 ) {
        PhantomHapticsDevice::stopScheduler();
        restart = true;
      }
      context_map[ pd ] = hlCreateContext( jj );
      if( restart ) {
        PhantomHapticsDevice::startScheduler();
      }
      ++nr_of_context;

      if( !dummy_context ) {
        dummy_context = hlCreateContext( jj );
        ++nr_of_context;
      }
      hlMakeCurrent( context_map[ pd ] );

      hlEnable(HL_HAPTIC_CAMERA_VIEW);
      hlEnable(HL_ADAPTIVE_VIEWPORT );
      return context_map[ pd ];
    }
  }
  return NULL;
}