Exemple #1
0
void drawSolidSphere( float x, float y, float z, float r )
{
    float alpha;
    float dalpha = 2.0*M_PI/na;
    float beta;
    float dbeta = 1.0*M_PI/nb;

    beta = M_PI/2;
    for( int j=0; j<nb; j++, beta-=dbeta)
    {
        alpha = 0;
        for( int i=0; i<na; i++, alpha+=dalpha)
        {
            glBegin( GL_POLYGON );

            OKG_POINT a = spherical(alpha,beta,r);
            OKG_POINT b = spherical(alpha+dalpha,beta,r);
            OKG_POINT c = spherical(alpha+dalpha,beta-dbeta,r);
            OKG_POINT d = spherical(alpha,beta-dbeta,r);

            OKG_POINT n = spherical(alpha+dalpha/2,beta-dbeta/2,0.8);
            glNormal3f(n.x,n.y,n.z);

            glVertex3f(x+a.x,y+a.y,z+a.z);
            glVertex3f(x+b.x,y+b.y,z+b.z);
            glVertex3f(x+c.x,y+c.y,z+c.z);
            glVertex3f(x+d.x,y+d.y,z+d.z);
            glEnd( );
        }
    }
}
Exemple #2
0
void drawSmoothEllipsoidPatch(
        float x, float y, float z,     // координати
        float rx, float ry, float rz,  // размери
        float a1, float a2,            // хоризонтален диапазон
        float b1, float b2             // вертикален диапазон
    )
{
    float alpha;
    float dalpha = (a2-a1)/(float)na;
    float beta;
    float dbeta = (b2-b1)/(float)nb;

    beta = b2;
    for( int j=0; j<nb; j++, beta-=dbeta)
    {
        alpha = a1;
        for( int i=0; i<na; i++, alpha+=dalpha)
        {
            OKG_POINT p;
            glBegin( GL_POLYGON );

            p = spherical(alpha,beta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha+dalpha,beta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha+dalpha,beta-dbeta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha,beta-dbeta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            glEnd( );
        }
    }
}
Exemple #3
0
void drawSmoothEllipsoid( float x, float y, float z, float rx, float ry, float rz )
{
    float alpha;
    float dalpha = 2.0*M_PI/na;
    float beta;
    float dbeta = 1.0*M_PI/nb;

    beta = M_PI/2;
    for( int j=0; j<nb; j++, beta-=dbeta)
    {
        alpha = 0;
        for( int i=0; i<na; i++, alpha+=dalpha)
        {
            OKG_POINT p;
            glBegin( GL_POLYGON );

            p = spherical(alpha,beta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha+dalpha,beta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha+dalpha,beta-dbeta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            p = spherical(alpha,beta-dbeta,1);
            glNormal3f(p.x,p.y,p.z);
            glVertex3f(x+rx*p.x,y+ry*p.y,z+rz*p.z);

            glEnd( );
        }
    }
}
Exemple #4
0
 void on_update(const UpdateEvent & e) override
 {
     cameraController.update(e.timestep_ms);
     animator.update(e.timestep_ms);
     
     auto what = spherical(zeroOne * ANVIL_PI, zeroOne * ANVIL_PI / 2);
     
     float3 newPos = float3(what.x, 1, what.z) * float3(24, 8, 24);
     std::cout << newPos << std::endl;
     camera.set_position(float3(newPos.x, newPos.y, newPos.z));
     
     // Option One
     camera.look_at(camera.pose.position, {-8, 2, 0});
     
     // Option Two
     camera.pose.orientation = qlerp(start.orientation, end.orientation, zeroOne);
 }
Exemple #5
0
//------------------------------------------------------------------------------
void BodyFixedPoint::UpdateBodyFixedLocation()
{
   if (stateType == "Cartesian")
   {
      bfLocation[0] = location[0];
      bfLocation[1] = location[1];
      bfLocation[2] = location[2];
   }
   // Otherwise, convert from input type to Cartesian
   else if (stateType == "Spherical")
   {
      Rvector3 spherical(location[0], location[1], location[2]);
      Rvector3 cart;
      if (horizon == "Sphere")
      {
         cart = BodyFixedStateConverterUtil::SphericalToCartesian(spherical,
                flattening, meanEquatorialRadius);
         bfLocation[0] = cart[0];
         bfLocation[1] = cart[1];
         bfLocation[2] = cart[2];
      }
      else if (horizon == "Ellipsoid")
      {
         cart = BodyFixedStateConverterUtil::SphericalEllipsoidToCartesian(spherical,
                flattening, meanEquatorialRadius);
         bfLocation[0] = cart[0];
         bfLocation[1] = cart[1];
         bfLocation[2] = cart[2];
      }
      else
         throw AssetException("Unable to set body fixed location for BodyFixedPoint \"" +
               instanceName + "\"; horizon reference is not a recognized type (known "
                     "types are either \"Sphere\" or \"Ellipsoid\")");
   }
   else
   {
      throw AssetException("Unable to set body fixed location for BodyFixedPoint \"" +
            instanceName + "\"; state type is not a recognized type (known "
                  "types are either \"Cartesian\" or \"Spherical\")");
   }

}
Exemple #6
0
Vector FrostedGlass::Sample(Vector* origin, Vector incident, Vector normal, float wavelength, std::mt19937* prng)
{
    /* Generate a random microfacet normal based on the Beckmann distribution with the given roughness. */
    float r1 = RandomVariable(prng);
    float r2 = RandomVariable(prng);
    float theta = atan(-pow(this->roughness, 2.0f) * log(1.0f - r1));
    float phi = 2.0f * PI * r2;
    Vector m = spherical(phi, theta);

    /* Rotate the microfacet normal according to the actual surface normal. */
    m = rotate(m, normal);

    /* Work out the correct n1 and n2 depending on the incident vector's direction relative to the normal. */
    float cosI = incident * normal;
    float n1, n2;
    if (cosI > 0)
    {
        /* Incident and normal have the same direction, ray is inside the material. */
        n1 = this->refractiveIndex->Lookup(wavelength);
        n2 = 1.0f;

        /* Flip the microfacet normal around. */
        m = ZERO - m;
    }
    else
    {
        /* Incident and normal have opposite directions, so the ray is outside the material. */
        n2 = this->refractiveIndex->Lookup(wavelength);
        n1 = 1.0f;

        /* Make the cosine positive. */
        cosI = -cosI;
    }

    /* Calculate the refracted angle's cosine. */
    float cosT = 1.0f - pow(n1 / n2, 2.0f) * (1.0f - pow(cosI, 2.0f));

    /* Check for total internal reflection. */
    if (cosT < 0.0f)
    {
        /* Total internal reflection occurred. */
        (*origin) = (*origin) + m * EPSILON;
        return reflect(incident, m);
    }

    /* Otherwise, finish computing the angle. */
    cosT = sqrt(cosT);

    /* Now, compute the Fresnel coefficients for reflection and refraction for a randomly polarized ray. */
    float R = (pow((n1 * cosI - n2 * cosT) / (n1 * cosI + n2 * cosT), 2.0f) + pow((n2 * cosI - n1 * cosT) / (n1 * cosT + n2 * cosI), 2.0f)) * 0.5f;

    /* Perform a random trial to decide whether to reflect or refract the ray. */
    if (RandomVariable(prng) < R)
    {
        /* Reflection. */
        (*origin) = (*origin) + m * EPSILON;
        return reflect(incident, m);
    }
    else
    {
        /* Refraction. */
        (*origin) = (*origin) - m * EPSILON;
        return incident * (n1 / n2) + m * ((n1 / n2) * cosI - cosT);
    }
}
Exemple #7
0
void INDIMountInterface::SkyChart_Paint( Control& sender, const Rect& updateRect )
{
   Graphics g( sender );

   RGBA darkRed = RGBAColor( 153, 0, 0 );
   RGBA darkYellow = RGBAColor( 153, 153, 0 );
   RGBA darkGreen = RGBAColor( 0, 153, 0 );

   Rect r( sender.BoundsRect() );

   int w = r.Width();
   int h = r.Height();
   int x0 = w >> 1;
   int y0 = h >> 1;

   g.FillRect( r, 0u );
   g.SetBrush( Brush::Null() );

   g.SetPen( darkRed );
   const int margin = 10;
   g.DrawLine( x0, 0+margin, x0, h-margin );
   g.DrawLine( 0+margin, y0, w-margin, y0 );

   g.EnableAntialiasing();

   if ( m_isAllSkyView )
   {
      double chartRadius = x0 - margin;
      g.DrawCircle( x0, y0, chartRadius );

      // draw telescope position
      StereoProjection::Spherical s;
      double hourAngle = (m_TargetRA.ToDouble() - m_lst)*360/24;
      double currentAlt = SkyMap::getObjectAltitude( m_TargetDEC.ToDouble(), hourAngle, m_geoLat );
      double currentAz = SkyMap::getObjectAzimut( m_TargetDEC.ToDouble(), hourAngle, m_geoLat );
      s.phi = Rad( currentAz );
      s.theta = Rad( 90 + currentAlt );
      StereoProjection::Polar p = s.Projected( chartRadius );
      StereoProjection::Rectangular r = p.ToRectangular();
#if 0
      Console().WriteLn( String().Format( "x=%f, y=%f, r=%f", r.x, r.y, chartRadius ) );
      Console().WriteLn( String().Format( "x0=%d, y0=%d", x0, y0 ) );
      Console().WriteLn( String().Format( "w=%d, h=%d", w, h ) );
      Console().WriteLn( String().Format( "phi=%f, theta=%f", s.phi, s.theta ) );
      Console().WriteLn( String().Format( "r=%f, pphi=%f", p.r, p.phi ) );
#endif
      g.DrawCircle( x0+r.x, y0+r.y, 5 );

      g.SetPen( darkGreen );
      hourAngle = (m_scopeRA - m_lst)*360/24;
      currentAlt = SkyMap::getObjectAltitude( m_scopeDEC, hourAngle, m_geoLat );
      currentAz = SkyMap::getObjectAzimut( m_scopeDEC, hourAngle, m_geoLat );
      s.phi = Rad( currentAz );
      s.theta = Rad( 90 + currentAlt );
      r = s.Projected( chartRadius ).ToRectangular();
      g.DrawCircle( x0+r.x, y0+r.y, 5 );

      g.SetPen( darkYellow );
      if ( m_skymap != nullptr )
         m_skymap->plotStars( m_lst, m_geoLat, x0, y0, chartRadius, g, m_limitStarMag );
   }
   else
   {
      if ( m_skymap != nullptr )
      {
         double CCD_chipHeight = 2200;
         double CCD_chipWidth = 2750;
         double CCD_pixelSize = 4.54/1000;
         double TEL_focalLength = 700;
         double FoV_width = CCD_chipWidth*CCD_pixelSize  / TEL_focalLength*3438/60;
         double FoV_height = CCD_chipHeight*CCD_pixelSize / TEL_focalLength*3438/60;
         double scale = 180.0/FoV_width;

         // draw scope position
         double currentAlt = SkyMap::getObjectAltitude( m_scopeDEC, m_scopeRA*360/24, m_geoLat );
         double currentAz = SkyMap::getObjectAzimut( m_scopeDEC, m_scopeRA*360/24, m_geoLat );

         StereoProjection::Spherical spherical( Rad( currentAz ), Rad( 90 + currentAlt ) );
         StereoProjection::Polar p = spherical.Projected( scale*x0 );
         StereoProjection::Rectangular r = p.ToRectangular();

         //Console().WriteLn( String().Format( "xx=%f, yy=%f, r=%f", r.x, r.y, scale * x0 ) );
         g.DrawCircle( x0, y0, 5 );

         // draw alignment deviation
         double alignAlt = SkyMap::getObjectAltitude( m_alignedDEC, m_alignedRA*360/24, m_geoLat );
         double alignAz = SkyMap::getObjectAzimut( m_alignedDEC, m_alignedRA*360/24, m_geoLat );
         StereoProjection::Rectangular rAlign =
            StereoProjection::Spherical( Rad( alignAz ), Rad( 90 + alignAlt ) ).Projected( scale*x0 ).ToRectangular();
         g.SetPen( darkGreen );
         g.DrawLine( x0 - r.x + r.x,
                     y0 - r.y + r.y,
                     x0 - r.x + rAlign.x,
                     y0 - r.y + rAlign.y );

         m_skymap->plotFoVStars( m_lst, m_geoLat, x0-r.x, y0-r.y, scale*x0, g, 13 );
      }
   }
}
Exemple #8
0
double *call_map_model(double la,double lo,double lambda0, double phi0,int brightness_model,double *brightness_params,double **bb_g,int make_grid,double theta1, double theta2, double r1, double r2, double star_bright,double la_cen,double lo_cen, double *lo_2d, double *la_2d, double **T_2d, double **y1_grid, double **y2_grid, double **y12_grid){
    double point_T,mu,p_t_bright,point_b;
    double l1,l2;
    double *output;

    double R = 1.0;
    int n_bb_seg = 10;

    point_T = 0.0;
    point_b = 0.0;

//    printf("bb_g %f\n",bb_g[0][1]);

    if(brightness_model == 1 || brightness_model == 3 || brightness_model == 4 || brightness_model == 6|| brightness_model == 8|| brightness_model == 10|| brightness_model == 11|| brightness_model == 12) {
        l1 = brightness_params[1];
        l2 = brightness_params[2];
    }
    if(brightness_model == 0){
        point_b = Uniform_b(brightness_params[0]);
    }
    else if(brightness_model == 1){
        point_T = Uniform_T(brightness_params[3]);
        point_b = bb_interp(point_T, bb_g);
    }

//    if(brightness_model == 2){
//        double p_day = brightness_params[0];
//        double p_night = brightness_params[1];
//        point_b = Two_b(la,lo,p_day,p_night);
//    }
//    if(brightness_model == 3){
//        double p_day = brightness_params[3];
//        double p_night = brightness_params[4];
//        double point_T = p_night;
//        point_T = Two_T(la,lo,p_day,p_night);
//        point_b = bb_interp(point_T, bb_g);
//    }

    else if(brightness_model == 4){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        point_T = zhang_2016(la,lo,xi,T_n,delta_T);
        point_b = bb_interp(point_T, bb_g);
    }
    else if(brightness_model == 5){

        point_b = spherical(la,lo,brightness_params,0);
    }

    else if(brightness_model == 14){

        point_T = spherical(la,lo,brightness_params,1);
        point_b = bb_interp(point_T, bb_g); 
    }

    else if(brightness_model == 6){
       double insol = brightness_params[3];
       double albedo = brightness_params[4];
       double redist = brightness_params[5];
       point_T = kreidberg_2016(la, lo, insol, albedo, redist);
       point_b = bb_interp(point_T, bb_g); 
    }

    else if(brightness_model == 2 || brightness_model == 7){
        double la0 = brightness_params[0];
        double lo0 = brightness_params[1];
        double p_b = brightness_params[2];
        double spot_b = brightness_params[4];
        double size = brightness_params[5];
//        printf("%f %f %f %f %f\n",la0,lo0,p_b,spot_b,size);
        point_b = Hotspot_b(la, lo, la0,lo0,p_b,spot_b,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
     }

    else if(brightness_model == 3 || brightness_model == 8){
        double la0 = brightness_params[4];
        double lo0 = brightness_params[5];
        double p_T = brightness_params[6];
        double spot_T = brightness_params[7];
        double size = brightness_params[8];
        double b1 = bb_interp(p_T, bb_g); 
        double b2 = bb_interp(spot_T, bb_g); 
        point_T = Hotspot_b(la, lo, la0,lo0,p_T,spot_T,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
        point_b = Hotspot_b(la, lo, la0,lo0,b1,b2,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
    }
    else if(brightness_model == 9){
        double albedo = brightness_params[3];
        double ars = pow(brightness_params[4],2);
        double insol = ars*star_bright;
//        printf("%f \n",insol*M_PI);
        point_b = lambertian(la,lo,insol,albedo);
    }
    else if(brightness_model == 10){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        point_T = zhang_2016(la,lo,xi,T_n,delta_T);
        point_b = bb_interp(point_T, bb_g);

        double albedo = brightness_params[6];
        double ars = pow(brightness_params[7],2);
        double insol = ars*star_bright;
        point_b = point_b + lambertian(la,lo,insol,albedo);
    }

    else if(brightness_model == 11){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        double clouds = brightness_params[6];

        point_T = zhang_2016(la,lo,xi,T_n,delta_T);

        point_b = bb_interp(point_T, bb_g);

        if(pow(lo,2) > pow(M_PI/2.0,2)){
            point_b = point_b - clouds;
        }
    }

    else if(brightness_model == 12 || brightness_model == 13){

/*        printf("\n");
        printf("%f\n",lo*180.0/M_PI);
        printf("%i\n",find_minimum(lo_2d, lo*180.0/M_PI, (int) brightness_params[3]));
        printf("%f\n",lo_2d[find_minimum(lo_2d, lo*180.0/M_PI, (int) brightness_params[3])]);
        printf("\n");*/

        int *out1;
        out1 = malloc(sizeof(int) * 2);

        int *out2;
        out2 = malloc(sizeof(int) * 2);

        int nlo, nla, nearest;

        if(brightness_model == 12){
            nlo = brightness_params[3];
            nla = brightness_params[4];
            nearest = brightness_params[5];
        }
        if(brightness_model == 13){
            nlo = brightness_params[0];
            nla = brightness_params[1];
            nearest = brightness_params[2];
        }

        find_top_two(lo_2d, lo*180.0/M_PI, (int) nlo, out1);

//        printf("before second %i\n",(int) brightness_params[4]);
        find_top_two(la_2d, la*180.0/M_PI, (int) nla, out2);

//        printf("positions %i %i %i %i %i %i\n",out1[0],out1[1],out2[0],out2[1],nlo,nla);
//        printf("positions %f %f %f %f\n",lo_2d[out1[0]],lo_2d[out1[1]],la_2d[out2[0]],la_2d[out2[1]]);

        float *ansy, *ansy1, *ansy2;

        ansy = malloc(sizeof(float) * 1);
        ansy1 = malloc(sizeof(float) * 1);
        ansy2 = malloc(sizeof(float) * 1);

        float *y,*y1,*y2,*y12;
        y = malloc(sizeof(float) * 5);
        y1 = malloc(sizeof(float) * 5);
        y2 = malloc(sizeof(float) * 5);
        y12 = malloc(sizeof(float) * 5);

        y[1] = T_2d[out1[0]][out2[0]];
        y[2] = T_2d[out1[1]][out2[0]];
        y[3] = T_2d[out1[1]][out2[1]];
        y[4] = T_2d[out1[0]][out2[1]];

        y1[1] = y1_grid[out1[0]][out2[0]];
        y1[2] = y1_grid[out1[1]][out2[0]];
        y1[3] = y1_grid[out1[1]][out2[1]];
        y1[4] = y1_grid[out1[0]][out2[1]];

        y2[1] = y2_grid[out1[0]][out2[0]];
        y2[2] = y2_grid[out1[1]][out2[0]];
        y2[3] = y2_grid[out1[1]][out2[1]];
        y2[4] = y2_grid[out1[0]][out2[1]];

        y12[1] = y12_grid[out1[0]][out2[0]];
        y12[2] = y12_grid[out1[1]][out2[0]];
        y12[3] = y12_grid[out1[1]][out2[1]];
        y12[4] = y12_grid[out1[0]][out2[1]];


//        printf("%f %f %f %f %f %f\n",lo_2d[out1[0]],lo_2d[out1[1]], la_2d[out2[0]], la_2d[out2[1]], lo*180.0/M_PI, la*180.0/M_PI);
        bcuint(y, y1, y2, y12, lo_2d[out1[0]],lo_2d[out1[1]], la_2d[out2[0]], la_2d[out2[1]], lo*180.0/M_PI, la*180.0/M_PI, ansy, ansy1, ansy2);

        if (nearest == 1) {
            int c_lo = find_minimum(lo_2d, lo*180.0/M_PI, (int) nlo);
            int c_la = find_minimum(la_2d, la*180.0/M_PI, (int) nla);
            *ansy = T_2d[c_lo][c_la];
        }

        if(brightness_model == 12){
            point_T = *ansy;
            point_b = bb_interp(point_T, bb_g);
        }
        if(brightness_model == 13){
            point_b = *ansy;
        }

        free(out1);
        free(out2);

        free(y);
        free(y1);
        free(y2);
        free(y12);

        free(ansy);
        free(ansy1);
        free(ansy2);

        }
    else{
        printf("BRIGHTNESS MODEL NOT RECOGNISED\n");
    }

//        printf("%f %f %f\n",ars, star_bright,insol);
    output = malloc(sizeof(double) * 2); // dynamic `array (size 2) of pointers to double`

    output[0] = point_b;
    output[1] = point_T;

    return output;

}