⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tracks.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  ASSERT(!key->next);  if (!track->keyL) {    track->keyL=key;    key->next=0;  }  else {    Lib3dsLin3Key *k,*p;    for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {      if (k->tcb.frame>key->tcb.frame) {        break;      }    }    if (!p) {      key->next=track->keyL;      track->keyL=key;    }    else {      key->next=k;      p->next=key;    }     if (k && (key->tcb.frame==k->tcb.frame)) {      key->next=k->next;      lib3ds_lin3_key_free(k);    }  }}/*! * \ingroup tracks  */voidlib3ds_lin3_track_remove(Lib3dsLin3Track *track, Lib3dsIntd frame){  Lib3dsLin3Key *k,*p;    ASSERT(track);  if (!track->keyL) {    return;  }  for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {    if (k->tcb.frame==frame) {      if (!p) {        track->keyL=track->keyL->next;      }      else {        p->next=k->next;      }      lib3ds_lin3_key_free(k);      break;    }  }}/*! * \ingroup tracks  */voidlib3ds_lin3_track_eval(Lib3dsLin3Track *track, Lib3dsVector p, Lib3dsFloat t){  Lib3dsLin3Key *k;  Lib3dsFloat nt;  Lib3dsFloat u;  if (!track->keyL) {    lib3ds_vector_zero(p);    return;  }  if (!track->keyL->next) {      lib3ds_vector_copy(p, track->keyL->value);    return;  }  for (k=track->keyL; k->next!=0; k=k->next) {    if ((t>=(Lib3dsFloat)k->tcb.frame) && (t<(Lib3dsFloat)k->next->tcb.frame)) {      break;    }  }  if (!k->next) {    if (track->flags&LIB3DS_REPEAT) {      nt=(Lib3dsFloat)fmod(t, (float)k->tcb.frame);      for (k=track->keyL; k->next!=0; k=k->next) {        if ((nt>=(Lib3dsFloat)k->tcb.frame) && (nt<(Lib3dsFloat)k->next->tcb.frame)) {          break;        }      }      ASSERT(k->next);    }    else {      lib3ds_vector_copy(p, k->value);      return;    }  }  else {    nt=t;  }  u=nt - (Lib3dsFloat)k->tcb.frame;  u/=(Lib3dsFloat)(k->next->tcb.frame - k->tcb.frame);    lib3ds_vector_cubic(    p,    k->value,    k->dd,    k->next->ds,    k->next->value,    u  );}/*! * \ingroup tracks  */Lib3dsBoollib3ds_lin3_track_read(Lib3dsLin3Track *track, FILE *f){  int keys;  int i,j;  Lib3dsLin3Key *k;  track->flags=lib3ds_word_read(f);  lib3ds_dword_read(f);  lib3ds_dword_read(f);  keys=lib3ds_intd_read(f);  for (i=0; i<keys; ++i) {    k=lib3ds_lin3_key_new();    if (!lib3ds_tcb_read(&k->tcb, f)) {      return(LIB3DS_FALSE);    }    for (j=0; j<3; ++j) {      k->value[j]=lib3ds_float_read(f);    }    lib3ds_lin3_track_insert(track, k);  }  lib3ds_lin3_track_setup(track);  return(LIB3DS_TRUE);}/*! * \ingroup tracks  */Lib3dsBoollib3ds_lin3_track_write(Lib3dsLin3Track *track, FILE *f){  Lib3dsLin3Key *k;  Lib3dsDword num=0;  for (k=track->keyL; k; k=k->next) {    ++num;  }  lib3ds_word_write((Lib3dsWord)track->flags,f);  lib3ds_dword_write(0,f);  lib3ds_dword_write(0,f);  lib3ds_dword_write(num,f);  for (k=track->keyL; k; k=k->next) {    if (!lib3ds_tcb_write(&k->tcb,f)) {      return(LIB3DS_FALSE);    }    lib3ds_vector_write(k->value,f);  }  return(LIB3DS_TRUE);}/*! * \ingroup tracks  */Lib3dsQuatKey*lib3ds_quat_key_new(){  Lib3dsQuatKey* k;  k=(Lib3dsQuatKey*)calloc(sizeof(Lib3dsQuatKey), 1);  return(k);}/*! * \ingroup tracks  */voidlib3ds_quat_key_free(Lib3dsQuatKey *key){  ASSERT(key);  free(key);}/*! * \ingroup tracks  */voidlib3ds_quat_track_free_keys(Lib3dsQuatTrack *track){  Lib3dsQuatKey *p,*q;  ASSERT(track);  for (p=track->keyL; p; p=q) {    q=p->next;    lib3ds_quat_key_free(p);  }}/*! * \ingroup tracks  */voidlib3ds_quat_key_setup(Lib3dsQuatKey *p, Lib3dsQuatKey *cp, Lib3dsQuatKey *c,  Lib3dsQuatKey *cn, Lib3dsQuatKey *n){  Lib3dsFloat ksm,ksp,kdm,kdp;  Lib3dsQuat q,qp,qn,qa,qb;  int i;    ASSERT(c);  if (!cp) {    cp=c;  }  if (!cn) {    cn=c;  }  if (!p || !n) {    lib3ds_quat_copy(c->ds, c->q);    lib3ds_quat_copy(c->dd, c->q);    return;  }  if (p) {    if (p->angle>LIB3DS_TWOPI-LIB3DS_EPSILON) {      lib3ds_quat_axis_angle(qp, p->axis, 0.0f);      lib3ds_quat_ln(qp);    }    else {      lib3ds_quat_copy(q, p->q);      if (lib3ds_quat_dot(q,c->q)<0) lib3ds_quat_neg(q);      lib3ds_quat_ln_dif(qp, c->q, q);    }  }  if (n) {    if (n->angle>LIB3DS_TWOPI-LIB3DS_EPSILON) {      lib3ds_quat_axis_angle(qn, n->axis, 0.0f);      lib3ds_quat_ln(qn);    }    else {      lib3ds_quat_copy(q, n->q);      if (lib3ds_quat_dot(q,c->q)<0) lib3ds_quat_neg(q);      lib3ds_quat_ln_dif(qn, c->q, q);    }  }  if (n && p) {    lib3ds_tcb(&p->tcb, &cp->tcb, &c->tcb, &cn->tcb, &n->tcb, &ksm, &ksp, &kdm, &kdp);    for(i=0; i<4; i++) {      qa[i]=-0.5f*(kdm*qn[i]+kdp*qp[i]);      qb[i]=-0.5f*(ksm*qn[i]+ksp*qp[i]);    }    lib3ds_quat_exp(qa);    lib3ds_quat_exp(qb);        lib3ds_quat_mul(c->ds, c->q, qa);    lib3ds_quat_mul(c->dd, c->q, qb);  }  else {    if (p) {      lib3ds_quat_exp(qp);      lib3ds_quat_mul(c->ds, c->q, qp);      lib3ds_quat_mul(c->dd, c->q, qp);    }    if (n) {      lib3ds_quat_exp(qn);      lib3ds_quat_mul(c->ds, c->q, qn);      lib3ds_quat_mul(c->dd, c->q, qn);    }  }}/*! * \ingroup tracks  */voidlib3ds_quat_track_setup(Lib3dsQuatTrack *track){  Lib3dsQuatKey *pp,*pc,*pn,*pl;  Lib3dsQuat q;  ASSERT(track);  for (pp=0,pc=track->keyL; pc; pp=pc,pc=pc->next) {    lib3ds_quat_axis_angle(q, pc->axis, pc->angle);    if (pp) {      lib3ds_quat_mul(pc->q, q, pp->q);    }    else {      lib3ds_quat_copy(pc->q, q);    }  }  pc=track->keyL;  if (!pc) {    return;  }  if (!pc->next) {    lib3ds_quat_copy(pc->ds, pc->q);    lib3ds_quat_copy(pc->dd, pc->q);    return;  }  if (track->flags&LIB3DS_SMOOTH) {    for (pl=track->keyL; pl->next->next; pl=pl->next);    lib3ds_quat_key_setup(pl, pl->next, pc, 0, pc->next); }  else {    lib3ds_quat_key_setup(0, 0, pc, 0, pc->next);  }  for (;;) {    pp=pc;    pc=pc->next;    pn=pc->next;    if (!pn) {      break;    }    lib3ds_quat_key_setup(pp, 0, pc, 0, pn);  }  if (track->flags&LIB3DS_SMOOTH) {    lib3ds_quat_key_setup(pp, 0, pc, track->keyL, track->keyL->next);  }  else {    lib3ds_quat_key_setup(pp, 0, pc, 0, 0);  }}/*! * \ingroup tracks  */voidlib3ds_quat_track_insert(Lib3dsQuatTrack *track, Lib3dsQuatKey *key){  ASSERT(track);  ASSERT(key);  ASSERT(!key->next);  if (!track->keyL) {    track->keyL=key;    key->next=0;  }  else {    Lib3dsQuatKey *k,*p;    for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {      if (k->tcb.frame>key->tcb.frame) {        break;      }    }    if (!p) {      key->next=track->keyL;      track->keyL=key;    }    else {      key->next=k;      p->next=key;    }     if (k && (key->tcb.frame==k->tcb.frame)) {      key->next=k->next;      lib3ds_quat_key_free(k);    }  }}/*! * \ingroup tracks  */voidlib3ds_quat_track_remove(Lib3dsQuatTrack *track, Lib3dsIntd frame){  Lib3dsQuatKey *k,*p;    ASSERT(track);  if (!track->keyL) {    return;  }  for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {    if (k->tcb.frame==frame) {      if (!p) {        track->keyL=track->keyL->next;      }      else {        p->next=k->next;      }      lib3ds_quat_key_free(k);      break;    }  }}/*! * \ingroup tracks  */voidlib3ds_quat_track_eval(Lib3dsQuatTrack *track, Lib3dsQuat q, Lib3dsFloat t){  Lib3dsQuatKey *k;  Lib3dsFloat nt;  Lib3dsFloat u;  if (!track->keyL) {    lib3ds_quat_identity(q);    return;  }  if (!track->keyL->next) {    lib3ds_quat_copy(q, track->keyL->q);    return;  }  for (k=track->keyL; k->next!=0; k=k->next) {    if ((t>=k->tcb.frame) && (t<k->next->tcb.frame)) {      break;    }  }  if (!k->next) {    if (track->flags&LIB3DS_REPEAT) {      nt=(Lib3dsFloat)fmod(t, (float)k->tcb.frame);      for (k=track->keyL; k->next!=0; k=k->next) {        if ((nt>=k->tcb.frame) && (nt<k->next->tcb.frame)) {          break;        }      }      ASSERT(k->next);    }    else {      lib3ds_quat_copy(q, k->q);      return;    }  }  else {    nt=t;  }  u=nt - k->tcb.frame;  u/=(k->next->tcb.frame - k->tcb.frame);  lib3ds_quat_squad(    q,    k->q,    k->dd,    k->next->ds,    k->next->q,    u  );}/*! * \ingroup tracks  */Lib3dsBoollib3ds_quat_track_read(Lib3dsQuatTrack *track, FILE *f){  int keys;  int i,j;  Lib3dsQuatKey *k;  track->flags=lib3ds_word_read(f);  lib3ds_dword_read(f);  lib3ds_dword_read(f);  keys=lib3ds_intd_read(f);  for (i=0; i<keys; ++i) {    k=lib3ds_quat_key_new();    if (!lib3ds_tcb_read(&k->tcb, f)) {      return(LIB3DS_FALSE);    }    k->angle=lib3ds_float_read(f);    for (j=0; j<3; ++j) {      k->axis[j]=lib3ds_float_read(f);    }    lib3ds_quat_track_insert(track, k);  }  lib3ds_quat_track_setup(track);  return(LIB3DS_TRUE);}/*! * \ingroup tracks  */Lib3dsBoollib3ds_quat_track_write(Lib3dsQuatTrack *track, FILE *f){  Lib3dsQuatKey *k;  Lib3dsDword num=0;  for (k=track->keyL; k; k=k->next) {    ++num;  }  lib3ds_word_write((Lib3dsWord)track->flags,f);  lib3ds_dword_write(0,f);  lib3ds_dword_write(0,f);  lib3ds_dword_write(num,f);  for (k=track->keyL; k; k=k->next) {    if (!lib3ds_tcb_write(&k->tcb,f)) {      return(LIB3DS_FALSE);    }    lib3ds_float_write(k->angle,f);    lib3ds_vector_write(k->axis,f);  }  return(LIB3DS_TRUE);}/*! * \ingroup tracks  */Lib3dsMorphKey*lib3ds_morph_key_new(){  Lib3dsMorphKey* k;  k=(Lib3dsMorphKey*)calloc(sizeof(Lib3dsMorphKey), 1);  return(k);}/*! * \ingroup tracks  */voidlib3ds_morph_key_free(Lib3dsMorphKey *key){  ASSERT(key);  free(key);}/*! * \ingroup tracks  */voidlib3ds_morph_track_free_keys(Lib3dsMorphTrack *track){  Lib3dsMorphKey *p,*q;  ASSERT(track);  for (p=track->keyL; p; p=q) {    q=p->next;    lib3ds_morph_key_free(p);  }}/*! * \ingroup tracks  */voidlib3ds_morph_track_insert(Lib3dsMorphTrack *track, Lib3dsMorphKey *key){  ASSERT(track);  ASSERT(key);  ASSERT(!key->next);  if (!track->keyL) {    track->keyL=key;    key->next=0;  }  else {    Lib3dsMorphKey *k,*p;    for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {      if (k->tcb.frame>key->tcb.frame) {        break;      }    }    if (!p) {      key->next=track->keyL;      track->keyL=key;    }    else {      key->next=k;      p->next=key;    }     if (k && (key->tcb.frame==k->tcb.frame)) {      key->next=k->next;      lib3ds_morph_key_free(k);    }  }}/*! * \ingroup tracks  */voidlib3ds_morph_track_remove(Lib3dsMorphTrack *track, Lib3dsIntd frame){  Lib3dsMorphKey *k,*p;    ASSERT(track);  if (!track->keyL) {    return;  }  for (p=0,k=track->keyL; k!=0; p=k, k=k->next) {    if (k->tcb.frame==frame) {      if (!p) {        track->keyL=track->keyL->next;      }      else {        p->next=k->next;      }      lib3ds_morph_key_free(k);      break;    }  }}/*! * \ingroup tracks  */voidlib3ds_morph_track_eval(Lib3dsMorphTrack *track, char *p, Lib3dsFloat t){  Lib3dsMorphKey *k;  char* result;  ASSERT(p);  if (!track->keyL) {    strcpy(p,"");    return;  }  if (!track->keyL->next) {    strcpy(p,track->keyL->name);    return;  }  result=0;  k=track->keyL;  while ((t<k->tcb.frame) && (t>=k->next->tcb.frame)) {    result=k->name;    if (!k->next) {      if (track->flags&LIB3DS_REPEAT) {        t-=k->tcb.frame;        k=track->keyL;      }      else {        break;      }    }    else {      k=k->next;    }  }  if (result) {    strcpy(p,result);  }  else {    strcpy(p,"");  }}/*! * \ingroup tracks */Lib3dsBoollib3ds_morph_track_read(Lib3dsMorphTrack *, FILE *){  /* FIXME: */  return(LIB3DS_TRUE);}/*! * \ingroup tracks  */Lib3dsBoollib3ds_morph_track_write(Lib3dsMorphTrack *, FILE *){  /* FIXME: */  ASSERT(0);  return(LIB3DS_FALSE);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -