コード例 #1
0
void make_crater_list() {
	int j;
        float theta;

	listnum = glGenLists(1);
	glNewList(listnum, GL_COMPILE);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glColor3f(0.27, 0.3, 0.27);
	for(j = 0; j < NUM_CRATERS; j++) {
		glPushMatrix();
		glTranslatef(x[j], 0.0, y[j]);

		glBegin(GL_TRIANGLE_STRIP);
		if (BINC * sqrt(x[j]*x[j] + y[j]*y[j]) > 2 * M_PI / 5) {
			draw_outside(radius[j], height[j], 2 * M_PI / 5 );
			draw_inside(radius[j], height[j], 2 * M_PI / 5);
 		}
		draw_outside(radius[j], height[j], BINC * sqrt(x[j]*x[j] + y[j]*y[j]));
		draw_inside(radius[j], height[j], BINC * sqrt(x[j]*x[j] + y[j]*y[j]));
		glEnd();
		glPopMatrix();
	}

        do_terrain();

	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glColor3f(0.05, 0.07, 0.05);
	for(j = 0; j < NUM_CRATERS; j++) {
		glPushMatrix();
		glTranslatef(x[j], 0.0, y[j]);

		glBegin(GL_QUADS);
		draw_lines(radius[j], height[j], WINC);
		glEnd();

		glPopMatrix();
	}

	glEndList();
}
コード例 #2
0
ファイル: gears2.c プロジェクト: OS2World/DEV-UTIL-MGL
void
gear(int nt, float wd, float ir, float or, float sa, float tp, float tip, int ns, Profile * ip)
{
  /**
   * nt - number of teeth 
   * wd - width of gear at teeth
   * ir - inside radius absolute scale
   * or - radius at outside of wheel (tip of tooth) ratio of ir
   * sa - angle of slant of teeth on gear (1 = slant of one whole tooth)
   * tp - ratio of tooth in slice of circle (0..1] (1 = teeth are touching at base)
   * tip - ratio of tip of tooth (0..tp] (cant be wider that base of tooth)
   * ns - number of elements in wheel width profile
   * *ip - list of float pairs {start radius, width, ...} (width is ratio to wd)
   *
   */

  /* gear lying on xy plane, z for width. all normals calulated 
     (normalized) */

  float prev;
  int k, t;

  /* estimat # times to divide circle */
  if (nt <= 0)
    circle_subdiv = 64;
  else {
    /* lowest multiple of number of teeth */
    circle_subdiv = nt;
    while (circle_subdiv < 64)
      circle_subdiv += nt;
  }

  /* --- draw wheel face --- */

  /* draw horzontal, vertical faces for each section. if first
     section radius not zero, use wd for 0.. first if ns == 0
     use wd for whole face. last width used to edge.  */

  if (ns <= 0) {
    flat_face(0.0, ir, wd);
  } else {
    /* draw first flat_face, then continue in loop */
    if (ip[0].rad > 0.0) {
      flat_face(0.0, ip[0].rad * ir, wd);
      prev = wd;
      t = 0;
    } else {
      flat_face(0.0, ip[1].rad * ir, ip[0].wid * wd);
      prev = ip[0].wid;
      t = 1;
    }
    for (k = t; k < ns; k++) {
      if (prev < ip[k].wid) {
        draw_inside(prev * wd, ip[k].wid * wd, ip[k].rad * ir);
      } else {
        draw_outside(prev * wd, ip[k].wid * wd, ip[k].rad * ir);
      }
      prev = ip[k].wid;
      /* - draw to edge of wheel, add final face if needed - */
      if (k == ns - 1) {
        flat_face(ip[k].rad * ir, ir, ip[k].wid * wd);

        /* now draw side to match tooth rim */
        if (ip[k].wid < 1.0) {
          draw_inside(ip[k].wid * wd, wd, ir);
        } else {
          draw_outside(ip[k].wid * wd, wd, ir);
        }
      } else {
        flat_face(ip[k].rad * ir, ip[k + 1].rad * ir, ip[k].wid * wd);
      }
    }
  }

  /* --- tooth side faces --- */
  tooth_side(nt, ir, or, tp, tip, wd);

  /* --- tooth hill surface --- */
}