Hello,
Please proof me wrong here. But a function like IsEntityVisible() is not possible to realize due to the nature of this engine. Well and don't get me started. The best solutions i found here deem these entitys
not to be visible:
Well, i can see 'em. Can you?
The answer why these solutions fail is simple: They are not checking the visibility of a model. They are in fact only checking the visibility of one single point. The entitys' origin. Give me a break... That's worthless...
TraceHull is out of the question, because our trace will end at the next wall. (right? no modifiers here)
Only thing we can do here is to approximate visibility. Huh approximate?
Well, we might just trace at every bone. This is pretty accurate and i did this. (uses up pretty much CPU time, :S )
Still, we are checking only single points. Theoretically there could be a wall with a tiny hole in it and behind that wall there is our enemy. We could be lookin at a body part which is not revealed by any bone point.
Another idea i had: (This pretty much fucked up CPU ressources)
I constructed this function to check visibility of a bounding box of an entity + single point of origin.
Code:
/* == fm_is_bbox_in_sight ==
* Determines if a bounding box of another entity is visible
* and not behind a wall for the given player index. This does not include
* a check if this bbox is in the viewcone of the player. So theoretically
* there could be a bbox of an entity directly behind us and this would return true,
*
H___________G
/| /|
/ | / |
E------------ F|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| |_D_____|__| C
| / | /
|/_________|/
A B
*/
stock bool:fm_is_bbox_in_sight(index, entity, bboxoffset)
{
new Float:origin[3], Float:view_ofs[3], Float:eyepos[3]
pev(index, pev_origin, origin)
pev(index, pev_view_ofs, view_ofs)
xs_vec_add(origin, view_ofs, eyepos)
new Float:mins[3]
new Float:maxs[3]
pev(entity, pev_absmin, mins)
pev(entity, pev_absmax, maxs)
mins[0] -= bboxoffset
mins[1] -= bboxoffset
mins[2] -= bboxoffset
maxs[0] += bboxoffset
maxs[1] += bboxoffset
maxs[2] += bboxoffset
new Float:boxEdges[8][3]
//A
boxEdges[0][0] = mins[0]
boxEdges[0][1] = mins[1]
boxEdges[0][2] = mins[2]
//B
boxEdges[1][0] = mins[0]
boxEdges[1][1] = mins[1] + (maxs[1] - mins[1])
boxEdges[1][2] = mins[2]
//C
boxEdges[2][0] = mins[0] + (maxs[0] - mins[0])
boxEdges[2][1] = mins[1] + (maxs[1] - mins[1])
boxEdges[2][2] = mins[2]
//D
boxEdges[3][0] = mins[0] + (maxs[0] - mins[0])
boxEdges[3][1] = mins[1]
boxEdges[3][2] = mins[2]
//E
boxEdges[4][0] = mins[0]
boxEdges[4][1] = mins[1]
boxEdges[4][2] = mins[2] + (maxs[2] - mins[2])
//F
boxEdges[5][0] = mins[0]
boxEdges[5][1] = mins[1] + (maxs[1] - mins[1])
boxEdges[5][2] = mins[2] + (maxs[2] - mins[2])
//G
boxEdges[6][0] = mins[0] + (maxs[0] - mins[0])
boxEdges[6][1] = mins[1] + (maxs[1] - mins[1])
boxEdges[6][2] = mins[2] + (maxs[2] - mins[2])
//H
boxEdges[7][0] = mins[0] + (maxs[0] - mins[0])
boxEdges[7][1] = mins[1]
boxEdges[7][2] = mins[2] + (maxs[2] - mins[2])
for(new i = 0; i < 8; i++)
{
engfunc(EngFunc_TraceLine, eyepos, boxEdges[i], 0, index)
new Float:fraction
global_get(glb_trace_fraction, fraction)
if (fraction == 1.0)
return true
}
new Float:entpos[3]
pev(entity, pev_origin, entpos)
engfunc(EngFunc_TraceLine, eyepos, entpos, 0, index)
switch (pev(entity, pev_solid)) {
case SOLID_BBOX..SOLID_BSP: return (global_get(glb_trace_ent) == entity)
}
new Float:fraction
global_get(glb_trace_fraction, fraction)
return (fraction == 1.0)
}
Now i am looping through this function with multiple bboxoffsets. (This Argument manipulates the magnitude of the bbox)
To visualize what i am checking:
Those are multiple scaled boxes overlayed. I am tracing every 8 edges of each box, to approximate visibility. It is damn accurate, depending on how many boxes i overlay. But it is also damn CPU Time consuming. So i am currently sticking with the bone-method. I also thought about looping through all hitboxes and applying my overlay-box method on each one.
But hitbox access isn't that easy, and it would be also way too CPU-consuming.
But what the hell do i want from you now?
I was just curious if there was a pro-solution from some AMXX-Aholics here.
Maybe even a solution that delivers irrefutable proof of visibility of a model. (based on the hitboxes is enough, not the actual mdl-surface)
Anyone?