Ejemplo n.º 1
0
void
HGE_distorted_set_displacement(HGE_distorted_t* d, int x, int y, GLfloat dx, GLfloat dy, int ref)
{
  HGE_c4ub_v2f_t* vertex = GET_VERTEX(d,x,y);
  GLfloat fw = (GLfloat)(d->grid_w - 1);
  GLfloat fh = (GLfloat)(d->grid_h - 1);

  switch(ref)
    {
    default:
    case HGE_DISTORT_POINT_ABS:
      dx += (d->img->w * ((GLfloat)x / fw));
      dy += (d->img->h * ((GLfloat)y / fh));      
      break;

    case HGE_DISTORT_POINT_REL:
      dx += vertex->x;
      dy += vertex->y;
      break;

    case HGE_DISTORT_TOPLEFT:
      break;

    case HGE_DISTORT_CENTER:
      dx += (d->img->w * 0.5);
      dy += (d->img->h * 0.5);
      break;
    }

  vertex->x = dx;
  vertex->y = dy;
}
Ejemplo n.º 2
0
void
HGE_distorted_set_color(HGE_distorted_t* d, int x, int y, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
{
  HGE_c4ub_v2f_t* vertex = GET_VERTEX(d,x,y);

  vertex->r = r;
  vertex->g = g;
  vertex->b = b;
  vertex->a = a;
}
Ejemplo n.º 3
0
void
HGE_distorted_get_color(HGE_distorted_t* d, int x, int y, GLubyte* r, GLubyte* g, GLubyte* b, GLubyte* a)
{
  HGE_c4ub_v2f_t* vertex = GET_VERTEX(d,x,y);

  if(r != NULL)
    *r = vertex->r;
  if(g != NULL)
    *g = vertex->g;
  if(b != NULL)
    *b = vertex->b;
  if(a != NULL)
    *a = vertex->a;
}
Ejemplo n.º 4
0
void
HGE_distorted_get_displacement(HGE_distorted_t* d, int x, int y, GLfloat* dx, GLfloat* dy, int ref)
{
  HGE_c4ub_v2f_t* vertex = GET_VERTEX(d,x,y);
  GLfloat fw = (GLfloat)(d->grid_w - 1);
  GLfloat fh = (GLfloat)(d->grid_h - 1);
  
  if(dx != NULL)
    {
      switch(ref)
	{
	default:
	case HGE_DISTORT_POINT_ABS:
	  *dx = vertex->x - (d->img->w * (GLfloat)x / fw);
	  break;
	case HGE_DISTORT_POINT_REL:
	  *dx = vertex->x - (d->img->w * (GLfloat)x / fw);
	  break;
	case HGE_DISTORT_TOPLEFT:
	  *dx = vertex->x;
	  break;
	case HGE_DISTORT_CENTER:
	  *dx = vertex->x - (d->img->w * 0.5);
	  break;
	}
    }

  if(dy != NULL)
    {
      switch(ref)
	{
	default:
	case HGE_DISTORT_POINT_ABS:
	  *dy = vertex->y - (d->img->h * (GLfloat)y / fh);
	  break;
	case HGE_DISTORT_POINT_REL:
	  *dy = vertex->y - (d->img->h * (GLfloat)y / fh);
	  break;
	case HGE_DISTORT_TOPLEFT:
	  *dy = vertex->y;
	  break;
	case HGE_DISTORT_CENTER:
	  *dy = vertex->y - (d->img->h * 0.5);
	  break;
	}
    }
}
/**
 * Read a polygon file and convert it to an NMG shell
 *
 * A polygon file consists of the following:
 *
 * The first line consists of two integer numbers: the number of
 * points (vertices) in the file, followed by the number of polygons
 * in the file.  This line is followed by lines for each of the
 * vertices.  Each vertex is listed on its own line, as the 3tuple "X
 * Y Z".  After the list of vertices comes the list of polygons.
 * each polygon is represented by a line containing 1) the number of
 * vertices in the polygon, followed by 2) the indices of the
 * vertices that make up the polygon.
 *
 * Implicitly returns r->s_p which is a new shell containing all the
 * faces from the polygon file.
 *
 * XXX This is a horrible way to do this.  Lee violates his own rules
 * about not creating fundamental structures on his own...  :-)
 * Retired in favor of more modern tessellation strategies.
 */
struct shell *
nmg_polytonmg(FILE *fp, struct nmgregion *r, const struct bn_tol *tol)
{
    int i, j, num_pts, num_facets, pts_this_face, facet;
    int vl_len;
    struct vertex **v;  /* list of all vertices */
    struct vertex **vl; /* list of vertices for this polygon*/
    point_t p;
    struct shell *s;
    struct faceuse *fu;
    struct loopuse *lu;
    struct edgeuse *eu;
    plane_t plane;
    struct model *m;

    s = nmg_msv(r);
    m = s->r_p->m_p;
    nmg_kvu(s->vu_p);

    /* get number of points & number of facets in file */
    if (fscanf(fp, "%d %d", &num_pts, &num_facets) != 2)
	bu_bomb("polytonmg() Error in first line of poly file\n");
    else
	if (RTG.NMG_debug & DEBUG_POLYTO)
	    bu_log("points: %d facets: %d\n",
		   num_pts, num_facets);


    v = (struct vertex **) bu_calloc(num_pts, sizeof (struct vertex *),
				     "vertices");

    /* build the vertices */
    for (i = 0; i < num_pts; ++i) {
	GET_VERTEX(v[i], m);
	v[i]->magic = NMG_VERTEX_MAGIC;
    }

    /* read in the coordinates of the vertices */
    for (i=0; i < num_pts; ++i) {
	if (fscanf(fp, "%lg %lg %lg", &p[0], &p[1], &p[2]) != 3)
	    bu_bomb("polytonmg() Error reading point");
	else
	    if (RTG.NMG_debug & DEBUG_POLYTO)
		bu_log("read vertex #%d (%g %g %g)\n",
		       i, p[0], p[1], p[2]);

	nmg_vertex_gv(v[i], p);
    }

    vl = (struct vertex **)bu_calloc(vl_len=8, sizeof (struct vertex *),
				     "vertex parameter list");

    for (facet = 0; facet < num_facets; ++facet) {
	if (fscanf(fp, "%d", &pts_this_face) != 1)
	    bu_bomb("polytonmg() error getting pt count for this face");

	if (RTG.NMG_debug & DEBUG_POLYTO)
	    bu_log("facet %d pts in face %d\n",
		   facet, pts_this_face);

	if (pts_this_face > vl_len) {
	    while (vl_len < pts_this_face) vl_len *= 2;
	    vl = (struct vertex **)bu_realloc((char *)vl,
					      vl_len*sizeof(struct vertex *),
					      "vertex parameter list (realloc)");
	}

	for (i=0; i < pts_this_face; ++i) {
	    if (fscanf(fp, "%d", &j) != 1)
		bu_bomb("polytonmg() error getting point index for v in f");
	    vl[i] = v[j-1];
	}

	fu = nmg_cface(s, vl, pts_this_face);
	lu = BU_LIST_FIRST(loopuse, &fu->lu_hd);
	/* XXX should check for vertex-loop */
	eu = BU_LIST_FIRST(edgeuse, &lu->down_hd);
	NMG_CK_EDGEUSE(eu);
	if (bn_mk_plane_3pts(plane, eu->vu_p->v_p->vg_p->coord,
			     BU_LIST_PNEXT(edgeuse, eu)->vu_p->v_p->vg_p->coord,
			     BU_LIST_PLAST(edgeuse, eu)->vu_p->v_p->vg_p->coord,
			     tol)) {
	    bu_log("At %d in %s\n", __LINE__, __FILE__);
	    bu_bomb("polytonmg() cannot make plane equation\n");
	} else nmg_face_g(fu, plane);
    }

    for (i=0; i < num_pts; ++i) {
	if (BU_LIST_IS_EMPTY(&v[i]->vu_hd)) continue;
	FREE_VERTEX(v[i]);
    }
    bu_free((char *)v, "vertex array");
    return s;
}