示例#1
0
文件: sprite.c 项目: lolitrain/marisa
void sprite_draw(struct sprite* s, float cx, float cy, float angle)
{
	float w2 = s->width/2;
	float h2 = s->height/2;
	int i;
	float sint = sin(torad(angle));
	float cost = cos(torad(angle));
	struct matrix2d rotation = { {
		{cost, -sint},
		{sint, cost} }};
	struct vector2d v[4] = { {{-w2, -h2}}, {{-w2, h2}}, {{w2, h2}}, {{w2,-h2}} };

	for(i=0; i<4;i++)
	{
		v[i] = matrix_vec_mult(rotation.m, v[i].vec);
	}

	for(i=0; i<4;i++)
	{
		v[i].vec[0] += cx;
		v[i].vec[1] += cy;
	}

	gl_bind_texture(s->texture);

	gl_vertex(v[0].vec[0], v[0].vec[1], 0, 0,0);
	gl_vertex(v[1].vec[0], v[1].vec[1], 0, 0,1);
	gl_vertex(v[2].vec[0], v[2].vec[1], 0, 1,1);
	gl_vertex(v[3].vec[0], v[3].vec[1], 0, 1,0);
}
示例#2
0
void do_goals_calculations(double v0) {
	std::cout.precision(3);
	std::cout<<"DEG\tLOW\tMID\tHIGH"<<std::endl;
	for(double a=LOW_ANGLE;a<=HIGH_ANGLE;a+=ANGLE_STEP) {
		double vx0=v0*std::cos(torad(a));
		double vy0=v0*std::sin(torad(a));
		std::cout<<a<<"°\t";
		std::cout<<tofeet(simulate_flight(vx0,vy0,a,DELTAT,tometers(LOW_TARGET)))<<"\t";
		std::cout<<tofeet(simulate_flight(vx0,vy0,a,DELTAT,tometers(MID_TARGET)))<<"\t";
		std::cout<<tofeet(simulate_flight(vx0,vy0,a,DELTAT,tometers(HIGH_TARGET)))<<std::endl;
	}
}
示例#3
0
void makePov(int type) {
    int xres, yres;
    float x,y,z;
    double c1 = cos(torad(-rotation-10));
    double s1 = sin(torad(-rotation-10));
    double c2 = cos(torad(-tilt-20));
    double s2 = sin(torad(-tilt-20));
    
    xres = resolution * 1.25 + 0.5;
    yres = 0.8 * xres + 0.5;
    
    while (True) {
        if (1.0 * xres / yres > 1.25) {
            yres++;
        } else if (1.0 * xres / yres < 1.25) {
            xres++;
        } else {
            break;
        }
    }
    
    x = -c1 * xeye + s1 * zeye;
    y = s1 * s2 * xeye - c2 * yeye + s2 * c1 * zeye;
    z = -c2 * s1 * xeye - s2 * yeye - c2 * c1 * zeye;
    
    gr3_setlightdirection(x, y, z);
    gr3_setquality(GR3_QUALITY_POVRAY_8X_SSAA);
    if (povray == -9999) {
        moldyn_export_(type,xres,yres);
    } else if (povray > 0) {
        rewind(fptr);
        current_cycle = 0;
        while (True) {
            read_cycle();
            if (file_done)
                break;
            moldyn_update_graphics();
            moldyn_export_(type,xres,yres);
        }
    }
    gr3_setquality(GR3_QUALITY_OPENGL_NO_SSAA);
    gr3_setlightdirection(0, 0, 0);
}
示例#4
0
void moldyn_display_callback(void) {
    int err;
    double x, y, z, fx, fy, fz, ux, uy, uz;
    double c1 = cos(torad(-rotation));
    double s1 = sin(torad(-rotation));
    double c2 = cos(torad(-tilt));
    double s2 = sin(torad(-tilt));
    /* Transform the view */
    x = -c1 * xeye + s1 * zeye;
    y = s1 * s2 * xeye - c2 * yeye + s2 * c1 * zeye;
    z = -c2 * s1 * xeye - s2 * yeye - c2 * c1 * zeye;
    fx = x + s1;
    fy = y + s2 * c1;
    fz = z - c2 * c1;
    ux = 0;
    uy = c2;
    uz = s2;
    
    gr3_setcameraprojectionparameters(45, 0.5, 7.0 * range);
    gr3_cameralookat(x, y, z, fx, fy, fz, ux, uy, uz);
    err = gr3_drawimage(0, window_width, 0, window_height, window_width, window_height, GR3_DRAWABLE_OPENGL);
    if (err) {
        moldyn_error(gr3_geterrorstring(err));
    }
    
    moldyn_display_text_();
    
    if (box) {
        moldyn_display_box_();
    }
    
    glutSwapBuffers();
    
    if (show_stat == HOLD) {
        glutIdleFunc(NULL);    
    } else if (show_stat == SHOW_NEXT || show_stat == SHOW_PREV) {
        show_stat = HOLD;
    } else if (show_stat == SHOW_ALL) {
        return;
    }
}
示例#5
0
文件: moon.c 项目: Yomin/remind
static double kepler(double m, double ecc)
{
    double e, delta;
#define EPSILON 1E-6

    e = m = torad(m);
    do {
	delta = e - ecc * sin(e) - m;
	e -= delta / (1 - ecc * cos(e));
    } while (abs(delta) > EPSILON);
    return e;
}
示例#6
0
文件: crcal.c 项目: tlapicka/crcal
/* Funkce vyzvedne ze zásobníku číslo, provede s nimi
 * matematickou operace danou parametrem function a výsledek
 * uloží zpět do zásobníku.
 * Funkce vrací FALSE pokud operaci nelze provést.
 */
