Example #1
0
void RealFFTI(const ColumnVector& A, const ColumnVector& B, ColumnVector& U)
{
   // inverse of a Fourier transform of a real series
   Tracer trace("RealFFTI");
   REPORT
   const int n21 = A.Nrows();                     // length of arrays
   if (n21 != B.Nrows() || n21 == 0)
      Throw(ProgramException("Vector lengths unequal or zero", A, B));
   const int n2 = n21 - 1;  const int n = 2 * n2;  int i = n2 - 1;

   ColumnVector X(n2), Y(n2);
   Real* a = A.Store(); Real* b = B.Store();  // first els of A and B
   Real* an = a + n2;   Real* bn = b + n2;    // last els of A and B
   Real* x = X.Store(); Real* y = Y.Store();  // first els of X and Y
   Real* xn = x + i;    Real* yn = y + i;     // last els of X and Y

   Real hn = 0.5 / n2;
   *x++  = hn * (*a + *an);  *y++  = - hn * (*a - *an);
   a++; an--; b++; bn--;
   int j = -1;  i = n2/2;
   while (i--)
   {
      Real c,s; cossin(j--,n,c,s);
      Real am = *a - *an; Real ap = *a++ + *an--;
      Real bm = *b - *bn; Real bp = *b++ + *bn--;
      Real samcbp = s * am - c * bp; Real sbpcam = s * bp + c * am;
      *x++  =  hn * ( ap + samcbp); *y++  =  - hn * ( bm + sbpcam);
      *xn-- =  hn * ( ap - samcbp); *yn-- =  - hn * (-bm + sbpcam);
   }
   FFT(X,Y,X,Y);             // have done inverting elsewhere
   U.ReSize(n); i = n2;
   x = X.Store(); y = Y.Store(); Real* u = U.Store();
   while (i--) { *u++ = *x++; *u++ = - *y++; }
}
Example #2
0
void iterate_terrain(BATB& batb, run::World& run, forest::World& forest)
{
    //terrain_group->autoUpdateLodAll(false, Any( Real(HOLD_LOD_DISTANCE) ));
    tick_t tick = run.tick;
    float_t x,z;
    cossin( 0.1 * tick, x, z );
    float_t y = sin( tick * 3 );

    //Vector3 pos( 0, 400, 0 );
    //camera->setPosition( pos );
    Ogre::Vector3 dir( x, -0.14, z );
    dir.normalise();
    //camera->setDirection( dir );
    if ( forest.runners.empty() )
    {
        std::cout << "runners.empty!!\n"; 
        camera->setDirection( dir );
    }
    else
    {
        forest::Runner runner = forest.runners.front();
        glm::mat4 aim = runner.move.aim;
        glm::vec4 z = aim[2];
        
        camera->setDirection( Ogre::Vector3( z[0], z[1], z[2] ) );

        glm::vec4 pos = runner.move.aim[3];
        camera->setPosition( Ogre::Vector3( pos[0], pos[1], pos[2] ) );

    }
    

}
Example #3
0
void RealFFT(const ColumnVector& U, ColumnVector& X, ColumnVector& Y)
{
   // Fourier transform of a real series
   Tracer trace("RealFFT");
   REPORT
   const int n = U.Nrows();                     // length of arrays
   const int n2 = n / 2;
   if (n != 2 * n2)
      Throw(ProgramException("Vector length not multiple of 2", U));
   ColumnVector A(n2), B(n2);
   Real* a = A.Store(); Real* b = B.Store(); Real* u = U.Store(); int i = n2;
   while (i--) { *a++ = *u++; *b++ = *u++; }
   FFT(A,B,A,B);
   int n21 = n2 + 1;
   X.ReSize(n21); Y.ReSize(n21);
   i = n2 - 1;
   a = A.Store(); b = B.Store();              // first els of A and B
   Real* an = a + i; Real* bn = b + i;        // last els of A and B
   Real* x = X.Store(); Real* y = Y.Store();  // first els of X and Y
   Real* xn = x + n2; Real* yn = y + n2;      // last els of X and Y

   *x++ = *a + *b; *y++ = 0.0;                // first complex element
   *xn-- = *a++ - *b++; *yn-- = 0.0;          // last complex element

   int j = -1; i = n2/2;
   while (i--)
   {
      Real c,s; cossin(j--,n,c,s);
      Real am = *a - *an; Real ap = *a++ + *an--;
      Real bm = *b - *bn; Real bp = *b++ + *bn--;
      Real samcbp = s * am + c * bp; Real sbpcam = s * bp - c * am;
      *x++  =  0.5 * ( ap + samcbp); *y++  =  0.5 * ( bm + sbpcam);
      *xn-- =  0.5 * ( ap - samcbp); *yn-- =  0.5 * (-bm + sbpcam);
   }
}
Example #4
0
void iterate_head(BATB& batb, run::World& world)
{
    tick_t tick = world.tick;
    float_t x,z;
    cossin( 0.5 * tick, x, z );
    //float_t y = sin( tick * 3 );
    float_t y = 50 + sin( tick * 3 );

    camera->setPosition( Ogre::Vector3( 128.0 * x, 64.0 * y, 128.0 * z ) );
    camera->lookAt( Ogre::Vector3( 0, 0, 0 ) );
}
Example #5
0
static void fftstep(ColumnVector& A, ColumnVector& B, ColumnVector& X,
                    ColumnVector& Y, int after, int now, int before)
{
    REPORT
    Tracer trace("FFT(step)");
    // const Real twopi = 6.2831853071795864769;
    const int gamma = after * before;
    const int delta = now * after;
    // const Real angle = twopi / delta;  Real temp;
    // Real r_omega = cos(angle);  Real i_omega = -sin(angle);
    Real r_arg = 1.0;
    Real i_arg = 0.0;
    Real* x = X.Store();
    Real* y = Y.Store();   // pointers to array storage
    const int m = A.Nrows() - gamma;

    for (int j = 0; j < now; j++)
    {
        Real* a = A.Store();
        Real* b = B.Store(); // pointers to array storage
        Real* x1 = x;
        Real* y1 = y;
        x += after;
        y += after;
        for (int ia = 0; ia < after; ia++)
        {
            // generate sins & cosines explicitly rather than iteratively
            // for more accuracy; but slower
            cossin(-(j*after+ia), delta, r_arg, i_arg);

            Real* a1 = a++;
            Real* b1 = b++;
            Real* x2 = x1++;
            Real* y2 = y1++;
            if (now==2)
            {
                REPORT int ib = before;
                if (ib) for (;;)
                    {
                        REPORT
                        Real* a2 = m + a1;
                        Real* b2 = m + b1;
                        a1 += after;
                        b1 += after;
                        Real r_value = *a2;
                        Real i_value = *b2;
                        *x2 = r_value * r_arg - i_value * i_arg + *(a2-gamma);
                        *y2 = r_value * i_arg + i_value * r_arg + *(b2-gamma);
                        if (!(--ib)) break;
                        x2 += delta;
                        y2 += delta;
                    }
            }
            else
            {
                REPORT int ib = before;
                if (ib) for (;;)
                    {
                        REPORT
                        Real* a2 = m + a1;
                        Real* b2 = m + b1;
                        a1 += after;
                        b1 += after;
                        Real r_value = *a2;
                        Real i_value = *b2;
                        int in = now-1;
                        while (in--)
                        {
                            // it should be possible to make this faster
                            // hand code for now = 2,3,4,5,8
                            // use symmetry to halve number of operations
                            a2 -= gamma;
                            b2 -= gamma;
                            Real temp = r_value;
                            r_value = r_value * r_arg - i_value * i_arg + *a2;
                            i_value = temp    * i_arg + i_value * r_arg + *b2;
                        }
                        *x2 = r_value;
                        *y2 = i_value;
                        if (!(--ib)) break;
                        x2 += delta;
                        y2 += delta;
                    }
            }

            // temp = r_arg;
            // r_arg = r_arg * r_omega - i_arg * i_omega;
            // i_arg = temp  * i_omega + i_arg * r_omega;

        }
    }
}