void map_mesh_move(map_type *map,int mesh_idx,d3pnt *mov_pnt) { int n,nvertex,npoly; d3pnt *pt; map_mesh_type *mesh; map_mesh_poly_type *poly; mesh=&map->mesh.meshes[mesh_idx]; // move meshes vertexes nvertex=mesh->nvertex; pt=mesh->vertexes; for (n=0; n!=nvertex; n++) { pt->x+=mov_pnt->x; pt->y+=mov_pnt->y; pt->z+=mov_pnt->z; pt++; } // move all poly boxes npoly=mesh->npoly; poly=mesh->polys; for (n=0; n!=npoly; n++) { map_prepare_mesh_poly(mesh,poly); poly++; } // fix mesh box map_prepare_mesh_box(mesh); }
void map_mesh_rotate(map_type *map,int mesh_idx,d3pnt *center_pnt,d3ang *rot_ang) { int n,nvertex,npoly; float fx,fy,fz; d3vct f_mpt; d3pnt *pt; matrix_type mat; map_mesh_type *mesh; map_mesh_poly_type *poly; mesh=&map->mesh.meshes[mesh_idx]; // get mesh rotation center f_mpt.x=(float)(center_pnt->x+mesh->rot_off.x); f_mpt.y=(float)(center_pnt->y+mesh->rot_off.y); f_mpt.z=(float)(center_pnt->z+mesh->rot_off.z); // matrixes matrix_rotate_xyz(&mat,rot_ang->x,rot_ang->y,rot_ang->z); // rotate vertexes nvertex=mesh->nvertex; pt=mesh->vertexes; for (n=0; n!=nvertex; n++) { fx=((float)pt->x)-f_mpt.x; fy=((float)pt->y)-f_mpt.y; fz=((float)pt->z)-f_mpt.z; matrix_vertex_multiply(&mat,&fx,&fy,&fz); pt->x=(int)(fx+f_mpt.x); pt->y=(int)(fy+f_mpt.y); pt->z=(int)(fz+f_mpt.z); pt++; } // fix boxes npoly=mesh->npoly; poly=mesh->polys; for (n=0; n!=npoly; n++) { map_prepare_mesh_poly(mesh,poly); poly++; } // fix mesh box map_prepare_mesh_box(mesh); }
void liquid_reflection_map_setup(void) { int n,k; map_mesh_type *mesh; map_mesh_poly_type *poly; mesh=map.mesh.meshes; for (n=0;n!=map.mesh.nmesh;n++) { map_prepare_mesh_box(mesh); poly=mesh->polys; for (k=0;k!=mesh->npoly;k++) { map_prepare_mesh_poly(&map,mesh,poly); poly++; } mesh++; } }
void map_prepare(map_type *map) { int n,k,wall_like_count,obscure_count; short *wall_sptr,*floor_sptr,*obscure_sptr; map_mesh_type *mesh; map_mesh_poly_type *poly; // prepare meshes mesh=map->mesh.meshes; for (n=0;n!=map->mesh.nmesh;n++) { // default some flags mesh->precalc_flag.shiftable=FALSE; mesh->precalc_flag.poly_has_camera=FALSE; mesh->precalc_flag.has_obscure_poly=FALSE; mesh->precalc_flag.lighting_small=FALSE; mesh->precalc_flag.shadow_ok=TRUE; // run through the mesh polygons wall_like_count=0; obscure_count=0; poly=mesh->polys; for (k=0;k!=mesh->npoly;k++) { // setup box and slope map_prepare_mesh_poly(map,mesh,poly); // setup texture and shifting flags poly->draw.txt_frame_offset=0; poly->draw.shift_on=((poly->shift.x!=0.0f) || (poly->shift.y!=0.0f)); poly->draw.shift_offset.x=0.0f; poly->draw.shift_offset.y=0.0f; mesh->precalc_flag.shiftable|=poly->draw.shift_on; mesh->precalc_flag.shadow_ok|=poly->draw.shadow_ok; // setup camera and obscure flags if (poly->camera[0]!=0x0) mesh->precalc_flag.poly_has_camera=TRUE; if (poly->flag.obscuring) { mesh->precalc_flag.has_obscure_poly=TRUE; obscure_count++; } // count wall like polys if (poly->box.wall_like) wall_like_count++; poly++; } // setup poly lists mesh->poly_list.wall_count=wall_like_count; mesh->poly_list.wall_idxs=(short*)malloc(sizeof(short)*mesh->poly_list.wall_count); mesh->poly_list.floor_count=mesh->npoly-wall_like_count; mesh->poly_list.floor_idxs=(short*)malloc(sizeof(short)*mesh->poly_list.floor_count); mesh->poly_list.obscure_count=obscure_count; mesh->poly_list.obscure_idxs=(short*)malloc(sizeof(short)*mesh->poly_list.obscure_count); wall_sptr=mesh->poly_list.wall_idxs; floor_sptr=mesh->poly_list.floor_idxs; obscure_sptr=mesh->poly_list.obscure_idxs; poly=mesh->polys; for (k=0;k!=mesh->npoly;k++) { if (poly->box.wall_like) { *wall_sptr++=(short)k; } else { *floor_sptr++=(short)k; } if (poly->flag.obscuring) *obscure_sptr++=(short)k; poly++; } // setup bump flags map_prepare_mesh_poly_bump(map,mesh); // setup boxes map_prepare_mesh_box(mesh); // calculate size optimizatins mesh->precalc_flag.lighting_small=!(((mesh->box.max.x-mesh->box.min.x)>max_map_mesh_size_lighting_small)||((mesh->box.max.y-mesh->box.min.y)>max_map_mesh_size_lighting_small)||((mesh->box.max.z-mesh->box.min.z)>max_map_mesh_size_lighting_small)); mesh++; } }
bool light_map_polys_start(char *err_str) { int n,k,sz,idx,nmesh, d,dist; int *mesh_idx_list; map_mesh_type *mesh,*chk_mesh; map_mesh_poly_type *poly; map_liquid_type *liq; light_map_poly_type *lm_poly; // build a list of meshes that // are close to each other to minimize // texture switches mesh_idx_list=(int*)malloc(map.mesh.nmesh*sizeof(int)); if (mesh_idx_list==NULL) { strcpy(err_str,"Out of Memory"); return(FALSE); } nmesh=0; for (n=0;n!=map.mesh.nmesh;n++) { mesh=&map.mesh.meshes[n]; // sort it idx=-1; dist=0; for (k=0;k!=nmesh;k++) { chk_mesh=&map.mesh.meshes[mesh_idx_list[k]]; d=distance_get(mesh->box.mid.x,mesh->box.mid.y,mesh->box.mid.z,chk_mesh->box.mid.x,chk_mesh->box.mid.y,chk_mesh->box.mid.z); if ((idx==-1) || (d<dist)) { idx=k; dist=d; } } if (idx==-1) idx=nmesh; // move it into list sz=sizeof(int)*(nmesh-idx); if (sz>0) memmove(&mesh_idx_list[idx+1],&mesh_idx_list[idx],sz); mesh_idx_list[idx]=n; nmesh++; } // get poly count light_map_poly_count=light_map_get_poly_count(); sz=sizeof(light_map_poly_type)*light_map_poly_count; light_map_polys=(light_map_poly_type*)malloc(sz); if (light_map_polys==NULL) { free(mesh_idx_list); strcpy(err_str,"Out of Memory"); return(FALSE); } // build polys lm_poly=light_map_polys; // mesh polys for (n=0;n!=nmesh;n++) { idx=mesh_idx_list[n]; mesh=&map.mesh.meshes[idx]; // clear all light map textures poly=mesh->polys; for (k=0;k!=mesh->npoly;k++) { poly->lmap_txt_idx=-1; poly++; } // no light map mesh? if (mesh->flag.no_light_map) continue; // prepare meshes map_prepare_mesh_box(mesh); // build poly 2D vertexes // and 2D size poly=mesh->polys; for (k=0;k!=mesh->npoly;k++) { lm_poly->mesh_idx=idx; lm_poly->poly_idx=k; lm_poly->liquid_idx=-1; // flatten the poly map_prepare_mesh_poly(&map,mesh,poly); light_map_create_mesh_poly_flatten(mesh,poly,lm_poly); poly++; lm_poly++; } } // liquid polys liq=map.liquid.liquids; for (n=0;n!=map.liquid.nliquid;n++) { // clear light map texture liq->lmap_txt_idx=-1; // setup poly lm_poly->mesh_idx=-1; lm_poly->poly_idx=-1; lm_poly->liquid_idx=n; // flatten the poly light_map_create_liquid_poly_flatten(liq,lm_poly); liq++; lm_poly++; } return(TRUE); }
void view_vbo_mesh_rebuild(int mesh_idx) { int n,k,cnt; float *pv; d3pnt *pnt; map_mesh_type *mesh; map_mesh_poly_type *poly; mesh=&map.mesh.meshes[mesh_idx]; if (mesh->npoly==0) return; // prepare the mesh map_prepare_mesh_box(mesh); // get the total vertex count cnt=0; poly=mesh->polys; for (n=0;n!=mesh->npoly;n++) { // prepare poly map_prepare_mesh_poly(&map,mesh,poly); // remember poly index for drawing poly->draw.vertex_offset=cnt; // next poly index cnt+=poly->ptsz; poly++; } // setup the VBO mesh->vbo.vertex_count=cnt; glBindBuffer(GL_ARRAY_BUFFER,mesh->vbo.vertex); glBufferData(GL_ARRAY_BUFFER,((mesh->vbo.vertex_count*(3+2+2))*sizeof(float)),NULL,GL_DYNAMIC_DRAW); pv=(float*)glMapBuffer(GL_ARRAY_BUFFER,GL_WRITE_ONLY); if (pv==NULL) return; poly=mesh->polys; for (n=0;n!=mesh->npoly;n++) { for (k=0;k!=poly->ptsz;k++) { pnt=&mesh->vertexes[poly->v[k]]; *pv++=(float)pnt->x; *pv++=(float)pnt->y; *pv++=(float)pnt->z; *pv++=poly->main_uv.uvs[k].x; *pv++=poly->main_uv.uvs[k].y; *pv++=poly->lmap_uv.uvs[k].x; *pv++=poly->lmap_uv.uvs[k].y; } poly++; } glUnmapBuffer(GL_ARRAY_BUFFER); glBindBuffer(GL_ARRAY_BUFFER,0); }