Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

/* polygon.cpp brief review 09/10/03; 19.39: e_brush_list_copy 09/10/03; 19.27: e_worldspawn es e_brush_list ahora version inicial */ #include #include #include #include #include "..\..\core\includes\polygon.h" #include "..\..\core\includes\vector.h" #include "..\..\core\includes\brush.h" // #define E_DEBUG void e_entity_initialize(struct e_entity *entity) { if(entity!=NULL) { entity->nplanes=0; entity->planes_list=NULL; } } struct e_entity_plane *e_entity_addplane (struct e_entity_plane *parent, struct e_entity_plane plane) { struct e_entity_plane *child; child=new struct e_entity_plane; memcpy(child,&plane,sizeof(struct e_entity_plane)); child->next=NULL; if (parent!=NULL) parent->next=child; return child; } struct e_entity *addentity(struct e_entity *parent, struct e_entity entity) { struct e_entity *child; child=new struct e_entity; memcpy(child,&entity,sizeof(struct e_entity)); child->next=NULL; if (parent!=NULL) parent->next=child; return child; } void e_brush_list_loadfromfile(char *filename, struct e_brush_list *worldspawn) { FILE *file; file=fopen(filename,"r"); if(file==NULL) printf("[error] unable to open file %s\n",filename), exit(1); printf(" <> file %s opened\n",filename); printf(" <> reading and generating geometry \n",filename); char inbuff[256]; char texture[256]; memset(inbuff,'\0',256*sizeof(char)); int f_worldspawn=0; fpos_t curpos; struct e_entity entity; struct e_entity_plane *aux_plane=NULL; struct e_entity *aux_entity=NULL; struct e_brush *aux_brush=NULL; e_brush_list_initialize(worldspawn); e_entity_initialize(&entity); struct e_brush brush; vector3 v[3]; int openbrackets=0; int entity_id=0; int plane_id=0; int nplanes=0; do { if((strstr(inbuff,"classname"))!=NULL && (strstr(inbuff,"worldspawn"))!=NULL ) f_worldspawn=1; fgetpos(file,&curpos); memset(inbuff,'\0',256*sizeof(char)); fgets(inbuff,256,file); if(f_worldspawn==1) { if((strstr(inbuff,"{"))!=NULL) { openbrackets++; nplanes=0; } if( (strstr(inbuff,"{"))==NULL && (strstr(inbuff,"}"))==NULL) { fsetpos(file,&curpos); memset(texture,'\0',256); int a[3]; int b[3]; int c[3]; int u[8]; fscanf(file,"( %i %i %i ) ( %i %i %i ) ( %i %i %i ) %s %f %f %f %f %f %f %f %f\n", &a[0], &b[0], &c[0], &a[1], &b[1], &c[1], &a[2], &b[2], &c[2], texture, &u[0], &u[1], &u[2], &u[3], &u[4], &u[5], &u[6], &u[7]); v[0]=vector3((double)a[0]/128,((double)c[0]/128),-(double)b[0]/128); v[1]=vector3((double)a[1]/128,((double)c[1]/128),-(double)b[1]/128); v[2]=vector3((double)a[2]/128,((double)c[2]/128),-(double)b[2]/128); fgetpos(file,&curpos); struct e_entity_plane plane; plane.plane=points2plane (v[2],v[1],v[0]); plane.id=plane_id; plane_id++; nplanes++; if (entity.planes_list==NULL) { entity.planes_list=e_entity_addplane(NULL,plane); aux_plane=entity.planes_list; } else { aux_plane=e_entity_addplane(aux_plane,plane); } } if((strstr(inbuff,"}"))!=NULL) { openbrackets--; if(openbrackets==0) { entity.id=entity_id; entity.nplanes=nplanes; // intersecto todos los planos aqui y genero el brush e_entity_generate_geometry(&entity, &brush); if (worldspawn->brush_list==NULL) { worldspawn->brush_list=addbrush(NULL,brush); aux_brush=worldspawn->brush_list; } else { aux_brush=addbrush(aux_brush,brush); } e_entity_initialize(&entity); nplanes=0; plane_id=0; } } } } while(!feof(file)); fclose(file); } void e_brush_list_initialize(struct e_brush_list *worldspawn) { if(worldspawn!=NULL) worldspawn->brush_list=NULL; } void e_brush_initialize(struct e_brush *brush) { if(brush!=NULL) { brush->npolygons=0; brush->polygon_list=NULL; } } struct e_brush *addbrush(struct e_brush *parent, struct e_brush brush) { struct e_brush *child; child=new struct e_brush; memcpy(child,&brush,sizeof(struct e_brush)); child->next=NULL; if (parent!=NULL) parent->next=child; return child; } struct e_brush *e_brush_copy(struct e_brush *original) { struct e_brush *brush; struct e_polygon *aux_polygon; struct e_polygon *loop_polygon; struct e_polygon polygon; brush=new struct e_brush; e_brush_initialize(brush); loop_polygon=original->polygon_list; while(loop_polygon!=NULL) { polygon=*(e_polygon_copy(loop_polygon)); /* add copied polygon */ if (brush->polygon_list==NULL) { brush->polygon_list=addpolygon(NULL,polygon); aux_polygon=brush->polygon_list; } else { aux_polygon=addpolygon(aux_polygon,polygon); } /**/ loop_polygon=loop_polygon->next; } brush->npolygons=original->npolygons; brush->next=NULL; return brush; } void e_entity_generate_geometry(struct e_entity *aux_entity, struct e_brush *brush) { struct e_entity_plane *aux_plane_i; struct e_entity_plane *aux_plane_j; struct e_entity_plane *aux_plane_k; struct e_entity_plane *aux_plane_l; struct e_polygon polygon; struct e_polygon *aux_polygon=NULL; struct e_plane newplane; struct vector3 center; int illegal; e_brush_initialize(brush); aux_plane_i=aux_entity->planes_list; while(aux_plane_i!=NULL) { e_polygon_initialize(&polygon); aux_plane_j=aux_entity->planes_list; while(aux_plane_j!=NULL) { aux_plane_k=aux_entity->planes_list; while(aux_plane_k!=NULL) { if( (aux_plane_i->id!=aux_plane_j->id) && (aux_plane_i->id!=aux_plane_k->id)) { struct vector3 newVertex; if((e_plane_3_intersection( aux_plane_i->plane, aux_plane_j->plane, aux_plane_k->plane, &newVertex))==1) { aux_plane_l=aux_entity->planes_list; illegal=0; while(aux_plane_l!=NULL) { if (classify_point(newVertex,aux_plane_l->plane)==E_FRONT) illegal=1; aux_plane_l=aux_plane_l->next; } if(illegal==0) { struct e_vertex nvertex; nvertex.position=newVertex; e_polygon_addvertex(&polygon,nvertex); } } } aux_plane_k=aux_plane_k->next; } aux_plane_j=aux_plane_j->next; } center=vector3(0,0,0); memcpy(&polygon.plane,aux_plane_i,sizeof(e_plane)); for(int nv=0;nvSmallestAngle) { SmallestAngle = Angle; Smallest = m; } } } // swap_vertices polygon.vertices[n+1] & polygon.vertices[Smallest] struct vector3 swap; memcpy(&swap,&polygon.vertices[n+1],sizeof(struct vector3)); memcpy(&polygon.vertices[n+1],&polygon.vertices[Smallest],sizeof(struct vector3)); memcpy(&polygon.vertices[Smallest],&swap,sizeof(struct vector3)); } // check if vertex order needs to be reversed e_polygon_getplane(&newplane, polygon); if (polygon.plane.normal*newplane.normal<0) { int j=polygon.nvertices; for (int i=0; ipolygon_list==NULL) { brush->polygon_list=addpolygon(NULL,polygon); aux_polygon=brush->polygon_list; } else { aux_polygon=addpolygon(aux_polygon,polygon); } e_polygon_initialize(&polygon); aux_plane_i=aux_plane_i->next; } } struct e_brush_list *e_brush_list_copy(struct e_brush_list *original) { struct e_brush_list *brush_list; struct e_brush *aux_brush; struct e_brush *loop_brush; struct e_brush brush; brush_list=new struct e_brush_list; e_brush_list_initialize(brush_list); loop_brush=original->brush_list; while(loop_brush!=NULL) { brush=*(e_brush_copy(loop_brush)); /* add copied brush */ if (brush_list->brush_list==NULL) { brush_list->brush_list=addbrush(NULL,brush); aux_brush=brush_list->brush_list; } else { aux_brush=addbrush(aux_brush,brush); } /**/ loop_brush=loop_brush->next; } return brush_list; } void e_brush_list_perform_CSG(struct e_brush_list *brushes) { printf(" <> performing CSG union\n"); struct e_brush_list *clipped_brushes; clipped_brushes=e_brush_list_copy(brushes); struct e_brush *aux_brush_j; struct e_brush *aux_brush_k; bool cliponplane; int j,k; aux_brush_j=clipped_brushes->brush_list; j=0; while(aux_brush_j!=NULL) { cliponplane=false; aux_brush_k=brushes->brush_list; k=0; while(aux_brush_k!=NULL) { if(j!=k) { printf("<%i,%i>\n",j,k); e_brush_clip(aux_brush_j, aux_brush_k, cliponplane); } else { cliponplane=true; } aux_brush_k=aux_brush_k->next; k++; } aux_brush_j=aux_brush_j->next; j++; } brushes=e_brush_list_copy(clipped_brushes); free(clipped_brushes); } void e_brush_clip(struct e_brush *brush, struct e_brush *against, bool cliponplane) { struct e_polygon *aux_poly; aux_poly=brush->polygon_list; while(aux_poly!=NULL) { printf("{}"); aux_poly=e_polygon_clip_polygon(aux_poly, against->polygon_list, cliponplane); aux_poly=aux_poly->next; } } struct e_polygon *e_polygon_clip_polygon(struct e_polygon *poly, struct e_polygon *against, bool cliponplane) { int r=e_polygon_classify(poly,against); /* if(r==E_FRONT) { printf("E_FRONT\n"); } if(r==E_BACK) { printf("E_BACK\n"); if(against->next!=NULL) { return poly->next; return e_polygon_clip_polygon(poly,against->next,cliponplane); } else { } } if(r==E_BOTHSIDES) { printf("E_BOTHSIDES\n"); poly->color=0; // return poly->next; } */ poly->color=0; return poly; } o que mecesitare en su implementacion, y un programita que demuestre su utilidad. Usare el algoritmo Sutherland-Hodgeman.

