I've been sick for the last few days so I only started reworking this last night,
I didn't see any good distance from plane function so I made one my self, would someone tell me if I got this little bit right
//tells distance from a plain to a point-Bobboau
float fvi_point_dist_plane( vector *plane_pnt, vector *plane_norm, // Plane description, a point and a normal
vector *point //a point to test
)
{
float dist,D;
D = -vm_vec_dot(plane_norm,plane_pnt);
dist = vm_vec_dot(plane_norm, point) + D;
return dist;
}
plane_pnt is a point on you're plane
plane_norm is the plane's normal
point is the point in question
it should return > 0 if the point is in front of the plane, < 0 if behind, and 0 if right on the plane.
in the decal code I start an intersection test from the first point that is in front of each of the six planes (I'm checking the top and bottom of my volume) and after the first intersection I don't copy any vert data untill I get an other one
might as well post the current decal code
I have this all in a interpeter, like the rendering and colision code has, it's fairly similar to the colision code up to this part
anything that you can't see defined is probly a global
this is only a few hours of work and it doesn't work at all yet, but from what I can see in the debug spew I'm working along the right path
oh, I'm trying method 1 first becase it sounds like it would be the easiest (I already have the rendering system and data structures set up for it)
void decal_create_tmappoly(ubyte * p)
{
mprintf(("entering decal_create_tmappoly\n"));
int i;
int nv;
model_tmap_vert *verts;
nv = dw(p+36);
if ( nv < 0 ) 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;
}
//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;
}
//poly culling
int temp_poly[820];
int skip = 0, numv = 0;
mprintf(("starting to test the poly, with %d verts in it\n",nv));
for(int k = 0; k<6; k++){
//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));
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));
}
}
//first point in front of the plane is good of corse
if(first_good == -1)continue;
temp_poly[0] = first_good;
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
for(i = first_good; i < (nv + first_good); i++){
mprintf(("looking for intersections between point %d and point %d, with plane %d\n", i%nv, (i + 1)%nv, k));
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[(i+1)%nv] = nverts++;
mprintf(("temp_poly point %d, was set to defpoint %d\n",(i+1)%nv, nverts-1));
skip = (skip+1)%2;
mprintf(("skip has been set to %d\n",skip));
numv++;
}else{
if(skip == 0){
mprintf(("segment %d %d has no itersection, copying\n", i%nv, (i + 1)%nv));
temp_poly[(i+1)%nv] = 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));
}
}
}
for(int h = 0; h < numv; h++)decal_poly[h] = temp_poly[h];
nv = numv;
}
mprintf(("copyint the poly to the decal, number %d\n", poly_num));
//copy a triangulated version of the poly to the new decal
for (i=1;i<(nv-1);i++) {
new_decal.poly[poly_num].point[0] = decal_poly[0];
new_decal.poly[poly_num].point[i] = decal_poly[i];
new_decal.poly[poly_num].point[i+1] = decal_poly[i+1];
}
poly_num++;
}
this is the first pass, so it's prety ugly
the volume I define is all ready in the models frame of reference (or it should be), and I was going to assign a diferent texture to backfaced polies (I'm useing a cube not just an infinitely extruded square, so this should only effect polys on thin model sections), also I'm useing a distance check thing to cull polys rather than bounding boxes (seemed like it would work better, or easier at least, even though it may give false positives),
assuming I'm setting the gloabals corectly I think this is almost working (for setting the geometry), I'm going to set UV coordanants baised on how far they are from the plains (sort of like a normal planer uv projection, but I was thinking about including the top and bottom of the cube so the coords are sort of baised on the distance from the center, cubic projection)