Example #1
0
/*
 * Phase 2 setup routine
 */
HIDDEN void
wood_setup_2(struct wood_specific *wd)
{
    mat_t xlate;
    int i;
    vect_t a_vertex, a_dir;

    register struct resource *resp = &rt_uniresource;

    /*
     * See if the user specified absolute coordinates for the vertex and
     * direction.  If so, use those instead of the RPP.
     */

    bn_mat_angles(xlate, V3ARGS(wd->rot));

    if (wd->flags & EXPLICIT_VERTEX) {
	MAT4X3PNT(wd->vertex, xlate, wd->V);
	MAT4X3PNT(wd->dir, xlate, wd->D);
    } else {
	if (wd->dz > 0.0) {
	    for (i = 0; i < 2; i++) {
		a_vertex[i] = wd->b_min[i];
		a_dir[i] = wd->b_max[i];
	    }
	    /* Z component is [2] */
	    a_vertex[2] = ((wd->b_max[2] - wd->b_min[2]) *
			   (bn_rand0to1(resp->re_randptr) * wd->dz)) + wd->b_min[2];
	    a_dir[2]    = ((wd->b_max[2] - wd->b_min[2]) *
			   (bn_rand0to1(resp->re_randptr) * wd->dz)) + wd->b_min[2];
	} else {
	    for (i = 0; i < 3; i++) {
		a_vertex[i] = ((wd->b_max[i] - wd->b_min[i]) *
			       (bn_rand0to1(resp->re_randptr) * wd->dd)) + wd->b_min[i];
		a_dir[i]    = ((wd->b_max[i] - wd->b_min[i]) *
			       (bn_rand0to1(resp->re_randptr) * wd->dd)) + wd->b_max[i];
	    }
	}
	MAT4X3PNT(wd->vertex, xlate, a_vertex);
	MAT4X3PNT(wd->dir, xlate, a_dir);
    }

    VSUB2(wd->dir, wd->dir, wd->vertex);
    VUNITIZE(wd->dir);
}
Example #2
0
/**
 *	P O P _ R A N D _ G O P --- return a random genetic operation
 *	TODO: implement other operations, weighted (like wrand) op selection
 */
int
pop_wrand_gop(void)
{
    float i = bn_rand0to1(randomer);
    if (i < 0.1)
	return REPRODUCE;
    if (i < 0.3)
	return MUTATE;
    return CROSSOVER;
}
Example #3
0
/**
 * Creates one metaball object with 'count' random points using
 * LIBWDB's mk_metaball() interface.
 */