Silencer of theDarkDesigns 
<silencer_ar@hotmail.com>
23/8/2003  _inicio de Enigma 3D Engine
A partir de hoy comienza el desarrollo de E3DE.
El motor tendra caracteristicas similares al del Quake 3: Arena, de id Software, mas algunos otros, como bump mapping y sombras proyectadas en tiempo real. El formato debera traer informacion precalculada que facilite la implementacion de las mismas.
Por el momento no me preocupare por eso, me pondre a investigar y pensar como funcionara el compilador de BSP primeramente, luego intentare calcular informacion de PVS.

Silencer of theDarkDesigns 
<silencer_ar@hotmail.com>


23/8/2003  _creación de la página
La idea de esta página es promocionar la creacion de Enigma 3D Engine, para que todos puedan opinar, criticar, o si pueden, ayudar en el desarrollo del mismo. Tambien podran encontrar aqui tutoriales, links relacionados, recomendaciones, etc.
Seguro el desarrollo de E3DE será lento, no tengo mucho tiempo disponible dado que he comenzado la facultad este año (Ciencias de la Computacion, Facultad de ciencias Exactas y Naturales, UBA). Aqui ire posteando los avances del mismo, asi como tambien pensamientos personales, asi sea sobre E3DE, o de cualquier otro tema.
No dude en contactarme por cualquier motivo, preguntas, comentarios, sugerencias, o simplemente hablar. Por mail, MSN, o en #c++ de irc.ciudad.com.ar

Silencer of theDarkDesigns 
<silencer_ar@hotmail.com>

 
Open Graphics Library
Capital Federal Linux Users Group
Ramiro Alcocer's Programacion Grafica
Facultad de Ciencias Exactas y Naturales, UBA

  rodrigo pelorosso - silencer's programming page - 2003 - Buenos Aires, ARGENTINA Despues de todo, uno es argentino :)