Author Topic: any help with a decal math problem  (Read 928 times)

0 Members and 1 Guest are viewing this topic.

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
any help with a decal math problem
ok, I'm trying to solve a little performence issue with the decals by clipping them to the UV boundery (cutting them off at 0.0 to 1.0) the idea I had was to use the UV coords I had to interpolate the geometry, well it doesn't work, but I'm not sure why, it probly has to do with decal_clip_line, you are suposed to give it two vetexes, and a UV coord (and tell it weather to clip for U of V) and it finds how far off that coord is between the two verts, then subtracts the second one from the first multiplys it by the ratio that the UV coord is being multiplyed by, then add the first point back on, it seemed to work on paper but it isn't in game, if anyone has any ideas how to get this to work, liniar agebra isn't my strongest suit, (though I just had an idea) so any math peoples try and think about it

Code: [Select]

void decal_clip_line(vertex *out,vertex* p1, vertex* p2, float test, bool U){
//test is wich part of the UV plane were testing 0.0 or 1.0
//U is if were testing the u of the uv pair, if false then were testing v
float iterp = 0.0;
if(U)iterp = (p1->u - test)/(p1->u - p2->u);
else iterp = (p1->v - test)/(p1->v - p2->v);
out->x = ((p2->x-p1->x)*iterp)+p1->x;
out->y = ((p2->y-p1->y)*iterp)+p1->y;
out->z = ((p2->z-p1->z)*iterp)+p1->z;
if(U){
out->u = ((p2->u-p1->u)*iterp)+p1->u;
out->v = p1->v;;
}else{
out->u = p1->u;
out->v = ((p2->v-p1->v)*iterp)+p1->v;
}
}

int decal_clip_tri(vertex in[3], vertex out[20]){
vertex work[20];
memcpy(work, in, sizeof(vertex)*3);
int n_verts = 0;
int old_n_verts = 3;

for(int i = 0; i //for each edge, in[i], in[(i+1)%3]
if((work[i].u <= 1.0f)){
//if the starting point is ok, copy it
out[n_verts++] = work[i];

if(!(work[(i+1)%old_n_verts].u <= 1.0f)){
//if the end point is bad, clip between them
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 1.0f, true);
//don't clip between two bad points
}
}else if((work[(i+1)%old_n_verts].u <= 1.0f)){
//if the start point is bad, but the end point is good clip it
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 1.0f, true);
//don't clip between two bad points
}

}
old_n_verts = n_verts;
n_verts = 0;
memcpy(work, out, sizeof(vertex)*20);
for( i = 0; i //for each edge, in[i], in[(i+1)%3]
if((work[i].u >= 0.0f)){
//if the starting point is ok, copy it
out[n_verts++] = work[i];

if(!(work[(i+1)%old_n_verts].u >= 0.0f)){
//if the end point is bad, clip between them
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 0.0f, true);
//don't clip between two bad points
}
}else if((work[(i+1)%old_n_verts].u >= 0.0f) ){
//if the start point is bad, but the end point is good clip it
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 0.0f, true);
//don't clip between two bad points
}

}

old_n_verts = n_verts;
n_verts = 0;
memcpy(work, out, sizeof(vertex)*20);
for( i = 0; i //for each edge, in[i], in[(i+1)%3]
if((work[i].v <= 1.0f)){
//if the starting point is ok, copy it
out[n_verts++] = work[i];

if(!(work[(i+1)%old_n_verts].v <= 1.0f)){
//if the end point is bad, clip between them
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 1.0f, false);
//don't clip between two bad points
}
}else if((work[(i+1)%old_n_verts].v <= 1.0f) ){
//if the start point is bad, but the end point is good clip it
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 1.0f, false);
//don't clip between two bad points
}

}

old_n_verts = n_verts;
n_verts = 0;
memcpy(work, out, sizeof(vertex)*20);
for( i = 0; i //for each edge, in[i], in[(i+1)%3]
if((work[i].v >= 0.0f)){
//if the starting point is ok, copy it
out[n_verts++] = work[i];

if(!(work[(i+1)%old_n_verts].v >= 0.0f)){
//if the end point is bad, clip between them
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 0.0f, false);
//don't clip between two bad points
}
}else if((work[(i+1)%old_n_verts].v >= 0.0f) ){
//if the start point is bad, but the end point is good clip it
decal_clip_line(&out[n_verts++], &work[i], &work[(i+1)%old_n_verts], 0.0f, false);
//don't clip between two bad points
}

}
return n_verts;
}

Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together