void
DpadRestrictorModifier::update(int msec_delta, XboxGenericMsg& msg)
{
  switch(m_mode)
  {
    case kRestrictFourWay:
      if (get_axis(msg, XBOX_AXIS_DPAD_X) && get_axis(msg, XBOX_AXIS_DPAD_Y))
      {
        // a diagonal was pressed, thus we reset the axis that wasn't
        // pressed the last time the dpad was touched
        set_axis(msg, m_last_unpressed_axis, 0);
      }
      else if (get_axis(msg, XBOX_AXIS_DPAD_X))
      {
        m_last_unpressed_axis = XBOX_AXIS_DPAD_Y;
      }
      else if (get_axis(msg, XBOX_AXIS_DPAD_Y))
      {
        m_last_unpressed_axis = XBOX_AXIS_DPAD_X;
      }
      break;

    case kRestrictXAxis:
      set_axis(msg, XBOX_AXIS_DPAD_Y, 0);
      break;

    case kRestrictYAxis:
      set_axis(msg, XBOX_AXIS_DPAD_X, 0);
      break;
  }
}
示例#2
0
static int joy_poll(void)
{
   fd_set set;
   struct timeval tv;
   struct js_event e[32];
   int i, ready;
   int bytes, n, k;

   for (i = 0; i < num_joysticks; i++) {
      tv.tv_sec = tv.tv_usec = 0;
      FD_ZERO(&set);
      FD_SET(joy_fd[i], &set);

      ready = select(FD_SETSIZE, &set, NULL, NULL, &tv);
      if (ready <= 0)
	 continue;

      while ((bytes = read(joy_fd[i], e, sizeof(e))) > 0) {
	 n = bytes / sizeof(e[0]);
	 for (k = 0; k < n; k++) {
	    if (e[k].type & JS_EVENT_BUTTON) {
	       if (e[k].number < joy[i].num_buttons)
		  joy[i].button[e[k].number].b = e[k].value;
	    }
	    else if (e[k].type & JS_EVENT_AXIS) {
	       if (e[k].number < TOTAL_JOYSTICK_AXES)
		  set_axis (axis[i][e[k].number], e[k].value);
	    }
	 }
      }
   }

   return 0;
}
示例#3
0
void Matrix3::orthonormalize() {

	// Gram-Schmidt Process

	Vector3 x=get_axis(0);
	Vector3 y=get_axis(1);
	Vector3 z=get_axis(2);

	x.normalize();
	y = (y-x*(x.dot(y)));
	y.normalize();
	z = (z-x*(x.dot(z))-y*(y.dot(z)));
	z.normalize();

	set_axis(0,x);
	set_axis(1,y);
	set_axis(2,z);

}
示例#4
0
void Basis::orthonormalize() {
	ERR_FAIL_COND(determinant() == 0);

	// Gram-Schmidt Process

	Vector3 x=get_axis(0);
	Vector3 y=get_axis(1);
	Vector3 z=get_axis(2);

	x.normalize();
	y = (y-x*(x.dot(y)));
	y.normalize();
	z = (z-x*(x.dot(z))-y*(y.dot(z)));
	z.normalize();

	set_axis(0,x);
	set_axis(1,y);
	set_axis(2,z);

}
void
FourWayRestrictorModifier::update(int msec_delta, XboxGenericMsg& msg)
{
  // left Stick
  if (abs(get_axis(msg, XBOX_AXIS_X1)) > abs(get_axis(msg, XBOX_AXIS_Y1)))
  {
    set_axis(msg, XBOX_AXIS_Y1, 0);
  }
  else if (abs(get_axis(msg, XBOX_AXIS_Y1)) > abs(get_axis(msg, XBOX_AXIS_X1)))
  {
    set_axis(msg, XBOX_AXIS_X1, 0);
  }
  else
  {
    set_axis(msg, XBOX_AXIS_X1, 0);
  }

  // right stick
  if (abs(get_axis(msg, XBOX_AXIS_X2)) > abs(get_axis(msg, XBOX_AXIS_Y2)))
  {
    set_axis(msg, XBOX_AXIS_Y2, 0);
  }
  else if (abs(get_axis(msg, XBOX_AXIS_Y2)) > abs(get_axis(msg, XBOX_AXIS_X2)))
  {
    set_axis(msg, XBOX_AXIS_X2, 0);
  }
  else
  {
    set_axis(msg, XBOX_AXIS_X2, 0);
  }
}
示例#6
0
void keyCodeCallback(GLFWwindow* window, int key_code, int scancode, int action, int mod)
{
    if(action == GLFW_REPEAT)
        return;

    for(int i = 0; i < key_inputs[key_code].action_count; ++i) {
        if(key_inputs[key_code].action_pairs[i].mods == mod) {
            set_input_state(key_inputs[key_code].action_pairs[i].action_id, action == GLFW_PRESS);
        }
    }

    for(int i = 0; i < key_inputs[key_code].axis_count; ++i) {
        if(key_inputs[key_code].axis_pairs[i].mods == mod) {
            // FIXME: On release, digital axes are reversed
            if(action == GLFW_PRESS)
                set_axis(key_inputs[key_code].axis_pairs[i].axis_id, key_inputs[key_code].axis_pairs[i].isx, key_inputs[key_code].axis_pairs[i].value, false, key_inputs[key_code].axis_pairs[i].emulated);
            else {
                set_axis(key_inputs[key_code].axis_pairs[i].axis_id, key_inputs[key_code].axis_pairs[i].isx, key_inputs[key_code].axis_pairs[i].value * -1, false, key_inputs[key_code].axis_pairs[i].emulated);
            }
        }
    }
}
示例#7
0
static int set_axis_exec(bContext *C, wmOperator *op)
{
    SpaceClip *sc = CTX_wm_space_clip(C);
    MovieClip *clip = ED_space_clip_get_clip(sc);
    MovieTracking *tracking = &clip->tracking;
    MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
    Scene *scene = CTX_data_scene(C);
    Object *object;
    int axis = RNA_enum_get(op->ptr, "axis");

    if (count_selected_bundles(C) != 1) {
        BKE_report(op->reports,
                   RPT_ERROR,
                   "Single track with bundle should be selected to define axis");
        return OPERATOR_CANCELLED;
    }

    object = get_orientation_object(C);
    if (object == NULL) {
        BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
        return OPERATOR_CANCELLED;
    }

    ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking,
                           tracking_object);
    MovieTrackingTrack *track = tracksbase->first;
    while (track) {
        if (TRACK_VIEW_SELECTED(sc, track) &&
                (track->flag & TRACK_HAS_BUNDLE))
        {
            break;
        }
        track = track->next;
    }

    set_axis(scene, object, clip, tracking_object, track, axis == 0 ? 'X' : 'Y');

    DAG_id_tag_update(&clip->id, 0);
    DAG_id_tag_update(&object->id, OB_RECALC_OB);

    WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
    WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);

    return OPERATOR_FINISHED;
}
示例#8
0
void WatchDiamondWidget::update_emc_slot(const MarkEmcStatus& status)
{
    char buf[256];
    int colors[5];

    for(int i=0; i<5; i++){
        colors[i] = (int)status.axisHomeState[i];
        axisPos[i] = status.cmdAxis[i];
    }

    set_axis(status.cmdAxis,colors);
    if(status.errorMsg[0]!='\0'){
        sprintf(buf,"%s\n",status.errorMsg);
        te_sysMessage->append(QString::fromUtf8(buf));
    }
    if(status.operatorText[0]!='\0'){
        sprintf(buf,"%s\n",status.operatorText);
        te_sysMessage->append(QString::fromUtf8(buf));
    }
    if(status.operatorDisplay[0]!='\0'){
        sprintf(buf,"%s\n",status.operatorDisplay);
        te_sysMessage->append(QString::fromUtf8(buf));
    }
}
示例#9
0
static int set_plane_exec(bContext *C, wmOperator *op)
{
  SpaceClip *sc = CTX_wm_space_clip(C);
  MovieClip *clip = ED_space_clip_get_clip(sc);
  Scene *scene = CTX_data_scene(C);
  MovieTracking *tracking = &clip->tracking;
  MovieTrackingObject *tracking_object;
  MovieTrackingTrack *track, *axis_track = NULL, *act_track;
  ListBase *tracksbase;
  Object *object;
  Object *camera = get_camera_with_movieclip(scene, clip);
  Depsgraph *depsgraph = CTX_data_depsgraph(C);
  int tot = 0;
  float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f};
  int plane = RNA_enum_get(op->ptr, "plane");
  float rot[4][4] = {
      {0.0f, 0.0f, -1.0f, 0.0f},
      {0.0f, 1.0f, 0.0f, 0.0f},
      {1.0f, 0.0f, 0.0f, 0.0f},
      {0.0f, 0.0f, 0.0f, 1.0f},
  }; /* 90 degrees Y-axis rotation matrix */

  if (count_selected_bundles(C) != 3) {
    BKE_report(op->reports, RPT_ERROR, "Three tracks with bundles are needed to orient the floor");

    return OPERATOR_CANCELLED;
  }

  tracking_object = BKE_tracking_object_get_active(tracking);
  tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
  act_track = BKE_tracking_track_get_active(tracking);

  object = get_orientation_object(C);
  if (object == NULL) {
    BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
    return OPERATOR_CANCELLED;
  }

  BKE_tracking_get_camera_object_matrix(scene, camera, mat);

  /* Get 3 bundles to use as reference. */
  track = tracksbase->first;
  while (track && tot < 3) {
    if (track->flag & TRACK_HAS_BUNDLE && TRACK_VIEW_SELECTED(sc, track)) {
      mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
      if (tot == 0 || track == act_track) {
        copy_v3_v3(orig, vec[tot]);
      }
      else {
        axis_track = track;
      }
      tot++;
    }
    track = track->next;
  }

  sub_v3_v3(vec[1], vec[0]);
  sub_v3_v3(vec[2], vec[0]);

  /* Construct ortho-normal basis. */
  unit_m4(mat);
  if (plane == 0) { /* floor */
    cross_v3_v3v3(mat[0], vec[1], vec[2]);
    copy_v3_v3(mat[1], vec[1]);
    cross_v3_v3v3(mat[2], mat[0], mat[1]);
  }
  else if (plane == 1) { /* wall */
    cross_v3_v3v3(mat[2], vec[1], vec[2]);
    copy_v3_v3(mat[1], vec[1]);
    cross_v3_v3v3(mat[0], mat[1], mat[2]);
  }

  normalize_v3(mat[0]);
  normalize_v3(mat[1]);
  normalize_v3(mat[2]);

  /* Move to origin point. */
  mat[3][0] = orig[0];
  mat[3][1] = orig[1];
  mat[3][2] = orig[2];

  if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
    invert_m4(mat);

    BKE_object_to_mat4(object, obmat);
    mul_m4_m4m4(mat, mat, obmat);
    mul_m4_m4m4(newmat, rot, mat);
    BKE_object_apply_mat4(object, newmat, 0, 0);

    /* Make camera have positive z-coordinate. */
    if (object->loc[2] < 0) {
      invert_m4(rot);
      mul_m4_m4m4(newmat, rot, mat);
      BKE_object_apply_mat4(object, newmat, 0, 0);
    }
  }
  else {
    BKE_object_apply_mat4(object, mat, 0, 0);
  }

  BKE_object_where_is_calc(depsgraph, scene, object);
  set_axis(scene, object, clip, tracking_object, axis_track, 'X');

  DEG_id_tag_update(&clip->id, 0);
  DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);

  WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
  WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);

  return OPERATOR_FINISHED;
}