示例#1
0
void polyObject::UpdateOneStep(double ogl_trans[16])
{
  
  position  = position + v;
  orientation = orientation + omega;
  
  
  if ( (position[0] > WallDist) && (v[0] > 0) )
    {
      v[0] = -v[0];
    }
  if ( (position[0] < -WallDist) && (v[0] < 0) )
    {
      v[0] = -v[0];
    }
  
  if ( (position[1] > WallDist) && (v[1] > 0) )
    {
      v[1] = -v[1];
    }
  if ( (position[1] < -WallDist) && (v[1] < 0) )
    {
      v[1] = -v[1];
    }
  
  if ( (position[2] > WallDist) && (v[2] > 0) )
    {
      v[2] = -v[2];
    }
  if ( (position[2] < -WallDist) && (v[2] < 0) )
    {
      v[2] = -v[2];
    }
  
  
  double theta_len = orientation.length();
  Vector theta = orientation;
  theta.normalize();
  
  Rotated(RAD2DEG(theta_len), theta[0], theta[1], theta[2], ogl_trans);
  ogl_trans[12] = position[0];
  ogl_trans[13] = position[1];
  ogl_trans[14] = position[2];
  
}
示例#2
0
void Points::Rotate(char axis, int point_count, std::string title)
{
    int g=point_count;

    std::vector<int> index(g*g);
    std::vector<int> rindex(g*g);
    std::vector<int> It(g);
    std::vector<double> theta(g);
    std::vector<double> phi(g);
    std::vector<double> theta_rotated(g);
    std::vector<double> phi_rotated(g);



    std::vector<double> theta_index(g*g);
    std::vector<double> phi_index(g*g);
    Points::kernel_map.resize(g);
    Points::weight_map.resize(g);
    Points::fkernel_map.resize(g);
    Points::theta_prime.resize(g*g);
    Points:: phi_prime.resize(g*g);

    std::vector<std::vector<double> > kern(g);
    std::vector<std::vector<double> > fkern(g);
    std::vector<std::vector<double> > weight(g);
    std::vector<std::vector<double> > rkern(g);
    std::vector<std::vector<double> > rkern2(g);
    std::vector<std::vector<double> > rotated_kern(g);
    std::vector<double> r_weight(g*g);
    std::vector<std::vector<double> > rfkernel_value(g);

    std::vector<Vex> Original(g);
    std::vector<Vex> Rotated(g);
    Points::TtoZ.resize(g);

    theta=Points::Theta;
    phi=Points::Phi;






    if(axis=='X')
    {
        theta_rotated=Points::theta_rotatedX;
        phi_rotated=Points::phi_rotatedX;

    }
    else if(axis=='Y')
    {

        theta_rotated=Points::theta_rotatedY;
        phi_rotated=Points::phi_rotatedY;

    }
    else if(axis=='Z')
    {

        theta_rotated=Points::theta_rotatedZ;
        phi_rotated=Points::phi_rotatedZ;

    }
    else
    {

    }


    std::vector<int> i_it(g*g);
    std::vector<int> j_it(g*g);


      for(int i=0; i<g; i++)
    {

        Original[i].SphericaltoXYZ(theta[i],phi[i],1.0);
        Rotated[i].SphericaltoXYZ(theta_rotated[i], phi_rotated[i], 1.0);

       // std::cout <<"x, y, z =" << Original[i].GetX() << ", " << Original[i].GetY() << ", "<< Original[i].GetZ() << ", "<< std::endl;
    }


    for(int i=0; i<g; i++)
    {
        kern[i].resize(g);
        fkern[i].resize(g);
        weight[i].resize(g);

        rkern[i].resize(g);
        rkern2[i].resize(g);

        //std::cout << "original xyz = ("  << Original[i].GetX() << ", " << Original[i].GetY() << ", " << Original[i].GetZ() << ")" << std::endl;


    }



//------------ load unroated kernel matrix from file ------------------//


    std::cout <<axis+title << std::endl;
    std::ifstream kernel_read(title);
    kernel_read.precision(15);
    kernel_read.clear();                 // clear fail and eof bits
    kernel_read.seekg(0, std::ios::beg); // back to the start!

    int u=0;

    for(int i=0; i<g; i++)
    {
        kernel_map[i].resize(g);
        fkernel_map[i].resize(g);
        weight_map[i].resize(g);

        for(int j=0; j<g; j++)
        {
            //kernel_read >> theta_index[u] >> phi_index[u] >> kern[i][j] >> fkern[i][j] >> weight[i][j];
            kernel_read >> kern[i][j] >> fkern[i][j] >> weight[i][j];
            u++;
        }

    }

    kernel_read.close();


//--------------find index that matches rotation -----------------------//


    for(int i=0; i<g; i++)
    {
        for(int j=0; j<g; j++)
        {
            if(Original[i]==Rotated[j])
            {
                Points::TtoZ[i] = Rotated[j];
                It[i]=j;
            }
        }
    }





//-------------------use rotated index to map kernel ------------------------//

    for(int i=0; i<g; i++)
    {
        Points::theta_prime[i]=theta[ It[i] ];
        Points::phi_prime[i]=phi[ It[i] ];

        for(int j=0; j<g; j++)
        {
            Points::kernel_map[i][j]=kern[ It[i] ][ It[j] ];
            Points::fkernel_map[i][j]=fkern[ It[i] ][ It[j] ];
            Points::weight_map[i][j]=weight[ It[i] ][ It[j] ];

        }

    }




    std::cout << std::endl;
    std::cout << "Rotation Passed! " <<  std::endl;
    std::cout << std::endl;

}