Added extra param to is_in_viewcone to switch between a 2D and 3D calculation

Neither is still as accurate as I want them to be though :\
This commit is contained in:
Scott Ehlert 2006-10-01 06:08:39 +00:00
parent 90f11b52bc
commit 39d5ea94fb
2 changed files with 26 additions and 13 deletions

View File

@ -798,31 +798,42 @@ static cell AMX_NATIVE_CALL in_view_cone(AMX *amx, cell *params)
CHECK_ENTITY(src);
Vector vecLOS;
edict_t *pEdictSrc = INDEXENT(src);
Vector vecLOS, vecForward;
float flDot;
edict_t *pEdictSrc = INDEXENT(src);
cell *addr = MF_GetAmxAddr(amx, params[2]);
float vecOrigin[3];
Vector origin(amx_ctof(addr[0]), amx_ctof(addr[1]), amx_ctof(addr[2]));
vecOrigin[0] = amx_ctof(addr[0]);
vecOrigin[1] = amx_ctof(addr[1]);
vecOrigin[2] = amx_ctof(addr[2]);
bool use2D = (params[0] / sizeof(cell)) == 2 || params[3] == 0;
Vector origin(vecOrigin[0], vecOrigin[1], vecOrigin[2]);
if (use2D)
{
MAKE_VECTORS(pEdictSrc->v.angles);
vecForward = gpGlobals->v_forward;
vecLOS = origin - pEdictSrc->v.origin;
vecForward.z = 0;
vecLOS.z = 0;
}
else
{
MAKE_VECTORS(pEdictSrc->v.v_angle);
vecForward = gpGlobals->v_forward;
vecLOS = origin - (pEdictSrc->v.origin + pEdictSrc->v.view_ofs);
}
vecLOS = vecLOS.Normalize();
flDot = DotProduct(vecLOS, gpGlobals->v_forward);
flDot = DotProduct(vecLOS, vecForward);
if (flDot >= cos(pEdictSrc->v.fov * (M_PI / 360)))
return 1;
else
return 0;
}
static cell AMX_NATIVE_CALL traceresult(AMX *amx, cell *params)

View File

@ -226,8 +226,10 @@ forward pfn_spawn(entid);
*/
native find_sphere_class(aroundent, _lookforclassname[], Float:radius, entlist[], maxents, Float:origin[3] = {0.0, 0.0, 0.0});
//SDK function - checks if an origin is in an entity's view cone
native is_in_viewcone(entity, Float:origin[3]);
/* SDK function - checks if an origin is in an entity's view cone
* Set use3d to 1 to do the calculation in 3D. Otherwise it will be in 2D.
*/
native is_in_viewcone(entity, Float:origin[3], use3d = 0);
//SDK function - checks if an entity is visible to an entity
native is_visible(entity, target);