in fact I think I will try breaking it down a bit realy quick before I have to go to work
this is all from the decal_create_tmappoly function, it is the thing that does all the hard work
what is first is simple initalisation code, this sets all the verts and stuff that the rest of the code will use to what is in the current polly
// mprintf(("entering decal_create_tmappoly\n"));
if(poly_num >= MAX_DECAL_POLY){
mprintf(("bugging out becase there are too many polys in the decal\n"));
return;
}
int i;
int nv;
// uv_pair uvlist[TMAP_MAX_VERTS];
// vector points[TMAP_MAX_VERTS];
model_tmap_vert *verts;
nv = dw(p+36);
if ( nv < 0 ) return;
// int tmap_num = dw(p+40);
/*
if ( (!(Mc->flags & MC_CHECK_INVISIBLE_FACES)) && (Mc_pm->textures[tmap_num] < 0) ) {
// Don't check invisible polygons.
return;
}
*/
verts = (model_tmap_vert *)(p+44);
vector temppoly[820];
for (i=0;i {
decal_poly[i] = (int)verts[i].vertnum;
temppoly[i].xyz = decal_point_list[decal_poly[i]]->xyz;
}
vector pnorm;
vm_vec_perp(&pnorm, decal_point_list[decal_poly[0]], decal_point_list[decal_poly[1]], decal_point_list[decal_poly[2]]);
float back = vm_vec_dot(&decal_cube_plane[4][1], &pnorm);
if( (back_faceing == 0) && (back >= 0) )return;
next is some polly culling
I'm not sure how well this worked and I probly didn't think it through as much as I should have
//poly culling
vector pcenter;
vm_vec_avg_n(&pcenter, nv, temppoly);
float pradius = 0;
float dist = 0;
for (i=0;i {
dist = vm_vec_dist(decal_point_list[decal_poly[i]], &pcenter);
if(dist>pradius){
pradius = dist;
}
}
//if it's too far to posably get near the cube get out
if(vm_vec_dist_quick(&pcenter, &decal_hit_point) >= (pradius + decal_hit_radius)){
// mprintf(("leaveing becase poly is too far away\n"));
return;
}
//this is for faster testing, I'm not sure if it's realy makeing it faster or not
int k;
for(k = 0; k<6; k++){
int first_good = -1;
for(i = 0; ((i< nv) && (first_good == -1)); i++){
if(fvi_point_dist_plane(&decal_cube_plane[k][0], &decal_cube_plane[k][1], decal_point_list[decal_poly[i]]) > 0){
first_good = i;
}
}
if(first_good == -1){
// mprintf(("all points are behind a plane, polygon is not in the cube\n"));
return;
}
}
//poly culling
now for the fun part
first a few last second initalisation
int temp_poly[820];
int skip = 0, numv = 0, valid = 0;
now for each plane of the cube
for(k = 0; k<6; k++){
find the first point of the decal poly in front of the plane, if any
//find the first point in front of the plain
int first_good = -1;
for(i = 0; ((i< nv) && (first_good == -1)); i++){
// mprintf(("testing point %d with plane %d\n", i, k));
// mprintf(("point's position is x %0.2f y %0.2f z %0.2f\n", decal_point_list[decal_poly[i]]->xyz.x, decal_point_list[decal_poly[i]]->xyz.y, decal_point_list[decal_poly[i]]->xyz.z));
// mprintf(("plane's position is x %0.2f y %0.2f z %0.2f\n", decal_cube_plane[k][0].xyz.x, decal_cube_plane[k][0].xyz.y, decal_cube_plane[k][0].xyz.z));
// mprintf(("plane's normal is x %0.2f y %0.2f z %0.2f\n", decal_cube_plane[k][1].xyz.x, decal_cube_plane[k][1].xyz.y, decal_cube_plane[k][1].xyz.z));
if(fvi_point_dist_plane(&decal_cube_plane[k][0], &decal_cube_plane[k][1], decal_point_list[decal_poly[i]]) >= 0){
first_good = i;
// mprintf(("%d is the first good point\n", i));
}
}
if(first_good == -1){
// mprintf(("all points are behind a plane, polygon is not in the cube\n"));
return;
}else{
valid = 1;
}
now for each vert in th decal polly starting with the first one in front of the plane
numv = 0;
//go through each point and see if there is an intersection between it the next point and the current plane
//if there is then make the intersection point the next point in the poly
//ignor all points untill there is another intersection
//other wise make the next point the next point in the poly
// if(k==1)Int3();
int is_infront = 1, is_infront2 = 1;
for(i = first_good; i < (nv + first_good); i++){
we go through each vert of the polly and check to see if the line between it and the next one intersects the plane of the cube we are currently testing.
// mprintf(("looking for intersections between point %d and point %d, with plane %d\n", i%nv, (i + 1)%nv, k));
// mprintf((" point %d, is at, x %0.2f y %0.2f z %0.2f and point %d, is at, x %0.2f y %0.2f z %0.2f\n", i%nv, decal_point_list[decal_poly[i]]->xyz.x, decal_point_list[decal_poly[i]]->xyz.y, decal_point_list[decal_poly[i]]->xyz.z, (i + 1)%nv, decal_point_list[decal_poly[(i + 1)%nv]]->xyz.x, decal_point_list[decal_poly[(i + 1)%nv]]->xyz.y, decal_point_list[decal_poly[(i + 1)%nv]]->xyz.z));
is_infront2 = is_infront;
float is_in = fvi_point_dist_plane(&decal_cube_plane[k][0], &decal_cube_plane[k][1], decal_point_list[decal_poly[(i + 1)%nv]]);
if(is_in >= 0){
is_infront = 1;
}else{
is_infront= 0;
}
if(is_infront != is_infront2){
if(fvi_segment_plane(&new_decal->vert[nverts], &decal_cube_plane[k][0], &decal_cube_plane[k][1], decal_point_list[decal_poly[i%nv]], decal_point_list[decal_poly[(i + 1)%nv]], 0)){
// mprintf(("segment %d %d has an an itersection\n", i%nv, (i + 1)%nv));
decal_point_list[nverts] = &new_decal->vert[nverts];
// mprintf(("new decal defpoint has been added as number %d at x %0.2f y %0.2f z %0.2f\n",nverts, new_decal->vert[nverts].xyz.x, new_decal->vert[nverts].xyz.y, new_decal->vert[nverts].xyz.z));
temp_poly[numv] = nverts++;
// mprintf(("temp_poly point %d, should have been set to defpoint %d, it was set to %d\n",numv, nverts-1, temp_poly[numv]));
skip = (skip+1)%2;
// mprintf(("skip has been set to %d\n",skip));
numv++;
if((skip == 0)){
// mprintf(("adding point, becase it is after an intersection point\n", (i + 1)%nv));
temp_poly[numv] = decal_poly[(i + 1)%nv];
numv++;
}
}else{
// mprintf(("there sould have been an intersection but there wasnt"));
}
}else{
if((skip == 0)){//don't copy the first point
// mprintf(("segment %d %d has no itersection, copying\n", i%nv, (i + 1)%nv));
temp_poly[numv] = decal_poly[(i + 1)%nv];
numv++;
}else{
// mprintf(("skipping segment %d %d becase it isn't in front of the plane\n", i%nv, (i + 1)%nv));
}
}
now we copy the temp poly to the decal poly and move to the next plane
// mprintf(("temp poly has %d points\n", numv));
for(int h = 0; h < numv; h++){
decal_poly[h] = temp_poly[h];
mprintf(("seting decal_poly point %d to %d\n",h,temp_poly[h]));
}
nv = numv;
numv=0;
// mprintf(("decal_poly now has has %d points\n", nv));
if(nv < 3)return; //if at any time we get fewer than three points this poly is dead
then we copy the poly to the decal
if((valid == 1) && (nv > 2)){
/* for (i=1;i<(nv-1);i++) {
if(poly_num >= MAX_DECAL_POLY){
mprintf(("bugging out becase there are too many polys in the decal\n"));
return;
}
new_decal->poly[poly_num].point[0] = decal_poly[0];
new_decal->poly[poly_num].point[1] = decal_poly[i];
new_decal->poly[poly_num].point[2] = decal_poly[i+1];
new_decal->poly[poly_num].norm = pnorm;
if(back > 0){
new_decal->poly[poly_num].backfaced = 0;
}else{
new_decal->poly[poly_num].backfaced = 1;
}
for (k=0;k<3;k++) {
//calculate the UV coords
new_decal->poly[poly_num].uv[k].u = (fvi_point_dist_plane(&decal_cube_plane[0][0], &decal_cube_plane[0][1], &new_decal->vert[new_decal->poly[poly_num].point[k]]) / (min_rad*2));
new_decal->poly[poly_num].uv[k].v = (fvi_point_dist_plane(&decal_cube_plane[2][0], &decal_cube_plane[2][1], &new_decal->vert[new_decal->poly[poly_num].point[k]]) / (min_rad*2));
}
// mprintf(("decal poly %d, vert 0 being set to %d, vert 1 %d, and vert 2 %d\n", poly_num, new_decal->poly[poly_num].point[0], new_decal->poly[poly_num].point[1], new_decal->poly[poly_num].point[2]));
poly_num++;
}*/
for (i=0;i if(poly_num >= MAX_DECAL_POLY){
mprintf(("bugging out becase there are too many polys in the decal\n"));
return;
}
if(i >= MAX_DECAL_POLY_POINT){
mprintf(("bugging out becase there are too many points in the poly\n"));
return;
}
new_decal->poly[poly_num].point[i] = decal_poly[i];
new_decal->poly[poly_num].norm = pnorm;
if(back > 0){
new_decal->poly[poly_num].backfaced = 0;
}else{
new_decal->poly[poly_num].backfaced = 1;
}
//calculate the UV coords
new_decal->poly[poly_num].uv[i].u = (fvi_point_dist_plane(&decal_cube_plane[0][0], &decal_cube_plane[0][1], &new_decal->vert[new_decal->poly[poly_num].point[i]]) / (min_rad*2));
new_decal->poly[poly_num].uv[i].v = (fvi_point_dist_plane(&decal_cube_plane[2][0], &decal_cube_plane[2][1], &new_decal->vert[new_decal->poly[poly_num].point[i]]) / (min_rad*2));
// mprintf(("decal poly %d, vert 0 being set to %d, vert 1 %d, and vert 2 %d\n", poly_num, new_decal->poly[poly_num].point[0], new_decal->poly[poly_num].point[1], new_decal->poly[poly_num].point[2]));
}
poly_num++;
}else{
// mprintf(("no poly, all points are out side of planes"));
}
mprintf(("there are now %d polys in the current decal\n", poly_num));
I will go over this tonight (saw a few things that seemed odd) but now I have to hurry to work