Exemplo n.º 1
0
void test_cast_ray(void){
   struct sphere s[2];
   struct color c1 = create_color(1,0,.3);
   s[0] = create_sphere(create_point(1.4,2.6,0), 2, c1);
   s[1] = create_sphere(create_point(4.5, 5, 0), 1,c1);

   struct ray r = create_ray(create_point(0,0,0), 
                             create_vector(1.4,2.6,0));

   struct ray r2 = create_ray(create_point(-123.2,-4,-.3),
                             create_vector(1.3,-2.9,-.3));

   struct ray r3 = create_ray(create_point(-4.5,-4.3,0),
                             create_vector(-23,-100,-100));

   checkit_int(cast_ray(r,s,2).r, 1);
   checkit_int(cast_ray(r,s,2).g, 0);
   checkit_int(cast_ray(r,s,2).b, .3);

   checkit_int(cast_ray(r2,s,2).r, 1);
   checkit_int(cast_ray(r2,s,2).g, 1);
   checkit_int(cast_ray(r2,s,2).b, 1);

   checkit_int(cast_ray(r3,s,2).r, 1);
   checkit_int(cast_ray(r3,s,2).g, 1);
   checkit_int(cast_ray(r3,s,2).b, 1);

}
Exemplo n.º 2
0
void test_sphere_intersection_point(void){

   struct ray r = create_ray(create_point(0,0,0),create_vector(1.3,0,0));
   struct sphere s = create_sphere(create_point(2.5,0,0),1.2);
   struct maybe_point test = sphere_intersection_point(r,s);
   checkit_double(test.p.x,1.3);
   checkit_double(test.p.y,0);
   checkit_double(test.p.z,0);
   checkit_int(test.isPoint,1);
   
   struct ray r2 = create_ray(create_point(-2.4,-2.9,-4.4),create_vector(-1,0,0));
   struct sphere s2 = create_sphere(create_point(2.3,5.7,8.2),1);
   struct maybe_point test2 = sphere_intersection_point(r2,s2);
   checkit_int(test2.isPoint,0);
   
   
   struct ray r3 = create_ray(create_point(-4.3,0,4.7),create_vector(3.5,0,0));
   struct sphere s3 = create_sphere(create_point(2.1,0,0),4.7);
   struct maybe_point test3 = sphere_intersection_point(r3,s3);
   checkit_int(test3.isPoint,1); 
   

   struct ray r4 = create_ray(create_point(1.2,-5.4,4.2),create_vector(1.1,1.2,1.3));
   struct sphere s4 = create_sphere(create_point(4.7,6.4,2.2),13.5);
   struct maybe_point test4 = sphere_intersection_point(r4,s4);
   checkit_double(test4.p.x,9.871860);
   checkit_double(test4.p.y,4.060210);
   checkit_double(test4.p.z,14.448561);
   checkit_int(test4.isPoint,1);
}
Exemplo n.º 3
0
void test_cast_all_rays(void){
   struct color	c = create_color(.3,.5,.9);

   struct sphere s[2];
   s[0] = create_sphere(create_point(1,1,0), 2,c);
   s[1] = create_sphere(create_point(.5, 1.5, -3.0), .5,c);
   struct point eye = create_point(0,0,-14);
   
   cast_all_rays(-10,10,-7.5,7.5,1024,768,eye,s,2);

}
Exemplo n.º 4
0
void test_create_sphere(void){
   struct sphere s = create_sphere(create_point(1.9,3.9,7.9), 45.55);
   checkit_double(s.center.x,1.9);
   checkit_double(s.center.y,3.9);
   checkit_double(s.center.z,7.9);
   checkit_double(s.radius,45.55);

struct sphere s2 = create_sphere(create_point(5.8,9.8,1.8), 23.23);
   checkit_double(s2.center.x,5.8);
   checkit_double(s2.center.y,9.8);
   checkit_double(s2.center.z,1.8);
   checkit_double(s2.radius,23.23);

}
Exemplo n.º 5
0
void test_find_intersection_points(void){
   struct sphere s1 = create_sphere(create_point(4.2,0,0),1.3);
   struct sphere s2 = create_sphere(create_point(2.6,0,0),5.4);
   struct ray r = create_ray(create_point(-23.2,0,0),create_vector(.2,0,0));
   struct sphere spheres[2] = {s1,s2};
   struct sphere hit[2];
   struct point pts[2];
   checkit_int(find_intersection_points(spheres,2,r,hit,pts),2);
   checkit_double(pts[0].x, 2.9);
   checkit_double(pts[0].y, 0);
   checkit_double(pts[0].z, 0);
   checkit_double(pts[1].x, -2.8);
   checkit_double(pts[1].y, 0);
   checkit_double(pts[1].z, 0);
   checkit_double(hit[0].center.x, 4.2);
   checkit_double(hit[0].center.y, 0);
   checkit_double(hit[0].center.z, 0);
   checkit_double(hit[0].radius, 1.3);
   checkit_double(hit[1].center.x, 2.6);
   checkit_double(hit[1].center.y, 0);
   checkit_double(hit[1].center.z, 0);
   checkit_double(hit[1].radius, 5.4);

   struct sphere s3 = create_sphere(create_point(4.5,1.4,3.2),1.8);
   struct sphere s4 = create_sphere(create_point(2,4.3,5.4),3.2);
   struct sphere s5 = create_sphere(create_point(2.9,3.4,2.1),2.3);
   struct ray r2 = create_ray(create_point(1,1.3,.5),create_vector(1.3,1.4,1.8));
   struct sphere spheres2[3] = {s3,s4,s5};
   struct sphere hit2[3];
   struct point pts2[3];
   checkit_int(find_intersection_points(spheres2,3,r2,hit2,pts2),2);

   checkit_double(pts2[0].x, 2.489528);
   checkit_double(pts2[0].y, 2.904107);
   checkit_double(pts2[0].z, 2.562423);  
   checkit_double(pts2[1].x, 1.492227);
   checkit_double(pts2[1].y, 1.830091);
   checkit_double(pts2[1].z, 1.181545);

   checkit_double(hit2[0].center.x, 2);
   checkit_double(hit2[0].center.y, 4.3);
   checkit_double(hit2[0].center.z, 5.4);
   checkit_double(hit2[0].radius, 3.2);
   checkit_double(hit2[1].center.x, 2.9);
   checkit_double(hit2[1].center.y, 3.4);
   checkit_double(hit2[1].center.z, 2.1);
   checkit_double(hit2[1].radius, 2.3);

}
Exemplo n.º 6
0
void input_spheres(char **argv, struct sphere s[], int c[]){

   c[0] = 0;
   FILE *fp;
   fp= fopen(argv[1],"r");
  
   if (fp == NULL) {
       perror("usage: a.out <filename> [-eye x y z] [-view min_x max_x min_y max_y width height] [-light x y z r g b] [-ambient r g b]\n");
   }

   double x, y,z, radius,r,g, b,a,d, sp, ro;
   int index = 0;   

   while (fscanf(fp, "%lf %lf%lf %lf%lf %lf%lf %lf%lf %lf%lf ", 
                       &x, &y, &z,&radius, &r, &g,&b, &a, &d,&sp, &ro) != EOF &&
                 index<10000) {
      struct sphere sphere =  create_sphere(create_point(x,y,z),
                                            radius,
                                            create_color(r,g,b),
                                            create_finish(a,d,sp,ro));
      s[index] = sphere;
      index++;
   }
   c[0] = index;
   fclose(fp);

}
Exemplo n.º 7
0
void		*parse_sphere(const parsing_sect_t *section, t_scene *scene)
{
	t_sphere	*sphere;
	t_object	*object;
	t_vec3		position;
	t_material	*material;
	float		radius;
	
	vec3_set(&position, 0, 0, 0);
	
	if (section->option_count > 0)
		parse_vec3(section->options[0] + 1, &position);

	radius = 0.f;

	if (section->option_count > 1)
		radius = atof(section->options[1][1]);

	material = NULL;

	if (section->option_count > 2)
		material = get_material(scene, section->options[2][1]);

	if (material == NULL)
		die("Unknown material.");

	sphere = create_sphere(&position, radius, material);
	object = create_object(section->name, SPHERE, sphere);
	lst_push_back(scene->objects, object);

	return (sphere);
}
Exemplo n.º 8
0
static void			la_norme_a_pas_dit_bonjour(char **line, t_obj *object,
												int i, int fd)
{
	if ((*line)[i] && strncmp(*line + i, "brightness", 10) == 0)
		object->brightness = parse_brightness(fd);
	else if ((*line)[i] && strncmp(*line + i, "sphere", 6) == 0)
		create_sphere(object, fd);
	else if ((*line)[i] && strncmp(*line + i, "cylinder", 8) == 0)
		create_cylinder(object, fd);
	else if ((*line)[i] && strncmp(*line + i, "cone", 4) == 0)
		create_cone(object, fd);
	else if ((*line)[i] && strncmp(*line + i, "para", 4) == 0)
		create_para(object, fd);
	else if ((*line)[i] && strncmp(*line + i, "plan", 4) == 0)
		create_plan(object, fd);
	else if ((*line)[i] && strncmp(*line + i, "spec", 4) == 0)
		object->spec = parse_brightness(fd);
	else if ((*line)[i] && strncmp(*line + i, "transpa", 7) == 0)
		object->transpa = parse_brightness(fd);
	else if ((*line)[i] && strncmp(*line + i, "indice", 6) == 0)
		object->indice = parse_brightness(fd);
	else if ((*line)[i] && strncmp(*line + i, "texture", 7) == 0)
		object->texture = parse_texture(fd);
	else if ((*line)[i] && strncmp(*line + i, "normal", 6) == 0)
		object->normal_map = parse_normal_map(fd);
	else if ((*line)[i] && strncmp(*line + i, "rep", 3) == 0)
		object->rep = parse_object_rep(fd);
}
Exemplo n.º 9
0
void	init_scene(t_img *img)
{
	init_cam(&img->scene.cam, init_vect(-2, -2, 0));
	img->scene.light = create_light(init_vect(0, 0, -35), 0xffffff);
	img->scene.obj[0] = create_sphere(init_vect(0, 0, -10), 80, 0xffffff);
	img->scene.obj[1] = create_sphere(init_vect(-20, 24, -80), 50, 0x00ff00);
	img->scene.obj[2] = create_sphere(init_vect(10, 10, -100), 50, 0xfff700);
	img->scene.obj[3] = create_sphere(init_vect(200, 200, -150), 50, 0x0000ff);
//	img->scene.obj[4] = create_cone(init_vect(0, 0, -5), 20, 0xff00ff);
	img->scene.obj[4] = create_sphere(init_vect(600, 600, -150), 50, 0xff00ff);
	img->scene.obj[5] = create_cylinder(init_vect(2, 2, -110),
							init_vect(0, 1, 1), 50, 0x777777);
	img->scene.obj[6] = create_plane(init_vect(1, 0, 1),
							init_vect(0, 0, -200), 0xff0000);
	img->scene.obj[7] = create_plane(init_vect(0, 1, 1),
							init_vect(0, 0, -200), 0xffffcc);
}
Exemplo n.º 10
0
void test_sphere_normal_at_point(void){
   struct sphere s = create_sphere(create_point(4.2,3.5,6.5),5.715767665);
   struct point p = create_point(5.3,2.4,5.4);
   struct vector v = sphere_normal_at_point(s,p);
   checkit_double(v.x,.57735);
   checkit_double(v.y,-.57735);
   checkit_double(v.z,-.57735);

   struct sphere s2 = create_sphere(create_point(1.2,0,0),4.45);
   struct point p2 = create_point(6.65,0,0);
   struct vector v2 = sphere_normal_at_point(s2,p2);
   checkit_double(v2.x,1);
   checkit_double(v2.y,0);
   checkit_double(v2.z,0);



}
Exemplo n.º 11
0
/** 
 * wrapper func to validate the block of points being processed and to
 * call the appropriate handler.
 */