static void
make_meatballs(struct rt_wdb *fp, const char *name, long count)
{
    static float *ctx; /* random context */
    static const int method = 1; /* 1==ISO */
    static const fastf_t threshold = 1.0;
    static const fastf_t SZ = 1000.0;

    long i;
    fastf_t **pts;

    RT_CK_WDB(fp);

    bn_rand_init(ctx, rand());
    bu_log("Creating [%s] object with %ld random point%s\n", name, count, count > 1 ? "s" : "");

    /* allocate a dynamic array of pointers to points.  this may be
     * subject to change but is presently the format mk_metaball()
     * wants.
     */
    pts = (fastf_t **)bu_calloc(count, sizeof(fastf_t*), "alloc metaball pts array");
    for (i=0; i < count; i++) {
	pts[i] = (fastf_t *)bu_malloc(sizeof(fastf_t)*5, "alloc metaball point");
    }

    /* create random metaball point values positioned randomly within
     * a cube with random field strengths.
     */
    for (i=0; i < count; i++) {
	/* just for explicit clarity */
	fastf_t x = bn_rand_half(ctx) * SZ;
	fastf_t y = bn_rand_half(ctx) * SZ;
	fastf_t z = bn_rand_half(ctx) * SZ;
	fastf_t field_strength = bn_rand0to1(ctx) * SZ / (2.0 * sqrt(count));

	VSET(pts[i], x, y, z);
	pts[i][3] = field_strength; /* something blobbly random */
	pts[i][4] = 0.0; /* sweat/goo field is unused with iso method */
    }

    /* pack the meat, create the metaball */
    mk_metaball(fp, name, count, method, threshold, (const fastf_t **)pts);

    /* free up our junk */
    for (i=0; i < count; i++) {
	bu_free(pts[i], "dealloc metaball point");
    }
    bu_free(pts, "dealloc metaball pts array");
}
Example #4
0
HIDDEN int
star_render(register struct application *ap, const struct partition *pp, struct shadework *swp, void *UNUSED(dp))
{
    /* Probably want to diddle parameters based on what part of sky */
    if (bn_rand0to1(ap->a_resource->re_randptr) >= 0.98) {
	register int i;
	register fastf_t f;
	i = (sizeof(star_colors)-1) / sizeof(star_colors[0]);

	/* "f" used for intermediate result to avoid an SGI compiler error */
	f = bn_rand0to1(ap->a_resource->re_randptr);
	i = ((double)i) * f;

	f = bn_rand0to1(ap->a_resource->re_randptr);
	VSCALE(swp->sw_color, star_colors[i], f);
    } else {
	VSETALL(swp->sw_color, 0);
    }

    if (swp->sw_reflect > 0 || swp->sw_transmit > 0)
	(void)rr_render(ap, pp, swp);

    return 1;
}
Example #5
0
int
main(int argc, char **argv)
{
    vect_t	norm;
    unsigned char	rgb[3];
    int	ix;
    double	x;
    double	size;
    int	quant;
    struct wmember head;
    vect_t	bmin, bmax, bthick;
    vect_t	r1min, r1max, r1thick;
    vect_t	lwh;		/* length, width, height */
    vect_t	pbase;

    BU_LIST_INIT( &head.l );

    MAT_IDN( identity );
    sin60 = sin(60.0 * 3.14159265358979323846264 / 180.0);

    outfp = wdb_fopen("room.g");
    mk_id( outfp, "Procedural Rooms" );

    /* Create the building */
    VSET( bmin, 0, 0, 0 );
    VSET( bmax, 80000, 60000, HEIGHT );
    VSET( bthick, 100, 100, 100 );
    make_room( "bldg", bmin, bmax, bthick, &head );

    /* Create the first room */
    VSET( r1thick, 100, 100, 0 );
    VMOVE( r1min, bmin );
    VSET( r1max, 40000, 10000, HEIGHT );
    VADD2( r1max, r1min, r1max );
    make_walls( "rm1", r1min, r1max, r1thick, NORTH|EAST, &head );
    make_carpet( "rm1carpet", r1min, r1max, "carpet.pix", &head );

    /* Create the golden earth */
    VSET( norm, 0, 0, 1 );
    mk_half( outfp, "plane", norm, -bthick[Z]-10.0 );
    rgb[0] = 240;	/* gold/brown */
    rgb[1] = 180;
    rgb[2] = 64;
    mk_region1( outfp, "plane.r", "plane", NULL, NULL, rgb );
    (void)mk_addmember( "plane.r", &head.l, NULL, WMOP_UNION );

    /* Create the display pillars */
    size = 4000;	/* separation between centers */
    quant = 5;	/* pairs */
    VSET( lwh, 400, 400, 1000 );
    for ( ix=quant-1; ix>=0; ix-- )  {
	x = 10000 + ix*size;
	VSET( pbase, x, 10000*.25, r1min[Z] );
	make_pillar( "Pil", ix, 0, pbase, lwh, &head );
	VSET( pbase, x, 10000*.75, r1min[Z] );
	make_pillar( "Pil", ix, 1, pbase, lwh, &head );
    }

#ifdef never
    /* Create some light */
    white[0] = white[1] = white[2] = 255;
    base = size*(quant/2+1);
    VSET( aim, 0, 0, 0 );
    VSET( pos, base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l1", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l2", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l3", pos, aim, 1, 100.0, white, &head );
    VSET( pos, base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l4", pos, aim, 1, 100.0, white, &head );
#endif

    /* Build the overall combination */
    mk_lfcomb( outfp, "room", &head, 0 );

    return 0;
}
Example #6
0
/**
 *	P O P _ R A N D --- random number (0, 1)
 */
fastf_t
pop_rand (void)
{
    return bn_rand0to1(randomer);
}
Example #7
0
HIDDEN int
wood_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *UNUSED(mfp), struct rt_i *UNUSED(rtip))
/* New since 4.4 release */
{
    register int i;
    register struct wood_specific *wd;

    register struct resource *resp = &rt_uniresource;

    /*
     * Get the impure storage for the control block
     */

    BU_CK_VLS(matparm);
    BU_GET(wd, struct wood_specific);
    *dpp = wd;

    /*
     * Load the default values
     */

    if (rp->reg_mater.ma_color_valid) {
	VSCALE(wd->lt_rgb, rp->reg_mater.ma_color, 255);
    } else {
	wd->lt_rgb[0] = 255;	/* Light yellow */
	wd->lt_rgb[1] = 255;
	wd->lt_rgb[2] = 224;
    }

    wd->dk_rgb[0] = 191;		/* Brownish-red */
    wd->dk_rgb[1] =  97;
    wd->dk_rgb[2] =   0;

    wd->ident     = 0;
    wd->forw      = WOOD_NULL;
    wd->rp	      = rp;
    wd->flags     = 0;
    wd->overlay   = 0;		/* Draw only one ring */
    wd->ns	      = 10;
    wd->jitter    = 0.0;
    wd->scale     = 1.0;
    wd->spacing   = 5;		/* 5mm space between rings */
    wd->dd        = 0.0;		/* no dither of vertex */
    wd->dz        = 0.0;		/* nor of Z-axis */
    wd->qd        = 0;
    wd->qp        = 0;
    wd->phase     = 5;
    wd->depth     = 0;

    wd->dither[0] = bn_rand0to1(resp->re_randptr);
    wd->dither[1] = bn_rand0to1(resp->re_randptr);
    wd->dither[2] = bn_rand0to1(resp->re_randptr);

    VSETALL(wd->rot, 0);
    VSETALL(wd->vertex, 0);
    VSETALL(wd->D, 0);
    VSETALL(wd->V, 0);

    /*
     * Parse the MATPARM field
     */

    if (bu_struct_parse(matparm, wood_parse, (char *)wd) < 0) {
	BU_PUT(wd, struct wood_specific);
	return -1;
    }

    /*
     * Do some sundry range and misc. checking
     */

    for (i = 0; i < 3; i++) {
	if (wd->dither[i] < 0 || wd->dither[i] > 1.0) {
	    bu_log("wood_setup(%s):  dither is out of range.\n",
		    rp->reg_name);
	    return -1;
	}
    }

    if (wd->flags == EXPLICIT_VERTEX) {
	bu_log("wood_setup(%s):  Explicit vertex specified without direction\n", rp->reg_name);
	return -1;
    }

    if (wd->flags == EXPLICIT_DIRECTION) {
	bu_log("wood_setup(%s):  Explicit direction specified without vertex\n", rp->reg_name);
	return -1;
    }

    /*
     * Get the bounding RPP
     */

    if (rt_bound_tree(rp->reg_treetop, wd->b_min, wd->b_max) < 0) return -1;

    /*
     * Add it to the wood chain
     */

    wd->forw   = Wood_Chain;
    Wood_Chain = wd;

    /*
     * See if the user has flagged this region as a member of a larger
     * combination.  If so, go ahead and process it
     */

    if (wd->ident == 0)
	wood_setup_2(wd);

    else {
	register struct wood_specific *wc;
	vect_t c_min, c_max;

	/*
	 * First, process the accumulated chain of wood regions and
	 * process all regions which have the specified ident field.
	 */

	VSETALL(c_min, 0);
	VSETALL(c_max, 0);

	for (wc = Wood_Chain; wc != WOOD_NULL; wc = wc->forw) {
	    if (wc->ident == wd->ident) {
		VMIN(c_min, wc->b_min);
		VMAX(c_max, wc->b_max);
	    }
	}

	/*
	 * Now, loop through the chain again this time updating the
	 * regions' min/max fields with the new values
	 */

	for (wc = Wood_Chain; wc != WOOD_NULL; wc = wc->forw) {
	    if (wc->ident == wd->ident) {
		VMOVE(wc->b_min, c_min);
		VMOVE(wc->b_max, c_max);
		wood_setup_2(wc);
	    }
	}

	/*
	 * End of multi-region processing loop
	 */

    }

    /*
     * Normalize the RGB colors
     */

    for (i = 0; i < 3; i++) {
	wd->lt_rgb[i] /= 255.0;
	wd->dk_rgb[i] /= 255.0;
    }

    /*
     * Return to the caller
     */

    return 1;
}