Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Bobboau on November 17, 2002, 05:15:30 am
-
I have started work on basic decal code, and it seems as if it should be working but it isn't, below are the two functions for makeing and rendering a basic non-clipped decal, and the header files for the new data, I also added
decal decals[MAX_SHIP_DECALS]; //the decals of the ship
to the ship strucure,
as far as I can tell the create function works, it seems to generate the proper polygons (in the form of vertex[poly][vert]) but it doesn't render them, as you can see there is quite a bit of debug text and the readout (seems to) show that the verts are getting positioned in the proper place, and I made it so that if it was getting rendered in global coords when it should be local or vice versa that the effect would be so big I could see it from quite a distance,
and I have called the rendering function from within both the ship render ruteen and the model render code got nothing on ether one
the code is designed to be compatable with future improvements that will clip decals to the hull of the ship
and I currently have the create function called from within beam_add_collision() just above the sheild hit code in order to give it a good oreintation matrix like this
I used the orientation of the hit ship as a second point becase I couldn't think of something better at the time, and I figured it would work
decal_point dec;
dec.orient.vec.fvec = cinfo->hit_normal;
//get a good orientation matrix baised on the normal of the hit face and the orientation of the ship it hit-Bobboau
vm_vec_normalize( &dec.orient.vec.fvec );
vm_vec_crossprod( &dec.orient.vec.uvec, &hit_object->orient.vec.rvec, &dec.orient.vec.fvec);
vm_vec_normalize( &dec.orient.vec.uvec );
vm_vec_crossprod( &dec.orient.vec.rvec, &dec.orient.vec.uvec, &dec.orient.vec.fvec);
vm_vec_normalize( &dec.orient.vec.rvec );
vm_vec_normalize( &dec.orient.vec.uvec );
vm_vec_normalize( &dec.orient.vec.fvec );
dec.pnt = cinfo->hit_point;
dec.radius = bwi->b_info.beam_muzzle_radius*2;
decal_create_simple(hit_object, &dec, bwi->b_info.beam_glow_bitmap);
#ifndef _DECAL_H
#define _DECAL_H
#define MAX_DECAL_POLY 20
#define MAX_DECAL_POINT 40
#define MAX_SHIP_DECALS 25
#include "globalincs/pstypes.h"
#include "object/object.h"
typedef struct decal{
vertex vert[MAX_DECAL_POLY][3];
int texture;
int is_valid; //this means it is a good decal that should be rendered-Bobboau
int n_poly;
}decal;
typedef struct decal_point{
vector pnt;
matrix orient;
float radius;
}decal_point;
#endif
int decal_create_simple(object * obj, decal_point *point, int texture);//makes a simple non-clipped decal
void decal_render_all(object * obj); //renders all decals
int decal_create_simple(object *obj, decal_point *point, int texture){//makes a simple non-clipped decal
mprintf(("a decal is about to be made at %0.2f, %0.2f, %0.2f\n", point->pnt.xyz.x, point->pnt.xyz.y, point->pnt.xyz.z));
if(obj->type != OBJ_SHIP){
return 0;
}
// vertex vert[1][2];
vector vec[4];
vector center = point->pnt;
float rad = point->radius * 100;
if(rad <=0) rad = 10;
mprintf(("radius %f\n",rad));
vector plain_point[4];
mprintf(("orient uvec x %0.2f %0.2f %0.2f\n", point->orient.vec.uvec.xyz.x, point->orient.vec.uvec.xyz.y, point->orient.vec.uvec.xyz.z));
mprintf(("orient rvec x %0.2f %0.2f %0.2f\n", point->orient.vec.rvec.xyz.x, point->orient.vec.rvec.xyz.y, point->orient.vec.rvec.xyz.z));
mprintf(("orient fvec x %0.2f %0.2f %0.2f\n", point->orient.vec.fvec.xyz.x, point->orient.vec.fvec.xyz.y, point->orient.vec.fvec.xyz.z));
plain_point[0] = point->orient.vec.uvec;
plain_point[1] = plain_point[0];
vm_vec_invert(&plain_point[1]);
plain_point[2] = point->orient.vec.rvec;
plain_point[3] = plain_point[2];
vm_vec_invert(&plain_point[3]);
vm_vec_scale_add( &vec[0], ¢er, &plain_point[0], rad );
vm_vec_scale_add( &vec[1], ¢er, &plain_point[2], rad );
vm_vec_scale_add( &vec[2], ¢er, &plain_point[1], rad );
vm_vec_scale_add( &vec[3], ¢er, &plain_point[3], rad );
mprintf(("\n"));
ship *shipp = &Ships[obj->instance];
decal *dec = shipp->decals;
dec[0].vert[0][0].x = vec[0].xyz.x;
dec[0].vert[0][0].y = vec[0].xyz.y;
dec[0].vert[0][0].z = vec[0].xyz.z;
dec[0].vert[0][1].x = vec[1].xyz.x;
dec[0].vert[0][1].y = vec[1].xyz.y;
dec[0].vert[0][1].z = vec[1].xyz.z;
dec[0].vert[0][2].x = vec[3].xyz.x;
dec[0].vert[0][2].y = vec[3].xyz.y;
dec[0].vert[0][2].z = vec[3].xyz.z;
dec[0].vert[1][0].x = vec[1].xyz.x;
dec[0].vert[1][0].y = vec[1].xyz.y;
dec[0].vert[1][0].z = vec[1].xyz.z;
dec[0].vert[1][1].x = vec[2].xyz.x;
dec[0].vert[1][1].y = vec[2].xyz.y;
dec[0].vert[1][1].z = vec[2].xyz.z;
dec[0].vert[1][2].x = vec[3].xyz.x;
dec[0].vert[1][2].y = vec[3].xyz.y;
dec[0].vert[1][2].z = vec[3].xyz.z;
dec[0].vert[0][0].u = 0;
dec[0].vert[0][1].u = 0;
dec[0].vert[0][2].u = 1;
dec[0].vert[0][0].v = 0;
dec[0].vert[0][1].v = 1;
dec[0].vert[0][2].v = 1;
dec[0].vert[1][0].u = 0;
dec[0].vert[1][1].u = 1;
dec[0].vert[1][2].u = 1;
dec[0].vert[1][0].v = 1;
dec[0].vert[1][1].v = 0;
dec[0].vert[1][2].v = 1;
mprintf(("poly 1 vert 1 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[0][0].x, dec[0].vert[0][0].y, dec[0].vert[0][0].z));
mprintf(("poly 1 vert 2 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[0][1].x, dec[0].vert[0][1].y, dec[0].vert[0][1].z));
mprintf(("poly 1 vert 3 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[0][2].x, dec[0].vert[0][2].y, dec[0].vert[0][2].z));
mprintf(("poly 2 vert 1 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[1][0].x, dec[0].vert[1][0].y, dec[0].vert[1][0].z));
mprintf(("poly 2 vert 2 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[1][1].x, dec[0].vert[1][1].y, dec[0].vert[1][1].z));
mprintf(("poly 2 vert 3 x %0.2f y %0.2f z %0.2f\n",dec[0].vert[1][2].x, dec[0].vert[1][2].y, dec[0].vert[1][2].z));
dec[0].texture = texture;
dec[0].n_poly = 2;
dec[0].is_valid = 1;
mprintf(("a decal should have been made at %0.2f %0.2f %0.2f\n", point->pnt.xyz.x, point->pnt.xyz.y, point->pnt.xyz.z));
//Int3();
return 1;
}
void decal_render_all(object * obj){
vertex vecs[3];
vertex *vlist[3] = { &vecs[0], &vecs[1], &vecs[2] };
mprintf(("about to render all decals\n"));
ship *shipp = &Ships[obj->instance];
for(int h = 0; h < MAX_SHIP_DECALS; h++){
decal *dec = &shipp->decals[h];
if(dec->is_valid){
mprintf(("decal %d is valid, and has %d polys\n",h,dec->n_poly));
for(int i = 0; in_poly; i++){
mprintf(("drawing decal poly %d, with bitmap %d\n", i, dec->texture));
gr_set_bitmap(dec->texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
vecs[0] = dec->vert[i][0];
vecs[1] = dec->vert[i][1];
vecs[2] = dec->vert[i][2];
mprintf(("vert 1 at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", vecs[0].x, vecs[0].y, vecs[0].z, vecs[0].u, vecs[0].v));
mprintf(("vert 2 at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", vecs[1].x, vecs[1].y, vecs[1].z, vecs[1].u, vecs[1].v));
mprintf(("vert 3 at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", vecs[2].x, vecs[2].y, vecs[2].z, vecs[2].u, vecs[2].v));
gr_set_cull(0);
g3_draw_poly(3, vlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_CORRECT );
gr_set_cull(1);
}
}
}
mprintf(("decals rendered\n"));
}
now I have been trying to solve this for about a week now and I just can't figure out what I'm doing wrong
*update* just had a weird bug in my test mission were a distorted poly got put accros my view like a huf item, I think I need to unflag them as projected, gona try it now
-
hey, I thought after this much time I would have gotten at least a basic egnolegement type responce
-
acknowledgement IIRC....but yeah....
I hope you get this working, and I have no idea how to sling polys, so I couldn't help you...
-
hello...
anybody here
-
I'm not entirely sure what this is. Is it for applying 'damage decals' onto ships, like 2D bomb crater marks, and beam scorches?
-
yes, it's very primitave though.
-
I'll post this on a couple of dev boards, maybe we can get you some help...
-
I'm fairly sure it's something in the rendering function, and that its something fairly FS specific, I'm probly not rotateing a vert around the location of the parent object or something
-
ok if I have three vertexes with coordanants relitive to an object and I want to render a polygon with thouse verts relitive to that object what do I need to do
for( int j = 0; j < 3; j++){
vecs[j] = dec->vert[i][j];
g3_rotate_vertex(&vecs[j], &obj->pos);
mprintf(("vert %d at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", j, vecs[j].x, vecs[j].y, vecs[j].z, vecs[j].u, vecs[j].v));
}
gr_set_cull(0);
g3_draw_poly(3, vlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_CORRECT );
gr_set_cull(1);
I tryed this it doesn't work
-
this is a segment of the debug spew I get, as you can see the local coords are corect (this was a faustus getting hit tward the front), the radius is corect as I want it huge so if it shows up anyware I will be able to see it, but, depending on what fiddeling I've done, I ether see nothing or I get the effect smeared across the screen (it isn't out in space if I swich veiws I still see it)
a decal is about to be made at -8.73, -0.05, 75.55
radius 200.000000
orient uvec x 0.00 -0.85 -0.53
orient rvec x -1.00 0.00 -0.00
orient fvec x -0.00 -0.53 0.85
poly 1 vert 1 x -8.73 y -169.22 z -31.13
poly 1 vert 2 x -208.73 y -0.05 z 75.55
poly 1 vert 3 x 191.27 y -0.05 z 75.55
poly 2 vert 1 x -208.73 y -0.05 z 75.55
poly 2 vert 2 x -8.73 y 169.12 z 182.23
poly 2 vert 3 x 191.27 y -0.05 z 75.55
a decal should have been made at -8.73 -0.05 75.55
about to render all decals
decal 0 is valid, and has 2 polys
drawing decal poly 0, with bitmap 63022
vert 0 at x -41.99 y -60.45 z 262.46 u 1.00 v 1.00
vert 1 at x -41.99 y -60.45 z 262.46 u 1.00 v 0.00
vert 2 at x -41.99 y -60.45 z 262.46 u 0.00 v 0.00
drawing decal poly 1, with bitmap 63022
vert 0 at x -41.99 y -60.45 z 262.46 u 1.00 v 0.00
vert 1 at x -41.99 y -60.45 z 262.46 u 0.00 v 1.00
vert 2 at x -41.99 y -60.45 z 262.46 u 0.00 v 0.00
decals rendered
this doesn't work ether
for( int j = 0; j < 3; j++){
vecs[j] = dec->vert[i][j];
g3_rotate_vertex(&vecs[j], &obj->pos);
g3_project_vertex(&vecs[j]);
mprintf(("vert %d at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", j, vecs[j].x, vecs[j].y, vecs[j].z, vecs[j].u, vecs[j].v));
}
:sigh: I no nobody is gona even look at this, but it helps the frustration
-
ah HA!!!
it sort of works!!!
for( int j = 0; j < 3; j++){
vecs[j] = dec->vert[i][j];
vector pos;
vm_vert2vec(&vecs[j], &pos);
vm_vec_add2(&pos, &obj->pos);
g3_rotate_vertex(&vecs[j], &pos);
g3_project_vertex(&vecs[j]);
mprintf(("vert %d at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", j, vecs[j].x, vecs[j].y, vecs[j].z, vecs[j].u, vecs[j].v));
}
:ha:
-
GOT IT!!!
ya!!!
for( int j = 0; j < 3; j++){
vecs[j] = dec->vert[i][j];
vector pos;
vm_vert2vec(&vecs[j], &pos);
g3_rotate_vertex(&vecs[j], &pos);
g3_project_vertex(&vecs[j]);
mprintf(("vert %d at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", j, vecs[j].x, vecs[j].y, vecs[j].z, vecs[j].u, vecs[j].v));
:p
I still need to take into acount rotateing submodels and I have to fix the UVs, but it's working
then I need to get it to make more than one, wich will be basicly only be recycleing the oldest point
then I have to make cliped decals
-
hey this things prety fun, use a fighter beam and hit a cap ship, it will project the beam's muzle glow texture upon the surface you hittry it (http://freespace.volitionwatch.com/blackwater/fs2decal.zip)
in addition to clipped decals I am going to make an effect baised on this that makes an impact effect for weapons that looks like energy getting sheathed off
-
Wow! Now THAT's interesting. I just tried it. BTW, if you force your weapon (using cheats) to sgreen or another beam, it leaves a HUGE decal.
-
ok I've reworked it I think it's a bit faster this way
typedef struct decal{
struct{
uv_pair uv[3];
int point[3]; //an index to the vert list-Bobboau
}poly[MAX_DECAL_POLY];
vector vert[MAX_DECAL_POLY * 3]; //the defpoints-Bobboau
int texture;
int is_valid; //this means it is a good decal that should be rendered-Bobboau
int n_poly;
int timestamp; //is to start fadeing away-Bobboau
}decal;
typedef struct decal_point{
vector pnt;
matrix orient;
float radius;
}decal_point;
int decal_create_simple(object *obj, decal_point *point, int texture){//makes a simple non-clipped decal
mprintf(("a decal is about to be made at %0.2f, %0.2f, %0.2f\n", point->pnt.xyz.x, point->pnt.xyz.y, point->pnt.xyz.z));
if(obj->type != OBJ_SHIP){
return 0;
}
// vertex vert[1][2];
// vector vec[4];
vector center = point->pnt;
float rad = point->radius * 2;
if(rad <=0) rad = 10;
mprintf(("radius %f\n",rad));
vector plain_point[4];
// mprintf(("orient uvec x %0.2f %0.2f %0.2f\n", point->orient.vec.uvec.xyz.x, point->orient.vec.uvec.xyz.y, point->orient.vec.uvec.xyz.z));
// mprintf(("orient rvec x %0.2f %0.2f %0.2f\n", point->orient.vec.rvec.xyz.x, point->orient.vec.rvec.xyz.y, point->orient.vec.rvec.xyz.z));
// mprintf(("orient fvec x %0.2f %0.2f %0.2f\n", point->orient.vec.fvec.xyz.x, point->orient.vec.fvec.xyz.y, point->orient.vec.fvec.xyz.z));
plain_point[0] = point->orient.vec.uvec;
plain_point[1] = plain_point[0];
vm_vec_negate(&plain_point[1]);
plain_point[2] = point->orient.vec.rvec;
plain_point[3] = plain_point[2];
vm_vec_negate(&plain_point[3]);
mprintf(("\n"));
ship *shipp = &Ships[obj->instance];
decal *dec = shipp->decals;
vm_vec_scale_add( &dec[0].vert[0], ¢er, &plain_point[0], rad );
vm_vec_scale_add( &dec[0].vert[1], ¢er, &plain_point[2], rad );
vm_vec_scale_add( &dec[0].vert[2], ¢er, &plain_point[1], rad );
vm_vec_scale_add( &dec[0].vert[3], ¢er, &plain_point[3], rad );
dec[0].poly[0].point[0] = 0;
dec[0].poly[0].point[1] = 1;
dec[0].poly[0].point[2] = 2;
dec[0].poly[1].point[0] = 0;
dec[0].poly[1].point[1] = 3;
dec[0].poly[1].point[2] = 2;
dec[0].poly[0].uv[0].u = 0; dec[0].poly[0].uv[0].v = 0;
dec[0].poly[0].uv[1].u = 0; dec[0].poly[0].uv[1].v = 1;
dec[0].poly[0].uv[2].u = 1; dec[0].poly[0].uv[2].v = 1;
dec[0].poly[1].uv[0].u = 0; dec[0].poly[1].uv[0].v = 0;
dec[0].poly[1].uv[1].u = 1; dec[0].poly[1].uv[1].v = 0;
dec[0].poly[1].uv[2].u = 1; dec[0].poly[1].uv[2].v = 1;
dec[0].texture = texture;
dec[0].n_poly = 2;
dec[0].is_valid = 1;
dec[0].timestamp = timestamp();
mprintf(("a decal should have been made at %0.2f %0.2f %0.2f\n", point->pnt.xyz.x, point->pnt.xyz.y, point->pnt.xyz.z));
//Int3();
return 1;
}
void decal_render_all(object * obj){
vertex vecs[3];
vertex *vlist[3] = { &vecs[0], &vecs[1], &vecs[2] };
mprintf(("about to render all decals\n"));
ship *shipp = &Ships[obj->instance];
for(int h = 0; h < MAX_SHIP_DECALS; h++){
decal *dec = &shipp->decals[h];
if(dec->is_valid){
mprintf(("decal %d is valid, and has %d polys\n",h,dec->n_poly));
for(int i = 0; in_poly; i++){
//mprintf(("drawing decal poly %d, with bitmap %d\n", i, dec->texture));
gr_set_bitmap(dec->texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
for( int j = 0; j < 3; j++){
// vecs[j] = dec->vert[i][j];
// vector pos;
// vm_vert2vec(&vecs[j], &pos);
// vm_vec_add2(&pos, &obj->pos);
g3_rotate_vertex(&vecs[j], &dec->vert[dec->poly[i].point[j]]);
g3_project_vertex(&vecs[j]);
vecs[j].u = dec->poly[i].uv[j].u;
vecs[j].v = dec->poly[i].uv[j].v;
//mprintf(("vert %d at x %0.2f y %0.2f z %0.2f u %0.2f v %0.2f\n", j, vecs[j].x, vecs[j].y, vecs[j].z, vecs[j].u, vecs[j].v));
}
gr_set_cull(0);
g3_draw_poly(3, vlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_CORRECT );
gr_set_cull(1);
}
}
}
mprintf(("decals rendered\n"));
}
-
(http://members.aol.com/lowark/FS2/Smilies/bump.gif)
DOES ANYONE ELSE CARE? THIS IS SO COOL!
-
I want to check it out, but every time I try to load a mission it crashes saying "Could not load model ." :confused:
By the way, Bobboau, I've started work on the ballistics primary conversion, so no need to feel swamped with requests. :)
-
maybe they are all put off by the title,
anyway, I'm currently working on the fully cliped version, and as such I'm going to make a function that makes a triangulated version of the hull in this format
typedef struct decal_model{ //this will store a triangulated version of the ships polygons
int point[800][3]; //an index to the vert list-Bobboau
vector vert[1200]; //the defpoints-Bobboau
int n_polys;
}decal_model;
I'm going to make the cliped decals by first figuring out wich faces (useing the decal_model) are posably going to be used, then on a polygon by polygon basis, I'm going to figure out what part of the poly is going to be used (if any), so if the entire poly is inside the decal box I'll just copy it to the ship's decal's poly list, if two of it's three verts are in side I'll copy the two verts, do a colision calculation to find the other two\three verts, thriangulate and stor the results, then when I'm all done I'll calculate the UV coords for each vert of each polygon, the rest of the code should be able to handel it from there.
as I was writeing up the submodel interpeter I needed, I started to think would it be faster if we stuffed all the poly data into an actual structure rather than the gobuldy gook it's all in now, it would ceranly make things clearer than they are now, though it might not be faster, wich I wouldn't want to harm
-
"I want to check it out, but every time I try to load a mission it crashes saying "Could not load model ." "
see if this (http://freespace.volitionwatch.com/blackwater/warpmodel.zip) fixes it
-
Well, it let the mission start, but as soon as a ship was about to warp in it crashed again.
Assert: Polygon_models[num]->id == model_num
File: D:\Games\projects\freespace2_public\fs2_open\code\Model\ModelRead.cpp
Line: 2461
Call stack:
------------------------------------------------------------------
model_render() warpin_render() fireball_render() obj_render() obj_render_all() game_render_frame() game_frame() game_do_frame() game_do_state() gameseq_process_events() WinMainSub() WinMain() WinMainCRTStartup() KERNEL32.DLL bff8b560()
KERNEL32.DLL bff8b412()
------------------------------------------------------------------
By the way, I just thought of something funny. :) Bobboau, how customizable is your decal trick? If we could configure the TAG missiles to leave a bright primary-colored decal on every ship they hit, we could have ourselves a genuine game of paintball. :lol:
-
are you useing a mod (and if so are you useing DTP's mod code)?
I've had some problems recently regarding this
and yes it could do that
-
You leave me speechless, Bobboau. :D
Any screenies? And what sort of performance hit do decals produce?
-
No mods. And oddly enough, I just went back in and it worked fine. Looks like a bug. :)
EDIT: Ah, nuts. Happened again. Same error, and it appeared to be completely random. :confused:
-
hmm, that ain't good...
here are some pics
they show both new glow point code and the decal code, note the decals show up in the target view, and I have to use the same transparency code as used in the weapon effects for now, I'm hopeing we to set a transparency bitmap soon
(http://freespace.volitionwatch.com/blackwater/decaltest00.jpg)
(http://freespace.volitionwatch.com/blackwater/decaltest01.jpg)
(http://freespace.volitionwatch.com/blackwater/decaltest02.jpg)
(http://freespace.volitionwatch.com/blackwater/decaltest03.jpg)
the last one shows the big problem with this method
-
Given the description of your algorithm earlier, Bob, I would have expected that dangling decal to have folded over to the top surface. I think that I may have misunderstood your methodology.
-
decal_create_simple only projects a two poly plain perpindicular to the normal of the hit poly, the rendering code should work with more complex decals, but I'm gona make what is basicly a boolein intersection with a projected cube, but I havn't done that yet (not sure I will be able to at all in fact)
the description was what I'm going to do not what I've done
-
Once you've got that down, would we be able to apply this technology to having shield effects of a set size on a capship without needing a seperate mesh?
Bah, I'm getting ahead of myself here... this is teh l33t. :D When you hit the rotating panels with the beam, does the decal stick?
-
the simple decals could be used in place of the current hit effect for capships, yes
I havn't gotten the rotating submodels covered yet, I'll have to make a submodel parent and do something similar to what I did with the glow points,
and odd thing if you hit were the submodel it in it's default position, it will act like it is hitting it right there
eventualy I'd like to use diferent bitmaps for decals that are getting hit at a diferent angle, and decals that rebuild themselves with beams so you end up with big ass swaths'o destruction
-
it's weird how nobody cares about this
-
As you said, they're probably turned off by the title. Start a new thread. :nod:
-
Originally posted by Bobboau
are you useing a mod (and if so are you useing DTP's mod code)?
I've had some problems recently regarding this
and yes it could do that
i would love to hear all about them
your troubles, so if there is a problem, so that i can solve it.
-
Originally posted by Bobboau
it's weird how nobody cares about this
...I care. :(
-
Me too! :(
Especially since I can't get it to work, and I want to see it. :(
-
Moi aussi
-
I just got my subobject interpeter to spit out a trianglulated version of the hull, which means I can now start on the real hard part of the clipped decals code
-
mkey, I've gotten the first version of the clipped decal code in it's first revision, it of corse does not work, but here it is, anyone who can find the many many bugs in it befor me will have the great honor of beeing 13373|2 than me
int decal_create(object * obj, decal_point *point, int subobject, int texture){
mprintf(("a decal is about to be made at %0.2f, %0.2f, %0.2f\n", point->pnt.xyz.x, point->pnt.xyz.y, point->pnt.xyz.z));
if(obj->type != OBJ_SHIP){
return 0;
}
vector center = point->pnt;
float rad = point->radius * 2;
if(rad <=0) rad = 10;
mprintf(("radius %f\n",rad));
vector plain_point[4];
vector cube_point[8];
//define the decals dimentions
plain_point[0] = point->orient.vec.uvec;
plain_point[1] = plain_point[0];
vm_vec_negate(&plain_point[1]);
plain_point[2] = point->orient.vec.rvec;
plain_point[3] = plain_point[2];
vm_vec_negate(&plain_point[3]);
vector topcenter;
vector bvec = point->orient.vec.fvec;
vm_vec_negate(&bvec);
vm_vec_scale_add(&topcenter, ¢er, &bvec, rad);
for(int i = 0; i < 4; i++){
vm_vec_scale_add( &cube_point[i], &topcenter, &plain_point[i], rad );
vm_vec_scale_add( &cube_point[i+4], &cube_point[i], &point->orient.vec.fvec, rad*2);
}
float max_rad = vm_vec_dist(¢er, &cube_point[0]); //the cube points are all equidistant, right?
mprintf(("decal defined\n"));
//define the decals dimentions
//set up the decal model
ship *shipp = &Ships[obj->instance];
decal *sdec = &shipp->decals[0];
polymodel *pm = model_get(shipp->modelnum);
bsp_info * sm;
sm = &pm->submodel[subobject];
decal_model dmod = sm->dec_model;
decal_model tdec; //temporary decal model for holding the culled down part of the decal
//end set up the decal model
mprintf(("decal model set up\n"));
//cull out all polys you are defanantly not going to be useing
tdec.n_polys = 0;
for(i=0; i<1200; i++) tdec.vert[i] = dmod.vert[i];//make sure they have the same def points
for(i = 0; i < dmod.n_polys; i++){
if(vm_vec_dist(¢er, &dmod.poly[i].center) <= (dmod.poly[i].radius + max_rad)){
tdec.poly[tdec.n_polys++] = dmod.poly[i];
}
}
mprintf(("culled unwanted poleis\n"));
//end cull out all polys you are defanantly not going to be useing
//the good part, find what part of wich poly you are going to be useing and copy that to a ship decal
sdec->n_poly = 0;
// find defpoints
int dec_vert = 0;
int decal_vert_index[1200];
for(int j = 0; j < 3; j ++){ //if this def point is inside the box, copy it
vector test_point, temp;
vm_vec_sub(&test_point, &tdec.vert[tdec.poly[i].point[j]], &point->pnt); //make it relitive to the decal point
vm_vec_unrotate(&temp, &test_point, &point->orient); //unrotate it
test_point = temp;
if(
test_point.xyz.x < (center.xyz.x + rad) &&
test_point.xyz.x > (center.xyz.x - rad) &&
test_point.xyz.y < (center.xyz.y + rad) &&
test_point.xyz.y > (center.xyz.y - rad) &&
test_point.xyz.z < (center.xyz.z + rad) &&
test_point.xyz.z > (center.xyz.z - rad)
)
{
decal_vert_index[j] = dec_vert; //this says wich index in the ship decal relates to the decal model
sdec->vert[dec_vert++] = tdec.vert[j];
mprintf(("defpoint %d copied\n", j));
}else{
decal_vert_index[j] = -1; //if it isn't in the box then there is no vert to relate to
mprintf(("defpoint %d isn't in the cube\n", j));
}
}
mprintf(("defpoints copied\n"));
for(i = 0; i < tdec.n_polys; i++){
mprintf(("procesing tdec poly %d, there are currently %d polys in the decal\n",tdec.n_polys, sdec->n_poly));
int verts_in_cube = 0;
//find how many of the verts of this poly are in the cube
for( int k = 0; k< 3; k++){
if(decal_vert_index[tdec.poly[i].point[k]] != -1){
verts_in_cube++;
}
}
mprintf(("%d of it's verts are in the cube\n",verts_in_cube));
int n_point = 0;
int poly_point[6];
int l, r, p, v, newpnt;
vector poly_pnts[3];
switch(verts_in_cube){
case 3:
//if all verts are in the box just copy it
for(l = 0; l < 3; l++){
sdec->poly[sdec->n_poly].point[i] = decal_vert_index[tdec.poly[i].point[l]];
}
sdec->n_poly++;
break;
case 2:
//if two of the verts are in make a (posably up to five-pointed, no less than four) poly
n_point = 0;
r=0;
for( l = 0; l < 3; l++){
if(decal_vert_index[tdec.poly[i].point[l]] != -1){
//if the point is in the cube just copy it
poly_point[r++] = decal_vert_index[tdec.poly[i].point[l]];
}else{
//else find one somewere between
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//posably one from a cube intersection
for(v = 0; v<3; v++)poly_pnts[v]= tdec.vert[tdec.poly[i].point[v]];
if(decal_intersect_poly_with_cube(&sdec->vert[dec_vert], poly_pnts, cube_point, 0) == 1){
poly_point[r++] = dec_vert++;
}
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
}
//then copy the triangulated version to the ship decal
for(p = 1; p<(r-1); p++){
sdec->poly[sdec->n_poly].point[0] = poly_point[0];
sdec->poly[sdec->n_poly].point[p] = poly_point[p];
sdec->poly[sdec->n_poly].point[p+1] = poly_point[p+1];
sdec->n_poly++;
}
break;
case 1:
//if one of the verts are in make a (posably up to 5-pointed, at least 3) poly
n_point = 0;
r=0;
for( l = 0; l < 3; l++){
if(decal_vert_index[tdec.poly[i].point[l]] != -1){
//if the point is in the cube just copy it
poly_point[r++] = decal_vert_index[tdec.poly[i].point[l]];
}else{
//else find one somewere between
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//posably one from a cube intersection
vector poly_pnts[3];
vector temppnt1;
vector temppnt2;
newpnt = 0;
for(v = 0; v<3; v++)poly_pnts[v]= tdec.vert[tdec.poly[i].point[v]];
if(decal_intersect_poly_with_cube(&temppnt1, poly_pnts, cube_point, 0) == 1){
newpnt = 1;
}
//posably another one from a cube intersection
for(v = 0; v<3; v++)poly_pnts[v]= tdec.vert[tdec.poly[i].point[v]];
if(decal_intersect_poly_with_cube(&temppnt2, poly_pnts, cube_point, 1) == 1){
newpnt = 2;
}
//that function doesn't generate points in any particular order so if the first one is closer to the last point make it the naext one
if(newpnt == 1){
sdec->vert[dec_vert] = temppnt1;
poly_point[r++] = dec_vert++;
}else if(newpnt == 2){
if(vm_vec_dist(&sdec->vert[dec_vert - 1], &temppnt1) < vm_vec_dist(&sdec->vert[dec_vert - 1], &temppnt2)){
sdec->vert[dec_vert] = temppnt1;
poly_point[r++] = dec_vert++;
sdec->vert[dec_vert] = temppnt2;
poly_point[r++] = dec_vert++;
}else{
sdec->vert[dec_vert] = temppnt2;
poly_point[r++] = dec_vert++;
sdec->vert[dec_vert] = temppnt1;
poly_point[r++] = dec_vert++;
}
poly_point[r++] = dec_vert++;
}
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
}
//then copy the triangulated version to the ship decal
for(p = 1; p<(r-1); p++){
sdec->poly[sdec->n_poly].point[0] = poly_point[0];
sdec->poly[sdec->n_poly].point[p] = poly_point[p];
sdec->poly[sdec->n_poly].point[p+1] = poly_point[p+1];
sdec->n_poly++;
}
break;
case 0:
//if none of the verts are in make a (posably up to 6-pointed) poly
n_point = 0;
r=0;
newpnt = 0;
vector newpoint[4];
for(v = 0; v<3; v++)poly_pnts[v]= tdec.vert[tdec.poly[i].point[v]];
for(k = 0; k<4; k++){
if( decal_intersect_poly_with_cube(&newpoint[k], poly_pnts, cube_point, k) == 1){
newpnt = k;
}
}
float dist;
switch(newpnt){
//four cube intersections
case 4:
for(v = 0; v<4; v++){
sdec->vert[dec_vert+v] = newpoint[v];
poly_point[r++] = dec_vert++;
}
r=4;
break;
//tree cube intersections
case 3:
for(l=0; l<3; l++){
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
for(l = 0; l<3; l++){
dist = vm_vec_dist(&sdec->vert[poly_point[r-1]], &newpoint[l%3]);
//if this intersection point is closer than the other two, use it as the next point
if((dist < vm_vec_dist(&sdec->vert[poly_point[r-1]], &newpoint[(l+1)%3])) && (dist < vm_vec_dist(&sdec->vert[poly_point[r-1]], &newpoint[(l+2)%3])) ){
sdec->vert[dec_vert] = newpoint[l];
k = l;
}
}
poly_point[r++] = dec_vert++;
//of the remaining two points wich one is the farthest from the first point is next
dist = vm_vec_dist(&sdec->vert[poly_point[0]], &newpoint[(k + 1)%3]);
if(dist > vm_vec_dist(&sdec->vert[poly_point[0]], &newpoint[(k+2)%3]) ){
sdec->vert[dec_vert] = newpoint[(k + 1)%3];
poly_point[r++] = dec_vert++;
sdec->vert[dec_vert] = newpoint[(k + 2)%3];
poly_point[r++] = dec_vert++;
}else{
sdec->vert[dec_vert] = newpoint[(k + 2)%3];
poly_point[r++] = dec_vert++;
sdec->vert[dec_vert] = newpoint[(k + 1)%3];
poly_point[r++] = dec_vert++;
}
break;
//two cube intersections
case 2:
//get the two poly points
for(l=0; l<3; l++){
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
//get the two cube intersections
for(l = 0; l<3; l++){
dist = vm_vec_dist(&sdec->vert[poly_point[r-1]], &newpoint[l%3]);
//if this intersection point is closer than the other, use it as the next point
if((dist < vm_vec_dist(&sdec->vert[poly_point[r-1]], &newpoint[(l+1)%3])) ){
sdec->vert[dec_vert] = newpoint[l];
k = l;
}
}
poly_point[r++] = dec_vert++;
//the remaining point is next
sdec->vert[dec_vert] = newpoint[(k + 2)%3];
poly_point[r++] = dec_vert++;
break;
//one cube intersection
case 1:
for(l=0; l<3; l++){
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
sdec->vert[dec_vert] = newpoint[0];
poly_point[r++] = dec_vert++;
break;
//no cube intersections
case 0:
for(l=0; l<3; l++){
//this one and the next
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l+1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
//this one and the previus
if(decal_intersect_seg_with_cube(&sdec->vert[dec_vert], tdec.vert[tdec.poly[i].point[l]], tdec.vert[tdec.poly[i].point[(l-1)%3]], cube_point, point->orient)){
poly_point[r++] = dec_vert++;
}
}
break;
}
//then copy the triangulated version to the ship decal
//IT IS POSABLE THAT THERE IS NO INTERSECTION AT ALL
for(p = 1; p<(r-1); p++){
sdec->poly[sdec->n_poly].point[0] = poly_point[0];
sdec->poly[sdec->n_poly].point[p] = poly_point[p];
sdec->poly[sdec->n_poly].point[p+1] = poly_point[p+1];
sdec->n_poly++;
}
break;
}
}
for(i=0; in_poly; i++){
for(int k=0; k<3; k++){
sdec->poly[i].uv[k].u = 0.5f;
sdec->poly[i].uv[k].v = 0.5f;
}
}
sdec->texture = texture;
sdec->is_valid = 1;
sdec->timestamp = timestamp();
mprintf(("a decal should have been made with %d polys\n",sdec->n_poly));
return 1;
}
these are two subrouteens used by that
int decal_intersect_seg_with_cube(vector * poly_point, vector start, vector end, vector cube_point[8], matrix orient){
mprintf(("entering decal_intersect_seg_with_cube\n"));
//for each four sided face of the cube
vector *pointlist[4];
vector plnorm = orient.vec.fvec;
pointlist[0] = &cube_point[4];
pointlist[1] = &cube_point[6];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[0];
pointlist[1] = &cube_point[3];
pointlist[2] = &cube_point[1];
pointlist[3] = &cube_point[2];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vector veca;
vector vecb;
veca = orient.vec.uvec;
vecb = orient.vec.rvec;
vm_vec_negate(&veca);
vm_vec_avg(&plnorm, &veca, &vecb);
vm_vec_normalize(&plnorm);
pointlist[0] = &cube_point[2];
pointlist[1] = &cube_point[1];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[6];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[3];
pointlist[1] = &cube_point[0];
pointlist[2] = &cube_point[4];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
veca = orient.vec.uvec;
vecb = orient.vec.rvec;
vm_vec_avg(&plnorm, &veca, &vecb);
vm_vec_normalize(&plnorm);
pointlist[0] = &cube_point[2];
pointlist[1] = &cube_point[0];
pointlist[2] = &cube_point[4];
pointlist[3] = &cube_point[6];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[3];
pointlist[1] = &cube_point[1];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
mprintf(("leaveing decal_intersect_seg_with_cube\n"));
return 0;//it couldn't find any
}
int decal_intersect_poly_with_cube(vector * poly_point, vector point[3], vector cube_point[8], int ints){
mprintf(("entering decal_intersect_poly_with_cube\n"));
vector plnorm;
vector *pointlist[3];
for(int i = 0; i<3; i++)pointlist[i] = &point[i];
vm_vec_perp(&plnorm, &point[0], &point[1], &point[2]);
vector pnt1 = cube_point[0];
vector pnt2 = cube_point[2];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face, and this isn't the last one
return 1;//and if it is, then get out
pnt1 = cube_point[2];
pnt2 = cube_point[1];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[1];
pnt2 = cube_point[3];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[3];
pnt2 = cube_point[0];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[0];
pnt2 = cube_point[4];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[2];
pnt2 = cube_point[6];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[1];
pnt2 = cube_point[5];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[3];
pnt2 = cube_point[7];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[4];
pnt2 = cube_point[6];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[6];
pnt2 = cube_point[5];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[5];
pnt2 = cube_point[7];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[7];
pnt2 = cube_point[4];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
mprintf(("leaveing decal_intersect_poly_with_cube\n"));
return 0;
}
now this is the object interpeter I made, that sets a trianglulated version of all submodels into a specal polymodel format I have incerted into the submodel data type
int decal_intersect_seg_with_cube(vector * poly_point, vector start, vector end, vector cube_point[8], matrix orient){
mprintf(("entering decal_intersect_seg_with_cube\n"));
//for each four sided face of the cube
vector *pointlist[4];
vector plnorm = orient.vec.fvec;
pointlist[0] = &cube_point[4];
pointlist[1] = &cube_point[6];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[0];
pointlist[1] = &cube_point[3];
pointlist[2] = &cube_point[1];
pointlist[3] = &cube_point[2];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vector veca;
vector vecb;
veca = orient.vec.uvec;
vecb = orient.vec.rvec;
vm_vec_negate(&veca);
vm_vec_avg(&plnorm, &veca, &vecb);
vm_vec_normalize(&plnorm);
pointlist[0] = &cube_point[2];
pointlist[1] = &cube_point[1];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[6];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[3];
pointlist[1] = &cube_point[0];
pointlist[2] = &cube_point[4];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
veca = orient.vec.uvec;
vecb = orient.vec.rvec;
vm_vec_avg(&plnorm, &veca, &vecb);
vm_vec_normalize(&plnorm);
pointlist[0] = &cube_point[2];
pointlist[1] = &cube_point[0];
pointlist[2] = &cube_point[4];
pointlist[3] = &cube_point[6];
if(fvi_segment_plane(poly_point, &cube_point[0], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
vm_vec_negate(&plnorm);
pointlist[0] = &cube_point[3];
pointlist[1] = &cube_point[1];
pointlist[2] = &cube_point[5];
pointlist[3] = &cube_point[7];
if(fvi_segment_plane(poly_point, &cube_point[5], &plnorm, &start, &end, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 4, pointlist, &plnorm, NULL, NULL, NULL))//then see if it is on the face
return 1;//and if it is, then get out
mprintf(("leaveing decal_intersect_seg_with_cube\n"));
return 0;//it couldn't find any
}
int decal_intersect_poly_with_cube(vector * poly_point, vector point[3], vector cube_point[8], int ints){
mprintf(("entering decal_intersect_poly_with_cube\n"));
vector plnorm;
vector *pointlist[3];
for(int i = 0; i<3; i++)pointlist[i] = &point[i];
vm_vec_perp(&plnorm, &point[0], &point[1], &point[2]);
vector pnt1 = cube_point[0];
vector pnt2 = cube_point[2];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face, and this isn't the last one
return 1;//and if it is, then get out
pnt1 = cube_point[2];
pnt2 = cube_point[1];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[1];
pnt2 = cube_point[3];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[3];
pnt2 = cube_point[0];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[0];
pnt2 = cube_point[4];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[2];
pnt2 = cube_point[6];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[1];
pnt2 = cube_point[5];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[3];
pnt2 = cube_point[7];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[4];
pnt2 = cube_point[6];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[6];
pnt2 = cube_point[5];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[5];
pnt2 = cube_point[7];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
pnt1 = cube_point[7];
pnt2 = cube_point[4];
if(fvi_segment_plane(poly_point, &point[0], &plnorm, &pnt1, &pnt2, 0.0) == 1)//see if the segment intersecs the plane
if(fvi_point_face(poly_point, 3, pointlist, &plnorm, NULL, NULL, NULL) && (0 != ints--))//then see if it is on the face
return 1;//and if it is, then get out
mprintf(("leaveing decal_intersect_poly_with_cube\n"));
return 0;
}
and these are the current versions of the data types
typedef struct decal_model{ //this will store a triangulated version of the ships polygons
struct{
int point[3]; //an index to the vert list-Bobboau
vector center; //the center of the poly
float radius; //the max radius of the poly
}poly[800];
vector vert[1200]; //the defpoints-Bobboau
int n_polys;
}decal_model;
//extern decal_model d_model;
typedef struct decal{
struct{
uv_pair uv[3];
int point[3]; //an index to the vert list-Bobboau
}poly[MAX_DECAL_POLY];
vector vert[MAX_DECAL_POLY * 3]; //the defpoints-Bobboau
int texture;
int is_valid; //this means it is a good decal that should be rendered-Bobboau
int n_poly;
int timestamp; //is to start fadeing away-Bobboau
}decal;
typedef struct decal_point{
vector pnt;
matrix orient;
float radius;
}decal_point;
-
AIEE! Too much code! What does it all mean?
-
it means cliped decals, eventualy
though right now it means a crash as soon as any thing tries to read the data in the tdec (temporary decal model)
-
Originally posted by GalacticEmperor
AIEE! Too much code! What does it all mean?
And Bob wonders why nobody replies....
For the part I do understand.. Great work!...
As for The Day I am going to understand The Code, that wil be the day Volition's freespace 5 wil be going gold after i bought them out and put them to work on the freespace series
;)