int
process_group(point_line_t **plta, int count) {
    int valid_count = 0;

    if (!plta) {
	printf("WARNING: Unexpected call to process_multi_group with a NULL point array\n");
	return 0;
    }

    bu_log("processing a group!\n");

    /* resort the list, put nulls at the end */
    valid_count = condense_points(plta, count);

    /* ignore insufficient counts */
    if (valid_count <= 2)
	switch ((*plta)[0].code) {
	    case(PLATE): /* need at least 3 (triangle) */
		/*		printf("IGNORING PLATE POINT DUPLICATE(S)\n"); */
		return 0;
	    case(ARB): /* need 8 */
		/*		printf("IGNORING ARB POINT DUPLICATE(S)\n");*/
		return 0;
	    case(CYLINDER): /* need at least 3 (2 for length + diam) */
		/* printf("IGNORING CYLINDER POINT DUPLICATE(S)\n"); */
		return 0;
	}

    /* FIXME: callbacks should really be registered in the lexer or
       parser when a point-line of that particular type is
       encountered
    */
    switch ((*plta)[0].code) {
	case(PLATE):
	    return create_plate(plta, valid_count);
	case(ARB):
	    return create_arb(plta, valid_count);
	case(CYLINDER):
	    return create_cylinder(plta, valid_count);
	case(CYL):
	    return create_cyl(plta, valid_count);
	case(POINTS):
#if PRINT_ARRAY
	    static int print_counter = 0;
	    if (print_counter == 0) {
		bu_log("--- POINTS ---\n");
		print_array(plta, count);
	    }
#endif
	    return create_points(plta, valid_count);
	case(SYMMETRY):
	    return create_points(plta, valid_count);
	case(PIPE):
	    return create_pipe(plta, valid_count);
	case(SPHERE):
	    return create_sphere(plta, valid_count);
    }

    printf("WARNING, unsupported point code encountered (%d)\n", (*plta)[0].code);
    return 0;
}
Exemplo n.º 12
0
Primitive * create_scene(cl_uint & n_primitives)
{	
	int curr_prim = 0;
	Primitive * primitive_list;

	if (CHOOSE_SCENE == 0){

		n_primitives = 17;
		primitive_list = (Primitive *) malloc(sizeof(Primitive) * n_primitives);
		memset(primitive_list, 0, sizeof(Primitive) * n_primitives);

		float light = 0.85f;
		//create_plane(create_material(r, g, b, refl, refr, refr_index, diff, spec), is_light, x, y, z, depth/radius);
		// floor plane
		primitive_list[curr_prim++] = create_plane(create_material(0.6f, 0.6f, 0.6f, 0.0f, 0.0f, 0.0f, 0.4f, 1.8f), false, 0.0f, 0.75f, 0.0f, 4.4f);
		// big sphere
		primitive_list[curr_prim++] = create_sphere(create_material(0.08f, 0.08f, 0.08f, 0.2f, 1.0f, 1.4f, 0.0f, 0.0f), false, 3.4f, -3.4f, 23.0f, 2.5f);
		// small sphere 5
		primitive_list[curr_prim++] = create_sphere(create_material(0.07f, 0.17f, 0.07f, 0.1f, 1.0f, 1.2f, 0.0f, 0.0f), false, -0.7f, -4.90f, 27.0f, 1.0f);
		// small sphere
		primitive_list[curr_prim++] = create_sphere(create_material(1.0f, 1.0f, 1.0f, 0.8f, 0.0f, 0.0f, 0.0f, 0.0f), false, -3.4f, -3.4f, 29.0f, 2.5f);
		// small sphere 2
		primitive_list[curr_prim++] = create_sphere(create_material(1.5f, 0.7f, 0.7f, 0.1f, 0.0f, 0.0f, 0.2f, 0.2f), false, 0.5f, -4.1f, 29.0f, 1.5f);
		// small sphere 3
		primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.7f, 0.2f, 0.0f, 0.0f, 0.2f, 0.2f), false, -6.0f, -4.1f, 32.0f, 1.5f);
		// small sphere 4
		primitive_list[curr_prim++] = create_sphere(create_material(0.07f, 0.17f, 0.07f, 0.3f, 1.0f, 1.2f, 0.2f, 0.8f), false, -6.7f, -4.90f, 29.0f, 1.0f);
		// small sphere 6 up front
		primitive_list[curr_prim++] = create_sphere(create_material(0.08f, 0.08f, 0.08f, 0.7f, 1.0f, 1.3f, 0.8f, 0.0f), false, 6.4f, -4.9f, 18.0f, 1.0f);
		// left wall
		primitive_list[curr_prim++] = create_plane(create_material(1.0f, 0.6f, 0.6f, 0.0f, 0.0f, 0.0f, 0.8f, 1.5f), false, 0.7f, 0.0f, 0.0f, 5.4f);
		// right wall
		primitive_list[curr_prim++] = create_plane(create_material(0.7f, 0.6f, 1.0f, 0.0f, 0.0f, 0.0f, 0.8f, 0.8f), false, -0.7f, 0.0f, 0.0f, 5.4f);
		// top wall
		primitive_list[curr_prim++] = create_plane(create_material(1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.2f, 0.8f), false, 0.0f, -0.8f, 0.0f, 5.4f);
		// back wall
		primitive_list[curr_prim++] = create_plane(create_material(1.5f, 1.5f, 1.5f, 0.0f, 0.0f, 0.0f, 1.2f, 0.8f), false, 0.0f, 0.0f, -0.14f, 5.4f);
		// front wall
		primitive_list[curr_prim++] = create_plane(create_material(0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f), false, 0.0f, 0.0f, 0.72f, 5.4f);
		// light source center
		primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, 0.0f, 6.5f, 22.0f, 0.35f);
		// light source right
		primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, -3.0f, 6.5f, 22.0f, 0.35f);
		// light source left
		primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, 3.0f, 6.5f, 22.0f, 0.35f);	
		/*	
		// light source ground back
		primitive_list[curr_prim++] = create_sphere(create_material(0.85f, 0.25f, 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), false, -5.8f, -5.55f, 31.0f, 0.35f);
		*/

	}else if(CHOOSE_SCENE == 1){		
		n_primitives = 64;
		primitive_list = (Primitive *) malloc(sizeof(Primitive) * n_primitives);
		memset(primitive_list, 0, sizeof(Primitive) * n_primitives);
		//create_plane(create_material(r, g, b, refl, refr, refr_index, diff, spec), is_light, x, y, z, depth/radius);
		// floor plane
		primitive_list[curr_prim++] = create_plane(create_material(0.4f, 0.3f, 0.3f, 0.0f, 0.0f, 1.0f, 1.0f, 0.8f), false, 0.0f, 1.0f, 0.0f, 4.4f);
		// big sphere
		primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.0f, 0.0f, 1.0f, 1.3f, 0.2f, 0.8f), false, 2.0f, 0.8f, 3.0f, 2.5f);
		// small sphere
		primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.0f, 0.5f, 0.0f, 1.0f, 0.1f, 0.8f), false, -5.5f, -0.5f, 7.0f, 2.0f);
		// light source 1
		primitive_list[curr_prim++] = create_sphere(create_material(0.4f, 0.4f, 0.4f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f), true, 0.0f, 5.0f, 5.0f, 0.1f);
		// light source 2
		primitive_list[curr_prim++] = create_sphere(create_material(0.6f, 0.6f, 0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f), true, -3.0f, 5.0f, 1.0f, 0.1f);
		// sphere 3
		primitive_list[curr_prim++] = create_sphere(create_material(1.0f, 0.4f, 0.4f, 0.5f, 0.0f, 1.0f, 0.2f, 0.8f), false, -1.5f, -3.8f, 1.0f, 1.5f);
		// back plane
		primitive_list[curr_prim++] = create_plane(create_material(0.5f, 0.3f, 0.5f, 0.0f, 0.0f, 1.0f, 0.6f, 0.0f), false, 0.4f, 0.0f, -1.0f, 12.0f);
		// ceiling plane
		primitive_list[curr_prim++] = create_plane(create_material(0.4f, 0.7f, 0.7f, 0.0f, 0.0f, 1.0f, 0.5f, 0.0f), false, 0.0f, -1.0f, 0.0f, 7.4f);

		for (int x = 0; x < 8; x++)
			for (int y = 0; y < 7; y++)
			{
				primitive_list[curr_prim++] = create_sphere(create_material(0.3f, 1.0f, 0.4f, 0.0f, 0.0f, 1.0f, 0.6f, 0.6f), false, -4.5f + x * 1.5f, -4.3f + y * 1.5f, 10.0f, 0.3f);
			}	
	}

	return primitive_list;
}
Exemplo n.º 13
0
ENTRYPOINT void 
init_glcells( ModeInfo *mi )
{
  int i, divisions;
  State *st=0;
  
  if (!sstate) {
    sstate = (State *)
        calloc( MI_NUM_SCREENS(mi), sizeof(State) );
    if (!sstate) {
      fprintf( stderr, "%s: out of memory\n", progname );
      exit(1);
    }
  }
  st = &sstate[MI_SCREEN(mi)];
  
  st->glx_context = init_GL(mi);
  st->cell = 0;
  st->num_cells = 0;
  st->wire = MI_IS_WIREFRAME(mi);
  
# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
  st->wire = 0;
# endif

  /* get settings */
  st->max_cells = s_maxcells;;
  if (st->max_cells < 50) st->max_cells = 50;
  if (st->max_cells > 10000) st->max_cells = 10000;
  
  st->pause = s_pause;
  if (st->pause < 0) st->pause = 0;
  if (st->pause > 400) st->pause = 400;
  st->pause_counter = st->pause;
  
  st->radius = s_radius;
  if (st->radius < 5) st->radius = 5;
  if (st->radius > 200) st->radius = 200;
  
  divisions = s_quality;
  if (divisions < 0) divisions = 0;
  if (divisions > 5) divisions = 5;
  
  st->num_seeds = s_seeds;
  if (st->num_seeds < 1) st->num_seeds = 1;
  if (st->num_seeds > 16) st->num_seeds = 16;
  
  st->minfood = s_minfood;
  if (st->minfood < 0) st->minfood = 0;
  if (st->minfood > 1000) st->minfood = 1000;
  
  st->maxfood = s_maxfood;
  if (st->maxfood < 0) st->maxfood = 0;
  if (st->maxfood > 1000) st->maxfood = 1000;
  
  if (st->maxfood < st->minfood) st->maxfood = st->minfood+1;
  
  st->keep_old_cells = s_keepold;
  
  st->divide_age = s_divideage;
  if (st->divide_age < 1) st->divide_age = 1;
  if (st->divide_age > 1000) st->divide_age = 1000;
     
  st->move_dist = s_min_dist;
  if (st->move_dist < 1.0) st->move_dist = 1.0;
  if (st->move_dist > 3.0) st->move_dist = 3.0;
  st->move_dist *= st->radius;
  
  for (i=0; i<NUM_CELL_SHAPES; ++i) st->cell_list[i] = -1;
  st->nucleus_list = -1;
  st->food = 0;
  
  st->sphere = create_sphere( st, divisions );
  st->disturbance = 
      (double *) malloc( st->sphere->num_vertex*sizeof(double) );
  for (i=0; i<st->sphere->num_vertex; ++i) {
    st->disturbance[i] = 
        0.05-((double)random()/(double)RAND_MAX*0.1);
  }
  
  create_nucleus_texture( st );

  reshape_glcells (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
}
Exemplo n.º 14
0
/**
 to initialize the scene with the default one.
 */
void make_test_scene (int xsize, int ysize) {
    //camera
    set_camera (0.f, 4.f, -4.f,
                0.f, 0.f, 0.f,
                0.f, 1.f, 0.f,
                90.f, xsize, ysize);
    //objects
    Material * plastic = create_plastic_mat (0.6f, 0.5f, 0.5f,
                                             0.6f, 0.5f, 0.5f,
                                             100.f);
	
    // ground plane
    Geometry * plane = create_plane (0.f, -1.f, 0.f,
                                     0.f, 1.f, 0.f);
    add_object (plane, plastic);

    // Up row
    // base objects
    Geometry *boxLeft = create_box (-2.f, 3.f, 0.f,
                                    1.f, 0.f, 0.f,
                                    0.f, 0.25f, 1.f,
                                    1.f, 1.f, 1.f);
    Geometry *sphereLeft = create_sphere (-2.f, 3.f, 0.f,
                                          0.65f);
    Geometry *boxCenter = create_box (0.f, 3.25f, 0.f,
                                      1.f, 0.f, 0.f,
                                      0.f, 0.25f, 1.f,
                                      1.f, 1.f, 1.f);
    Geometry *sphereCenter = create_sphere (0.f, 3.25f, 0.f,
                                            0.65f);
    Geometry *boxRight = create_box (2.f, 3.f, 0.f,
                                     1.f, 0.f, 0.f,
                                     0.f, 0.25f, 1.f,
                                     1.f, 1.f, 1.f);
    Geometry *sphereRight = create_sphere (2.f, 3.f, 0.f,
                                           0.65f);
    // CSG objects
    Geometry *unionUp = create_csg_union (boxLeft, sphereLeft);
    Geometry *intersectionUp = create_csg_intersection(boxCenter, sphereCenter);
    Geometry *differenceUp = create_csg_difference(boxRight, sphereRight);
	
    add_object (unionUp, plastic);
    add_object (intersectionUp, plastic);
    add_object (differenceUp, plastic);
	
    // Middle row
    // base objects
    Geometry *coneLeft = create_cone(-2.25f, 1.f, -1.25f,
                                     -2.25f, 3.f, -1.25f,
                                     0.5f);
    Geometry *cylinderLeft = create_cylinder(-2.25f, 1.75f, -1.25f,
                                             0.5f, 0.f, 1.f,
                                             0.25f, 1.5f);
    Geometry *coneCenter = create_cone(0.f, 1.5f, -0.75f,
                                       0.f, 3.5f, -0.75f,
                                       0.5f);
    Geometry *cylinderCenter = create_cylinder(0.f, 2.25f, -0.75f,
                                               0.5f, 0.f, 1.f,
                                               0.25f, 1.5f);
    Geometry *coneRight = create_cone(2.25f, 1.f, -1.25f,
                                      2.25f, 3.f, -1.25f,
                                      0.5f);
    Geometry *cylinderRight = create_cylinder(2.25f, 1.75f, -1.25f,
                                              0.5f, 0.f, 1.f,
                                              0.25f, 1.5f);
    // CSG objects
    Geometry * unionDown = create_csg_union (coneLeft, cylinderLeft);
    Geometry * intersectionDown = create_csg_intersection(coneCenter, cylinderCenter);
    Geometry * differenceDown = create_csg_difference(coneRight, cylinderRight);
	
    add_object (unionDown, plastic);
    add_object (intersectionDown, plastic);
    add_object (differenceDown, plastic);
	
    // front object
    char complex_tree[] = "(- (* (bo 0. 2.5 -3.25 1. 0. 0. 0. 0. 1. 1.0 1.0 1.0) (sp 0. 2.5 -3.25 0.65) ) (+ (cy 0. 2.5 -3.25 1.0 0.0 0.0 0.3 1.75) (+ (cy 0. 2.5 -3.25 0.0 1.0 0.0 0.3 1.75) (cy 0. 2.5 -3.25 0.0 0.0 1.0 0.3 1.75) ) ) )";
    Geometry *tree = csg_parse(complex_tree);
    if (tree)
        add_object (tree, plastic);

    //lights
	// Front light -- white
    add_light (0.f, 5.f, -1.5f, 1.5f, 1.5f, 1.5f);
	// Back light -- blue
    add_light (4.f, 2.f, 10.f, 0.1f, 0.1f, 0.9f);
	// Left light -- red
    add_light (-4.f, 5.f, -2.f, 0.9f, 0.1f, 0.1f);
}
Exemplo n.º 15
0
bool create_sphere(NodeInstance& node, const Context& context, int subdivision, uint32_t flags)
{
    add_part(node.mesh);
    return create_sphere(node.mesh, context, subdivision, flags);
}