bool make1param(Oper1par function)
{
    complex double x;
    if (isnan(x = pop())) {
        return false;
    }
    if (function == csin || function == ccos || function == ctan) {
        push(function(torad(x)), EOF);
    } else if (function == casin || function == cacos || function == catan) {
        push(radto(function(x)), EOF);
    } else {
        push(function(x), EOF);
    }
    return true;
}
示例#7
0
文件: tamo_moon.c 项目: tsupo/tamo
static double
phase( double pdate,
       double *pphase,      /* Illuminated fraction        */
       double *mage,        /* Age of moon in days         */
       double *dist,        /* Distance in kilometres      */
       double *angdia,      /* Angular diameter in degrees */
       double *sudist,      /* Distance to Sun             */
       double *suangdia )   /* Sun's angular diameter      */
{
    double  Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
            mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon,
            MoonAge, MoonPhase,
            MoonDist, MoonDFrac, MoonAng,
            F, SunDist, SunAng;

    /* Calculation of the Sun's position */

    Day = pdate - epoch;                    /* Date within epoch */
    N = fixangle((360.0 / 365.2422) * Day); /* Mean anomaly of the Sun */
    M = fixangle(N + elonge - elongp);      /* Convert from perigee
                                               co-ordinates to epoch 1980.0 */
    Ec = kepler(M, eccent);                 /* Solve equation of Kepler */
    Ec = sqrt((1.0 + eccent) / (1.0 - eccent)) * tan(Ec / 2.0);
    Ec = 2.0 * todeg(atan(Ec));             /* True anomaly */
    Lambdasun = fixangle(Ec + elongp);      /* Sun's geocentric ecliptic
                                               longitude */
    /* Orbital distance factor */
    F = ((1.0 + eccent * cos(torad(Ec))) / (1.0 - eccent * eccent));
    SunDist = sunsmax / F;              /* Distance to Sun in km */
    SunAng = F * sunangsiz;             /* Sun's angular size in degrees */

    /* Calculation of the Moon's position */
    /* Moon's mean longitude */
    ml = fixangle(13.1763966 * Day + mmlong);

    /* Moon's mean anomaly */
    MM = fixangle(ml - 0.1114041 * Day - mmlongp);

    /* Moon's ascending node mean longitude */
    MN = fixangle(mlnode - 0.0529539 * Day);

    /* Evection */
    Ev = 1.2739 * sin(torad(2.0 * (ml - Lambdasun) - MM));

    /* Annual equation */
    Ae = 0.1858 * sin(torad(M));

    /* Correction term */
    A3 = 0.37 * sin(torad(M));

    /* Corrected anomaly */
    MmP = MM + Ev - Ae - A3;

    /* Correction for the equation of the centre */
    mEc = 6.2886 * sin(torad(MmP));

    /* Another correction term */
    A4 = 0.214 * sin(torad(2.0 * MmP));

    /* Corrected longitude */
    lP = ml + Ev + mEc - Ae + A4;

    /* Variation */
    V = 0.6583 * sin(torad(2.0 * (lP - Lambdasun)));

    /* True longitude */
    lPP = lP + V;

    /* Corrected longitude of the node */
    NP = MN - 0.16 * sin(torad(M));

    /* Y inclination coordinate */
    y = sin(torad(lPP - NP)) * cos(torad(minc));

    /* X inclination coordinate */
    x = cos(torad(lPP - NP));

    /* Ecliptic longitude */
    Lambdamoon = todeg(atan2(y, x));
    Lambdamoon += NP;

#if 0
    /* Ecliptic latitude */
    (void)todeg(asin(sin(torad(lPP - NP)) * sin(torad(minc))));
#endif

    /* Calculation of the phase of the Moon */
    /* Age of the Moon in degrees */
    MoonAge = lPP - Lambdasun;

    /* Phase of the Moon */
    MoonPhase = (1.0 - cos(torad(MoonAge))) / 2.0;

    /* Calculate distance of moon from the centre of the Earth */

    MoonDist = (msmax * (1.0 - mecc * mecc)) /
                   (1.0 + mecc * cos(torad(MmP + mEc)));

    /* Calculate Moon's angular diameter */

    MoonDFrac = MoonDist / msmax;
    MoonAng = mangsiz / MoonDFrac;

#if	0
    /* Calculate Moon's parallax */
    MoonPar = mparallax / MoonDFrac;
#endif
    *pphase   = MoonPhase;
    *mage     = synmonth * (fixangle(MoonAge) / 360.0);
    *dist     = MoonDist;
    *angdia   = MoonAng;
    *sudist   = SunDist;
    *suangdia = SunAng;
    return fixangle(MoonAge) / 360.0;
}
示例#8
0
void moldyn_update_graphics(void) {
    double x, y, z, fx, fy, fz, ux, uy, uz;
    double c1 = cos(torad(-rotation));
    double s1 = sin(torad(-rotation));
    double c2 = cos(torad(-tilt));
    double s2 = sin(torad(-tilt));
    /* Transform the view */
    x = -c1 * xeye + s1 * zeye;
    y = s1 * s2 * xeye - c2 * yeye + s2 * c1 * zeye;
    z = -c2 * s1 * xeye - s2 * yeye - c2 * c1 * zeye;
    fx = x + s1;
    fy = y + s2 * c1;
    fz = z - c2 * c1;
    ux = 0;
    uy = c2;
    uz = s2;
    
    gr3_setcameraprojectionparameters(45, 0.5, 7.0 * range);
    gr3_cameralookat(x, y, z, fx, fy, fz, ux, uy, uz);
    if (file_done) { /* TODO: disable NEXT in a better way */
        last_init_done = True;
    }
    
    gr3_clear();
    if (num_atoms > 0) {
        if (colors) {
            gr3_drawspheremesh(num_atoms, atom_positions, atom_colors, atom_radii);
        } else {
            float *atom_color_replacement = (float *)malloc(num_atoms*sizeof(float)*3);
            if (!atom_color_replacement) {
                moldyn_error("Failed to allocate memory for atom_color_replacement.");
            } else {
                int i;
                for (i = 0; i < num_atoms*3; i++) {
                    atom_color_replacement[i] = 1.0f;
                }
                gr3_drawspheremesh(num_atoms, atom_positions, atom_color_replacement, atom_radii);
                free(atom_color_replacement);
            }
        }
    }
    
    if (format == xyz) {
        int i;
        int num_spins = 0;
        float spin_len = 1;
        float spintop_len = 0.4;
        float *spin_positions;
        float *spin_directions;
        float *spin_colors;
        float *spin_radii;
        float *spin_lengths;
        for (i = 0; i < num_atoms; i++) {
            if (atom_spins[3*i+0] != 0 || atom_spins[3*i+1] != 0 || atom_spins[3*i+2] != 0) {
                num_spins++;
            }
        }
        spin_positions = (float *) malloc(sizeof(float) * 3 * num_spins);
        spin_directions = (float *) malloc(sizeof(float) * 3 * num_spins);
        spin_colors = (float *) malloc(sizeof(float) * 3 * num_spins);
        spin_radii = (float *) malloc(sizeof(float) * num_spins);
        spin_lengths = (float *) malloc(sizeof(float) * num_spins);
        for (i = 0; i < num_atoms; i++) {
            if (atom_spins[3*i+0] != 0 || atom_spins[3*i+1] != 0 || atom_spins[3*i+2] != 0) {
                spin_positions[3*i+0] = atom_positions[3*i+0] - atom_spins[3*i+0]/2*spin_len;
                spin_positions[3*i+1] = atom_positions[3*i+1] - atom_spins[3*i+1]/2*spin_len;
                spin_positions[3*i+2] = atom_positions[3*i+2] - atom_spins[3*i+2]/2*spin_len;
                spin_directions[3*i+0] = atom_spins[3*i+0];
                spin_directions[3*i+1] = atom_spins[3*i+1];
                spin_directions[3*i+2] = atom_spins[3*i+2];
                spin_colors[3*i+0] = 1;
                spin_colors[3*i+1] = 1;
                spin_colors[3*i+2] = 1;
                spin_lengths[i] = spin_len;
                spin_radii[i] = cyl_rad;
            }
        }
        gr3_drawcylindermesh(num_spins, spin_positions, spin_directions, spin_colors, spin_radii, spin_lengths);
        for (i = 0; i < num_atoms; i++) {
            if (atom_spins[3*i+0] != 0 || atom_spins[3*i+1] != 0 || atom_spins[3*i+2] != 0) {
                spin_positions[3*i+0] = atom_positions[3*i+0] + atom_spins[3*i+0]/2*spin_len;
                spin_positions[3*i+1] = atom_positions[3*i+1] + atom_spins[3*i+1]/2*spin_len;
                spin_positions[3*i+2] = atom_positions[3*i+2] + atom_spins[3*i+2]/2*spin_len;
                spin_directions[3*i+0] = atom_spins[3*i+0];
                spin_directions[3*i+1] = atom_spins[3*i+1];
                spin_directions[3*i+2] = atom_spins[3*i+2];
                spin_colors[3*i+0] = 1;
                spin_colors[3*i+1] = 1;
                spin_colors[3*i+2] = 1;
                spin_lengths[i] = spintop_len;
                spin_radii[i] = 2*cyl_rad;
            }
        }
        gr3_drawconemesh(num_spins, spin_positions, spin_directions, spin_colors, spin_radii, spin_lengths);
        free(spin_positions);
        free(spin_directions);
        free(spin_colors);
        free(spin_radii);
        free(spin_lengths);
    }
    
    
    if (bonds) {
        int i, j, k, l;
        double vx, vy, vz, cyl_len;
        int num_bonds = 0;
        float *bond_positions;
        float *bond_directions;
        float *bond_colors;
        float *bond_radii;
        float *bond_lengths;
        
        for (i = 0; i < num_atoms; i++) {
            if (atom_numbers[i] == 0)
                continue;
            for (j = i + 1; j < num_atoms; j++) {
                if (atom_numbers[j] && atom_adjacency_matrix[i * num_atoms + j]) {
                    num_bonds++;
                }
            }
        }
        
        bond_positions = (float *) malloc(sizeof(float) * 3 * num_bonds);
        bond_directions = (float *) malloc(sizeof(float) * 3 * num_bonds);
        bond_colors = (float *) malloc(sizeof(float) * 3 * num_bonds);
        bond_radii = (float *) malloc(sizeof(float) * num_bonds);
        bond_lengths = (float *) malloc(sizeof(float) * num_bonds);
        
        for (i = 0, j = 0, l = 0; i < num_atoms; i++) {
            if (atom_numbers[i] == 0)
                continue;
            for (j = i + 1; j < num_atoms; j++) {
                if (atom_numbers[j] && atom_adjacency_matrix[i * num_atoms + j]) {
                    if (atom_positions[2+3*j] > atom_positions[2+3*i]) {
                        vx = atom_positions[0+3*j] - atom_positions[0+3*i];
                        vy = atom_positions[1+3*j] - atom_positions[1+3*i];
                        vz = atom_positions[2+3*j] - atom_positions[2+3*i];
                        k = i;
                    } else {
                        vx = atom_positions[0+3*i] - atom_positions[0+3*j];
                        vy = atom_positions[1+3*i] - atom_positions[1+3*j];
                        vz = atom_positions[2+3*i] - atom_positions[2+3*j];
                        k = j;
                    }
                    
                    cyl_len = sqrt(vx * vx + vy * vy + vz * vz);
                    bond_positions[3 * l + 0] = atom_positions[0+3*k];
                    bond_positions[3 * l + 1] = atom_positions[1+3*k];
                    bond_positions[3 * l + 2] = atom_positions[2+3*k];
                    bond_directions[3 * l + 0] = vx;
                    bond_directions[3 * l + 1] = vy;
                    bond_directions[3 * l + 2] = vz;
                    bond_lengths[l] = cyl_len;
                    bond_radii[l] = cyl_rad;
                    bond_colors[3 * l + 0] = 1;
                    bond_colors[3 * l + 1] = 1;
                    bond_colors[3 * l + 2] = 1;
                    l++;
                }
            }
        }
        gr3_drawcylindermesh(num_bonds, bond_positions, bond_directions, bond_colors, bond_radii, bond_lengths);
        
        free(bond_positions);
        free(bond_directions);
        free(bond_colors);
        free(bond_radii);
        free(bond_lengths);
    }
}
示例#9
0
文件: demo3d.c 项目: cyamauch/eggx
int main()
{
  int win, i, j, k, m, key = 0;
  int arp[5] = { 0, 3, 1, 4, 2 }, ars[7] = {
  0, 5, 3, 1, 6, 4, 2};
  double pentagon[3][5], septagon[3][7], parab[3][144], y;

  win = gopen(L, L);
  window(win, -L / 2, -L / 2, L / 2, L / 2);
  gsetbgcolor(win, ECTRL_BGCOLOR);
  newcolor(win, ECTRL_FGCOLOR);
  winname(win, "e_3d demo");
  layer(win, 0, 1);
  gsetnonblock(ENABLE);
  i = j = m = 0;

  for (i = 0; i < 144; i++) {
    y = L/(2*144.0)*i;
    parab[0][i] = 0;
    parab[1][i] = -y;
    parab[2][i] = 0.02*y*(L/2 - y);
  }

  while (key != 'q') {
    g3dsetangle(torad(40 * (1.5 + sin(j * 2 * M_PI / 30))),
		i * 2 * M_PI / 144);
    gclr(win);

    for (k = 0; k < 5; k++) {
      pentagon[0][k] =
	  L / 6 * cos(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5;
      pentagon[1][k] =
	  L / 6 * sin(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5;
      pentagon[2][k] = 0;
    }
    for (k = 0; k < 7; k++) {
      septagon[0][k] =
	  L / 6 * cos(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) -
	  L / 5;
      septagon[1][k] = 0;
      septagon[2][k] =
	  L / 6 * sin(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) +
	  L / 5;
    }
    newcolor(win, "lightsteelblue");
    newlinestyle(win, LineOnOffDash);
    for(k = 0; k < 6; k++) {
      drawline3d(win, -L/10*k, 0, 0,  -L/10*k, -L/2, 0);
      drawline3d(win, 0, -L/10*k, 0,  -L/2, -L/10*k, 0);
    }
    newlinestyle(win, LineSolid);
    newcolor(win, "red4");
    fillpoly3d(win, pentagon[0], pentagon[1], pentagon[2], 5, 0);
    newcolor(win, "green4");
    fillpoly3d(win, septagon[0], septagon[1], septagon[2], 7, 0);
    newcolor(win, ECTRL_FGCOLOR);
    drawarrow3d(win, 0, 0, 0, 0, 0, L / 3, 10, 6, 12);
    drawarrow3d(win, 0, 0, 0, 0, L / 3, 0, 10, 6, 12);
    drawarrow3d(win, 0, 0, 0, L / 3, 0, 0, 10, 6, 12);
    newcolor(win, "gold3");
    drawstr3d(win, 0, 0, L/3+10, FONTSET, 0, "z¼´");
    drawlines3d(win, parab[0], parab[1], parab[2], 144);
    y = L/(2*36.0)*(i%36);
    putimg24m3d(win, 0 - 6 *(-sin(_phi) - cos(_th)*cos(_phi)), 
                     -y - 6*(cos(_phi) - cos(_th)*sin(_phi)), 
                0.02*y*(L/2 - y) -6*sin(_th), 12, 12, Xpm_image_stone6);
    copylayer(win, 1, 0);
    i++;
    i %= 144;
    j++;
    j %= 30;
    m++;
    m %= 50;
    msleep(40);
    key = ggetch();
  }
  gcloseall();
  return 0;
}
示例#10
0
 virtual void tolatlon(double l, double s, double& lat, double& lon) const
 {
     lon = torad(todeg(lonp) + (s - s0) / res);
     lat = torad(todeg(latp) - (l - l0) / res);
 }