Пример #1
0
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);
}
Пример #2
0
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);
}
Пример #3
0
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++;
	}
}
Пример #4
0
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++;
	}
}
Пример #5
0
void map_mesh_reset_poly_uv(map_type *map,int mesh_idx,int poly_idx)
{
    int						n,kx,ky,kz;
    float					fx,fy,fz,ltxtx,rtxtx,ltxty,rtxty,ltxtz,rtxtz,
                            x_txtoff,y_txtoff,x_txtfact,y_txtfact,x_txtfact_2,
                            f_dist_1,f_dist_2,txt_scale_x,txt_scale_y;
    double					dx,dz,d;
    d3pnt					*pt;
    map_mesh_type			*mesh;
    map_mesh_poly_type		*poly;

    mesh=&map->mesh.meshes[mesh_idx];
    poly=&mesh->polys[poly_idx];

    // get scale

    map_get_texture_uv_get_scale(map,poly->txt_idx,&txt_scale_x,&txt_scale_y);

    // setup box and slope
    // needed for texture calculations

    map_prepare_mesh_poly(mesh,poly);

    // walls-like polygons

    if (poly->box.wall_like) {

        ltxtx=(float)(poly->line.lx+poly->line.lz)*txt_scale_x;
        rtxtx=(float)(poly->line.rx+poly->line.rz)*txt_scale_x;

        // get point texture factor

        x_txtfact=rtxtx-ltxtx;

        // get distance texture factor

        dx=(double)(poly->line.rx-poly->line.lx);
        dz=(double)(poly->line.rz-poly->line.lz);
        d=(dx*dx)+(dz*dz);
        x_txtfact_2=(float)(sqrt(d)*txt_scale_x);
        if (x_txtfact<0) x_txtfact_2=-x_txtfact_2;

        if (fabs(x_txtfact_2)>fabs(x_txtfact)) x_txtfact=x_txtfact_2;		// if distance calc is longer, use that

        x_txtoff=map_get_texture_round_coord(map_get_texture_reduce_coord(ltxtx));
        x_txtfact=map_get_texture_round_coord(x_txtfact);

        ltxty=((float)poly->box.min.y)*txt_scale_y;
        rtxty=((float)poly->box.max.y)*txt_scale_y;

        y_txtoff=map_get_texture_round_coord(map_get_texture_reduce_coord(ltxty));
        y_txtfact=map_get_texture_round_coord(rtxty-ltxty);

        // deal with offset locks

        if (map->textures[poly->txt_idx].scale.lock_offset) {
            x_txtoff=0.0f;
            y_txtoff=0.0f;
        }

        // create the polygons UVs

        dx=(double)(poly->box.max.x-poly->line.lx);
        dz=(double)(poly->box.max.z-poly->line.lz);
        f_dist_2=(float)sqrt((dx*dx)+(dz*dz));

        for (n=0; n!=poly->ptsz; n++) {
            pt=&mesh->vertexes[poly->v[n]];

            dx=(double)(pt->x-poly->line.lx);
            dz=(double)(pt->z-poly->line.lz);
            f_dist_1=(float)sqrt((dx*dx)+(dz*dz));

            ky=pt->y-poly->box.min.y;

            fx=f_dist_1/f_dist_2;
            fy=(float)ky/(float)(poly->box.max.y-poly->box.min.y);

            poly->uv[0].x[n]=x_txtoff+(x_txtfact*fx);
            poly->uv[0].y[n]=y_txtoff+(y_txtfact*fy);
        }

        return;
    }

    // floor-like polygon

    ltxtx=((float)poly->box.min.x)*txt_scale_x;
    rtxtx=((float)poly->box.max.x)*txt_scale_x;

    ltxtz=((float)poly->box.min.z)*txt_scale_y;
    rtxtz=((float)poly->box.max.z)*txt_scale_y;

    x_txtoff=map_get_texture_round_coord(map_get_texture_reduce_coord(ltxtx));
    x_txtfact=map_get_texture_round_coord(rtxtx-ltxtx);

    y_txtoff=map_get_texture_round_coord(map_get_texture_reduce_coord(ltxtz));
    y_txtfact=map_get_texture_round_coord(rtxtz-ltxtz);

    // deal with offset locks

    if (map->textures[poly->txt_idx].scale.lock_offset) {
        x_txtoff=0.0f;
        y_txtoff=0.0f;
    }

    // set the polygon UVs

    for (n=0; n!=poly->ptsz; n++) {
        pt=&mesh->vertexes[poly->v[n]];

        kx=pt->x-poly->box.min.x;
        kz=pt->z-poly->box.min.z;

        fx=(float)kx/(float)(poly->box.max.x-poly->box.min.x);
        fz=(float)kz/(float)(poly->box.max.z-poly->box.min.z);

        poly->uv[0].x[n]=x_txtoff+(x_txtfact*fx);
        poly->uv[0].y[n]=y_txtoff+(y_txtfact*fz);
    }
}
Пример #6
0
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);
}
Пример #7
0
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);
}