by Spike » Thu Mar 19, 2009 4:45 pm
qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
so:
{
trace_t tr;
vec3_t endpos;
memset(&tr, 0, sizeof(tr));
tr.fraction = 1;
VectorMA(p->origin, frametime, p->vel, endpos);
VectorCopy(endpos, tr.endpos);
SV_RecursiveHullCheck(&cl.worldmodel->hulls[0], 0, 0, 1, p->origin, endpos, &tr);
VectorCopy(tr.endpos, p->origin);
if (tr.fraction != 1)
{
float f = DotProduct(vel*tr.plane_normal)*-2;//bounce like a super-bouncy ball.
VectorMA(p->vel, f, tr.plane_normal, p->vel);
}
}
Insert the above code instead of the following line:
VectorMA(p->origin, frametime, p->vel, p->origin);
Then it'll clip particles to the world.
notes:
sv_recursivehullcheck is a generic function provided inside the server code. the 0,0,1 parameters are needed due to its recursive nature, but should be set as above for starting at the top of the bsp tree.
the passed in trace_t structure needs to be pre-initialised. Really its only the values you want set if it should fail to hit anything. This being fraction, solidity, and endpos.
If the trace starts solid, endpos will not be changed. This means the particle will pass through solids still, but only if the trace started in a solid. This gives some protection against moving BSP objects.
hull 0 is the point-sized/infinity-small hull. The next smallest is too big.
It'll not clip to doors/moving plats/func_wall.
For that you'd need to iterate over the visentities list for bsp models, and pick whichever trace gave the smallest fractions.
CL_LinkEntities will give you hits here, but I'm not gonna discuss it in detail cos I don't remember the contents of that array or even the actual name of it.
The above code will probably not even compile. Certainly it'll have undeclared functions.
Regarding oriented decals... Which texture are you going to use? :)
.