Ejemplo n.º 1
0
/*
 * Class:     visad_java3d_TrackdJNI
 * Method:    get_trackd_c
 * Signature: ([I[F[F[F[I[I)V
 */
  JNIEXPORT void JNICALL Java_visad_java3d_TrackdJNI_get_1trackd_1c
    (JNIEnv *env, jobject obj, jintArray number_of_sensors_j,
     jfloatArray sensor_positions_j, jfloatArray sensor_angles_j,
     jfloatArray sensor_matrices_j, jintArray number_of_buttons_j,
     jintArray button_states_j) {

     int ns, nb, is, ib, i, j, k;
     float pos[3];
     float mat[4][4];

     jint *number_of_sensors =
       (*env)->GetIntArrayElements(env, number_of_sensors_j, 0);
     jfloat *sensor_positions =
       (*env)->GetFloatArrayElements(env, sensor_positions_j, 0);
     jfloat *sensor_angles =
       (*env)->GetFloatArrayElements(env, sensor_angles_j, 0);
     jfloat *sensor_matrices =
       (*env)->GetFloatArrayElements(env, sensor_matrices_j, 0);
     jint *number_of_buttons =
       (*env)->GetIntArrayElements(env, number_of_buttons_j, 0);
     jint *button_states =
       (*env)->GetIntArrayElements(env, button_states_j, 0);

     ns = trackdGetNumberOfSensors(tracker);
     if (ns > number_of_sensors[0]) ns = number_of_sensors[0];
     number_of_sensors[0] = ns;
     for (is=0; is<ns; is++) {
       trackdGetPosition(tracker, is, pos);
       sensor_positions[3*is] = pos[0];
       sensor_positions[3*is+1] = pos[1];
       sensor_positions[3*is+2] = pos[2];
       trackdGetEulerAngles(tracker, is, pos);
       sensor_angles[3*is] = pos[0];
       sensor_angles[3*is+1] = pos[1];
       sensor_angles[3*is+2] = pos[2];
       trackdGetMatrix(tracker, is, mat);
       k = 0;
       for (i=0; i<4; i++) {
         for (j=0; j<4; j++) {
           sensor_matrices[16*is+k] = mat[i][j];
           k++;
         }
       }
     }

     nb = trackdGetNumberOfButtons(controller);
     if (nb > number_of_buttons[0]) nb = number_of_buttons[0];
     number_of_buttons[0] = nb;
     for (ib=0; ib<nb; ib++) {
       button_states[ib] = trackdGetButton(controller, ib);
     }
     (*env)->ReleaseIntArrayElements(env, number_of_sensors_j, number_of_sensors, 0);
     (*env)->ReleaseFloatArrayElements(env, sensor_positions_j, sensor_positions, 0);
     (*env)->ReleaseFloatArrayElements(env, sensor_angles_j, sensor_angles, 0);
     (*env)->ReleaseFloatArrayElements(env, sensor_matrices_j, sensor_matrices, 0);
     (*env)->ReleaseIntArrayElements(env, number_of_buttons_j, number_of_buttons, 0);
     (*env)->ReleaseIntArrayElements(env, button_states_j, button_states, 0);
  }
Ejemplo n.º 2
0
void
TrackDClient::pollForInput(Array<EventRef> &events) 
{
  // Update trackers
  for (int i=0;i<iMin(_numSensors, _tEventNames.size());i++) {
    float tracker[6];
    trackdGetPosition(_trackerMemory, i, &(tracker[0]));
    trackdGetEulerAngles(_trackerMemory, i, &(tracker[3]));
  
    Vector3 trans(tracker[0], tracker[1], tracker[2]);
    Matrix3 rotY = Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(tracker[4]));
    Matrix3 rotX = Matrix3::fromAxisAngle(Vector3(1,0,0), toRadians(tracker[3]));
    Matrix3 rotZ = Matrix3::fromAxisAngle(Vector3(0,0,1), toRadians(tracker[5]));
    
    CoordinateFrame trackerToDevice = CoordinateFrame(trans) * 
		CoordinateFrame(rotY) *
		CoordinateFrame(rotX) * 
		CoordinateFrame(rotZ);
    trackerToDevice.translation *= _trackerUnitsToRoomUnitsScale;

    /** This is probably more direct, but can't test it right now..
    float mat[4][4];
    trackdGetMatrix(_trackerMemory, i, mat);
    CoordinateFrame trackerToDevice = CoordinateFrame(Matrix3(mat[0][0], mat[1][1], mat[2][2],
                                                              mat[0][1], mat[1][1], mat[2][1],
                                                              mat[0][2], mat[1][2], mat[2][2]),
                                                      Vector3(mat[0][3], mat[1][3], mat[2][3]));
    **/
    
    CoordinateFrame eventRoom = _finalOffset[i] * _deviceToRoom * 
      trackerToDevice * _propToTracker[i];

    events.append(new Event(getTrackerName(i), eventRoom));  
  }

  // Update buttons
  for (int i=0;i<iMin(_numButtons, _bEventNames.size());i++) {
    int b = trackdGetButton(_wandMemory, i);
    if (b != _buttonStates[i]) {
      _buttonStates[i] = b;
      std::string name = getButtonName(i);
      if (b) {
        name = name + "_down";
      }
      else {
        name = name + "_up";
      }
      events.append(new Event(name));
    }
  }

  /**
  // Update valuators
  for (int i=0;i<_numValuators;i++) {
    float v = trackdGetValuator(_wandMemory, i);
    if (v != _valuatorStates[i]) {
      _valuatorStates[i] = v;
      events.append(new Event(getValuatorName(i), v));
    }
  }
  **/
}