回复: 再回答我这个问题少年一下,如何判断2人之间障碍物
Post by jim_yang你可以看看这个帖子
http://forums.alliedmods.net/showthread.php?t=74780&highlight=visible
好像跟我问的问题差不多,看不懂英文,是不是也没办法解决?
回复: 再回答我这个问题少年一下,如何判断2人之间障碍物
bool FBoxVisible (edict_t *pEdict, edict_t *pTargetEdict, Vector *pvHit, unsigned char *ucBodyPart) // KWo - 24.02.2008 - rewritten...
{
int i;
int RenderFx; // KWo - 22.03.2008
int RenderMode; // KWo - 22.03.2008
Vector RenderColor; // KWo - 22.03.2008
float RenderAmount; // KWo - 22.03.2008
float LightLevel; // KWo - 23.03.2008
bool SemiTransparent = false; // KWo - 22.03.2008
*ucBodyPart = 0;
Vector vecEnDirection = pTargetEdict->v.angles;
// don't look through water
if (((pEdict->v.waterlevel != 3) && (pTargetEdict->v.waterlevel == 3))
|| ((pEdict->v.waterlevel == 3) && (pTargetEdict->v.waterlevel == 0)))
return (FALSE);
// KWo - 22.03.2008 - added invisibility check
RenderFx = pTargetEdict->v.renderfx;
RenderMode = pTargetEdict->v.rendermode;
RenderColor = pTargetEdict->v.rendercolor;
RenderAmount = pTargetEdict->v.renderamt;
if (((RenderFx == kRenderFxExplode) || (pTargetEdict->v.effects & EF_NODRAW))
&& !(pTargetEdict->v.oldbuttons & IN_ATTACK)) // kRenderFxExplode is always invisible even for mode kRenderNormal
{
return (FALSE);
}
else if (((RenderFx == kRenderFxExplode) || (pTargetEdict->v.effects & EF_NODRAW))
&& (pTargetEdict->v.oldbuttons & IN_ATTACK))
{
SemiTransparent = true;
}
else if ((RenderFx != kRenderFxHologram) && (RenderMode != kRenderNormal)) // kRenderFxHologram is always visible no matter what is the mode
{
if (RenderFx == kRenderFxGlowShell)
{
if ((RenderAmount <= 20.0) && (RenderColor.x <= 20)
&& (RenderColor.y <= 20) && (RenderColor.z <= 20))
{
if (!(pTargetEdict->v.oldbuttons & IN_ATTACK))
{
return (FALSE);
}
else
{
SemiTransparent = true;
}
}
else if ((RenderAmount <= 60.0) && (RenderColor.x <= 60)
&& (RenderColor.y <= 60) && (RenderColor.z <= 60))
{
SemiTransparent = true;
}
}
else
{
if (RenderAmount <= 20)
{
if (!(pTargetEdict->v.oldbuttons & IN_ATTACK))
{
return (FALSE);
}
else
{
SemiTransparent = true;
}
}
else if (RenderAmount <= 60)
{
SemiTransparent = true;
}
}
}
// KWo - 26.03.2008 - added darkness check
LightLevel = UTIL_IlluminationOf(pTargetEdict);
// ALERT(at_logged," Bot %s checks the illumination of %s. It's = %f.\n",
// STRING(pEdict->v.netname), STRING(pTargetEdict->v.netname), LightLevel);
if ((LightLevel < 3.0) && (!(pTargetEdict->v.effects & EF_DIMLIGHT)) /* && (!g_bIsOldCS15) */ && !(pTargetEdict->v.oldbuttons & IN_ATTACK))
{
return (FALSE);
}
else if (((LightLevel < 10.0) || (pTargetEdict->v.oldbuttons & IN_ATTACK)) && (!(pTargetEdict->v.effects & EF_DIMLIGHT)) /* && (!g_bIsOldCS15) */)
{
SemiTransparent = true; // in this case we can notice the enemy, but not so good...
}
TraceResult tr;
Vector vecLookerOrigin = GetGunPosition (pEdict);
Vector vecTarget = pTargetEdict->v.origin;
// Check direct Line to waist
UTIL_TraceLine (vecLookerOrigin, vecTarget, ignore_monsters, ignore_glass, pEdict, &tr);
if (tr.flFraction == 1.0)
{
*pvHit = tr.vecEndPos;
*ucBodyPart |= WAIST_VISIBLE;
}
MAKE_VECTORS (vecEnDirection);
// Check direct Line to head
vecTarget = vecTarget + pTargetEdict->v.view_ofs + Vector(0.0, 0.0, 3.0);
UTIL_TraceLine (vecLookerOrigin, vecTarget, ignore_monsters, ignore_glass, pEdict, &tr);
if ((tr.flFraction == 1.0) && (!SemiTransparent)) // if the player is rendered, his head cannot be good seen...
{
*pvHit = tr.vecEndPos;
*ucBodyPart |= HEAD_VISIBLE;
}
if (*ucBodyPart != 0)
return (TRUE);
// Nothing visible - check randomly other Parts of Body
for (i = 0; i < 6; i++)
{
vecTarget = pTargetEdict->v.origin;
switch(i)
{
case 0: // left arm
{
vecTarget.x -= 10.0 * gpGlobals->v_right.x;
vecTarget.y -= 10.0 * gpGlobals->v_right.y;
vecTarget.z += 8.0;
break;
}
case 1: // right arm
{
vecTarget.x += 10.0 * gpGlobals->v_right.x;
vecTarget.y += 10.0 * gpGlobals->v_right.y;
vecTarget.z += 8.0;
break;
}
case 2: // left leg
{
vecTarget.x -= 10.0 * gpGlobals->v_right.x;
vecTarget.y -= 10.0 * gpGlobals->v_right.y;
vecTarget.z -= 12.0;
break;
}
case 3: // right leg
{
vecTarget.x += 10.0 * gpGlobals->v_right.x;
vecTarget.y += 10.0 * gpGlobals->v_right.y;
vecTarget.z -= 12.0;
break;
}
case 4: // left foot
{
vecTarget.x -= 10.0 * gpGlobals->v_right.x;
vecTarget.y -= 10.0 * gpGlobals->v_right.y;
vecTarget.z -= 24.0;
break;
}
case 5: // right foot
{
vecTarget.x += 10.0 * gpGlobals->v_right.x;
vecTarget.y += 10.0 * gpGlobals->v_right.y;
vecTarget.z -= 24.0;
break;
}
}
/*
vecTarget.x += RANDOM_FLOAT (pTargetEdict->v.mins.x, pTargetEdict->v.maxs.x);
vecTarget.y += RANDOM_FLOAT (pTargetEdict->v.mins.y, pTargetEdict->v.maxs.y);
vecTarget.z += RANDOM_FLOAT (pTargetEdict->v.mins.z, pTargetEdict->v.maxs.z);
*/
UTIL_TraceLine (vecLookerOrigin, vecTarget, dont_ignore_monsters, ignore_glass, pEdict, &tr);
if ((tr.flFraction <= 1.0) && (tr.pHit == pTargetEdict))
{
// Return seen position
*pvHit = tr.vecEndPos;
*ucBodyPart |= CUSTOM_VISIBLE;
return (TRUE);
}
}
return (FALSE);
}
这个是机器人如何判断是否能够看见另一个人,仅供参考
回复: 再回答我这个问题少年一下,如何判断2人之间障碍物
再次感谢,我等一下回家后慢慢来消化。。。。回复: 再回答我这个问题少年一下,如何判断2人之间障碍物
http://www.dt-club.net/forum/showthread.php?t=27513看这个帖子.
页:
1
[2]