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