AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   IsEntityVisible (https://forums.alliedmods.net/showthread.php?t=74780)

DeepBlueSea 07-24-2008 19:45

IsEntityVisible
 
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:

http://www.abload.de/img/halflife04dg4.jpg

http://www.abload.de/img/halflife05615.jpg

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:
http://www.abload.de/img/halflife07ae1.jpg

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?

Exolent[jNr] 07-24-2008 19:56

Re: IsEntityVisible
 
Are you speaking of fm_is_ent_visible() from fakemeta_util?

Code:
stock bool:fm_is_ent_visible(index, entity, ignoremonsters = 0) {     new Float:start[3], Float:dest[3]     pev(index, pev_origin, start)     pev(index, pev_view_ofs, dest)     xs_vec_add(start, dest, start)     pev(entity, pev_origin, dest)     engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0)     new Float:fraction     get_tr2(0, TR_flFraction, fraction)     if (fraction == 1.0 || get_tr2(0, TR_pHit) == entity)         return true     return false }

DeepBlueSea 07-24-2008 20:33

Re: IsEntityVisible
 
Quote:

Are you speaking of fm_is_ent_visible() from fakemeta_util?
Hell yes, i was speaking of this function.
It is completely worthless.

Alka 07-25-2008 03:18

Re: IsEntityVisible
 
You can try to make a loop and check around the player origin, like origin[1] + 5.0, origin[0] + 5.0 and so...practically should work.

Arkshine 07-25-2008 11:51

Re: IsEntityVisible
 
In 'fm_is_ent_visible()' , change fraction == 1.0 by fraction >= 0.9 and it will be almost perfect. :)

DeepBlueSea 07-25-2008 12:36

Re: IsEntityVisible
 
Almost perfect? There happen to be thick walls in this game...
http://www.abload.de/img/halflife10frw.jpg

Sorry for the pixelation. My Graphic-cards ram got kind of hot once.

Arkshine 07-25-2008 13:14

Re: IsEntityVisible
 
Sorry, I've read too fast your problem and what I've said can't help you. :o

Now I understand and I will try to think a bit more. :)

DeepBlueSea 07-25-2008 13:29

Re: IsEntityVisible
 
Don't be sorry. At least this got mentioned in this thread.
We can list all possible methods to detect visibility, and their pro and contras.

endeffects 12-23-2008 09:02

Re: IsEntityVisible
 
i have the same problem like you,
did you found a working solution?

Dores 12-23-2008 10:04

Re: IsEntityVisible
 
Try getting the aim origin, then check for all entities in a small sphere that it's center is the aiming origin, and then check fm_is_bbox_in_sight() (or fm_is_ent_visible()). If the functions return false and there's a player near the aiming origin, there's a player half-visible behind a wall.


All times are GMT -4. The time now is 05:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.