コード例 #1
0
ファイル: SCBigInteger.cpp プロジェクト: w3woody/caredemo
int SCBigInteger::CompareTo(const SCBigInteger &i) const
{
	if (isNan) return 2;
	if (i.isNan) return 2;			// nans are never equal. They're errors

	if (isNeg != i.isNeg) {
		return i.isNeg ? 1 : -1;	// > if supplied is negative
	}

	/*
	 *	Compare the unsigned array
	 */

	int comp = CompareAbs(i);
	if (isNeg) comp = -comp;
	return comp;
}
コード例 #2
0
ファイル: OpenGlTunnels.cpp プロジェクト: PsyPhy/GRASPonISS
void __fastcall Tunnel::MakeKeyFrames( char *nom, short nseg, short condition )
{
    short i, k;
    GLfloat tmp[3];
    GLfloat dir[10][3];

    MakeDir(nom, nseg, dir);

    ///////////////////////
    // Position KeyFrames
    ///////////////////////

    // 1st
    PosKey[0][0] = PosKey[0][1] = PosKey[0][2] = 0;
    Affect(PosKeyDir[0], dir[1]);
    PosKeyTime[0] = 0;

    // 2st
    Scal(PosKey[1], LSEG, dir[1]);
    Affect(PosKeyDir[1], dir[1]);
    PosKeyTime[1] = (double) LSEG / SPEED;

    for(k=2, i=2 ; i<=nseg ; i++)
    {
      // k-ieme
      Add(tmp, dir[i-1], dir[i]);
      Scal(tmp, RSEG, tmp);
      Add(PosKey[k], PosKey[k-1], tmp);
      Affect(PosKeyDir[k], dir[i]);
      PosKeyTime[k] = PosKeyTime[k-1] + (double) M_PI_2 * RSEG / SPEED;
      k++;

      // k-ieme (+1)
      Scal(tmp, LSEG, dir[i]);
      Add(PosKey[k], PosKey[k-1], tmp);
      Affect(PosKeyDir[k], dir[i]);
      PosKeyTime[k] = PosKeyTime[k-1] + (double) LSEG / SPEED;
      k++;
    }
    nPosKey = k-1;
    LastPosKey = 0;
    NextPosKey = 1;


    ////////////////////////////////////////////////
    // Rotation KeyFrames, fonction des conditions
    ////////////////////////////////////////////////

    if(condition == 1)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], dir[i]);
        Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        Affect(RotKeyDir[k], dir[i]);
        Cross(tmp, RotKeyDir[k-1], RotKeyDir[k]);
        if(CompareAbs(tmp, RotKeyUp[k-1]))         // Si rotation autour de RotKeyUp
          Affect(RotKeyUp[k], RotKeyUp[k-1]);
        else                                    // Sinon applique la rotation à RotKeyUp
          Cross(RotKeyUp[k], tmp, RotKeyUp[k-1]);

        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }

    else if(condition == 2)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], dir[i]);
        Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        Affect(RotKeyDir[k], dir[i]);
        Cross(tmp, RotKeyDir[k-1], RotKeyDir[k]);
        if(CompareAbs(tmp, RotKeyUp[k-1]))         // Si rotation autour de RotKeyUp
          Affect(RotKeyUp[k], RotKeyUp[0]);
        else                                       // Sinon applique la rotation à RotKeyUp
          Cross(RotKeyUp[k], tmp, RotKeyUp[k-1]);

        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }

    else if(condition == 3)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], RotKeyDir[k-1]);
        Affect(RotKeyUp[k], RotKeyUp[0]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        if(dir[i][1] == 1 || dir[i][1] == -1)   // si segment vertical
        {
          if(i+1 <= nseg)
            Affect(RotKeyDir[k], dir[i+1]);
          else
            Affect(RotKeyDir[k], RotKeyDir[k-1]);
        }
        else
          Affect(RotKeyDir[k], dir[i]);

        Affect(RotKeyUp[k], RotKeyUp[0]);
        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      if(dir[i][1] == 1 || dir[i][1] == -1)   // si segment vertical
        Affect(RotKeyDir[k], RotKeyDir[k-1]);
      else
        Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[0]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }
}