Beispiel #1
0
int main(int argc, char **argv)
{
  Poly *l, *p, *c = poly_alloc(3);
  Item *i;

  init_sdl();
  s = scene_read();
  init_render();

  for (o = s->objs; o != NULL; o = o->next) {
    for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) {
      p = poly_transform(prim_polys(o->u.prim, l), mclip);
      if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p)))))
	hither_clip(VIEW_ZMIN(s->view), p, z_store, plist_free);
    }
  }
  z = z_sort(z);

  for (i = z->head; i != NULL; i = i->next) { 
    gouraud_shade(c, P(i), N(i), s->view->center, rc, M(i));
    p = poly_homoxform(S(i),mdpy);
    scan_poly(p, gouraud_paint, gouraud_set(g,c,s->img));
  }
  img_write(s->img, "stdout", 0);
  exit(0);
}
Beispiel #2
0
int main(int argc, char **argv)
{
  Poly *l, *p, *q = poly_alloc(3);
  Hpoly *t = hpoly_alloc(3);
  Item *i;

  init_sdl();
  s = scene_read();
  init_render();

  for (o = s->objs; o != NULL; o = o->next) {
    for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) {
      p = poly_transform(prim_polys(o->u.prim, l), mclip);
      if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p)))))
	hither_clip(0, p, z_store, plist_free);
    }
  }
  z = z_sort(z);

  for (i = z->head; i != NULL; i = i->next) {
    t = hpoly_polyxform(t, S(i), mdpy);
    q = poly_wz_hpoly(q, W(i), t);
    texture_wscale(W(i), T(i));
    scan_spoly3(q, 2, texture_shadepaint,
             texture_set(td,W(i),T(i),P(i),N(i),DU(i),DV(i),rc,M(i)));
  }
  img_write(s->img, "stdout", 0);
  exit(0);
}
Beispiel #3
0
void load_objects_gl(Object *objs)
{
  Object *o; iMesh *m;

  for (o = objs; o != NULL; o = o->next) {
    setup_texture(o);
    switch (o->type) {
    case V_TRIMESH:
      if (mesh_(o)->nv == NULL)
	imesh_compute_normals(mesh_(o)); 
      vbo_store_mesh_gl(o, mesh_(o)); 
      break;
    case V_PRIM:
      m = prim_mesh(prim_(o), prim_uv_decomp(prim_(o), 1.));
      vbo_store_mesh_gl(o, m); 
      break;
    case V_GROUP:
      load_objects_gl(children_(o));
      break;
    default: error("(load_obj_gl) wrong type");
    }
  }
}
Beispiel #4
0
Datei: main.c Projekt: cheque/s3d
int main(int argc, char **argv) {	
	FILE *fp, *foff, *ftrans;
	
	Val v;
	lang_defun("sphere", sphere_parse);
	lang_defun("conep", conep_parse);
	lang_defun("cylin", cylin_parse);
	
	if (lang_parse() == 0)
		v = lang_eval();
	
	fprintf(stderr, "\n");
	//fprintf(stderr, "type = %d\n", v.type);
	//fprintf(stderr, "V_PRIM = %d\n", V_PRIM);
	int primID = prim_type(v.u.v);
	fprintf(stderr, "prim_type = %d\n", primID);
	
	double Vol_calc;
	double radius;
	double height;
		
	if (primID == SPHERE){
		fprintf(stderr, "It's a SPHERE! \n");
		Sphere *s = ((Prim*)v.u.v)->d;
		radius = s->r;
		Vol_calc = 4 * PI * pow(radius,3) / 3;
	};

	if (primID == CONEP){
		fprintf(stderr, "It's a CONE! \n");
		Conep *c = ((Prim*)v.u.v)->d;
		radius = c->r;
		height = c->h;
		Vol_calc = PI * height * SQR(radius) / 3;
	};

	if (primID == CYLIN){
		fprintf(stderr, "It's a CYLINDER! \n");
		Cylin *c = ((Prim*)v.u.v)->d;
		radius = c->r;
		height = c->h;
		Vol_calc = PI * height * SQR(radius);
	};
	
	double randnum = rand() % 99;
	char meshSDLfile[sizeof "MESH0000.sdl"];
	char meshOFFfile[sizeof "MESH0000.sdl"];
	char meshtransfile[sizeof "transMESH0000.sdl"];
	printf("Writing mesh files...\n");
	printf("MESH%2d%2.0f.sdl\n",primID,randnum);
	printf("MESH%2d%2.0f.off\n",primID,randnum);
	                         
	sprintf(meshSDLfile,"MESH%2d%2.0f.sdl",primID,randnum);	
	sprintf(meshOFFfile,"MESH%2d%2.0f.off",primID,randnum);
	sprintf(meshtransfile,"transMESH%2d%2.0f.off",primID,randnum);
	fp = 	fopen(meshSDLfile,"w");
	foff = fopen(meshOFFfile,"w");
	ftrans = fopen(meshtransfile,"w");
	
	Prim *p = (Prim*)v.u.v;
	double step = 0.1;
	double Vol1 = rayvolume(p,step);
	
	double level = 3;
	iMesh *mesh = prim_uv_decomp(p,3);
	imesh_write(mesh,fp);
	imesh_writeOFF(mesh,foff);
	
	printf("Volume (rayvolume.c): %g \n",Vol1);
	printf("Volume (formula): %g \n",Vol_calc);
	
	printf("\nParsing SDL mesh and translating to OFF mesh...\n --> transMESH%2d%2.0f.sdl\n",primID,randnum);
	
	rewind(fp);
	imesh_translate(fp,ftrans);

	fclose(fp);
	fclose(foff);
	fclose(ftrans);
	
	return 0;
}