本文整理汇总了C++中DistanceSquared函数的典型用法代码示例。如果您正苦于以下问题:C++ DistanceSquared函数的具体用法?C++ DistanceSquared怎么用?C++ DistanceSquared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DistanceSquared函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AI_ValidateNoEnemyGroupMember
qboolean AI_ValidateNoEnemyGroupMember( AIGroupInfo_t *group, gentity_t *member )
{
if ( !group )
{
return qfalse;
}
vec3_t center;
if ( group->commander )
{
VectorCopy( group->commander->currentOrigin, center );
}
else
{//hmm, just pick the first member
if ( group->member[0].number < 0 || group->member[0].number >= ENTITYNUM_WORLD )
{
return qfalse;
}
VectorCopy( g_entities[group->member[0].number].currentOrigin, center );
}
//FIXME: maybe it should be based on the center of the mass of the group, not the commander?
if ( DistanceSquared( center, member->currentOrigin ) > 147456/*384*384*/ )
{
return qfalse;
}
if ( !gi.inPVS( member->currentOrigin, center ) )
{//not within PVS of the group enemy
return qfalse;
}
return qtrue;
}
示例2: S_Base_HearingThroughEntity
/*
=================
S_Base_HearingThroughEntity
Also see S_AL_HearingThroughEntity
=================
*/
static qboolean S_Base_HearingThroughEntity( int entityNum, const vec3_t origin )
{
float distanceSq;
vec3_t sorigin;
if (origin)
VectorCopy(origin, sorigin);
else
VectorCopy(loopSounds[entityNum].origin, sorigin);
if( listener_number == entityNum )
{
// This is an outrageous hack to detect
// whether or not the player is rendering in third person or not. We can't
// ask the renderer because the renderer has no notion of entities and we
// can't ask cgame since that would involve changing the API and hence mod
// compatibility. I don't think there is any way around this, but I'll leave
// the FIXME just in case anyone has a bright idea.
distanceSq = DistanceSquared(
sorigin,
listener_origin );
if( distanceSq > THIRD_PERSON_THRESHOLD_SQ )
return qfalse; //we're the player, but third person
else
return qtrue; //we're the player
}
else
return qfalse; //not the player
}
示例3: DistanceSquared
float CVector3::LengthSquared()
{
float result;
Vector3 thisV3 = { X, Y, Z };
DistanceSquared(thisV3, zero, result);
return result;
}
示例4: DistanceSquared
/*
===========
Team_GetLocation
Report a location for the player. Uses placed nearby target_location entities
============
*/
gentity_t *Team_GetLocation( gentity_t *ent )
{
gentity_t *eloc, *best;
float bestlen, len;
best = NULL;
bestlen = 3.0f * 8192.0f * 8192.0f;
for ( eloc = level.locationHead; eloc; eloc = eloc->nextPathSegment )
{
len = DistanceSquared( ent->r.currentOrigin, eloc->r.currentOrigin );
if ( len > bestlen )
{
continue;
}
if ( !trap_InPVS( ent->r.currentOrigin, eloc->r.currentOrigin ) )
{
continue;
}
bestlen = len;
best = eloc;
}
return best;
}
示例5: Rancor_Smash
void Rancor_Smash( void )
{
int radiusEntNums[128];
int numEnts;
const float radius = 128;
const float halfRadSquared = ((radius/2)*(radius/2));
const float radiusSquared = (radius*radius);
float distSq;
int i;
vec3_t boltOrg;
AddSoundEvent( NPC, NPC->r.currentOrigin, 512, AEL_DANGER, qfalse );//, qtrue );
numEnts = NPC_GetEntsNearBolt( radiusEntNums, radius, NPC->client->renderInfo.handLBolt, boltOrg );
for ( i = 0; i < numEnts; i++ )
{
gentity_t *radiusEnt = &g_entities[radiusEntNums[i]];
if ( !radiusEnt->inuse )
{
continue;
}
if ( radiusEnt == NPC )
{//Skip the rancor ent
continue;
}
if ( radiusEnt->client == NULL )
{//must be a client
continue;
}
if ( (radiusEnt->client->ps.eFlags2&EF2_HELD_BY_MONSTER) )
{//can't be one being held
continue;
}
distSq = DistanceSquared( radiusEnt->r.currentOrigin, boltOrg );
if ( distSq <= radiusSquared )
{
G_Sound( radiusEnt, CHAN_AUTO, G_SoundIndex( "sound/chars/rancor/swipehit.wav" ) );
if ( distSq < halfRadSquared )
{//close enough to do damage, too
G_Damage( radiusEnt, NPC, NPC, vec3_origin, radiusEnt->r.currentOrigin, Q_irand( 10, 25 ), DAMAGE_NO_ARMOR|DAMAGE_NO_KNOCKBACK, MOD_MELEE );
}
if ( radiusEnt->health > 0
&& radiusEnt->client
&& radiusEnt->client->NPC_class != CLASS_RANCOR
&& radiusEnt->client->NPC_class != CLASS_ATST )
{
if ( distSq < halfRadSquared
|| radiusEnt->client->ps.groundEntityNum != ENTITYNUM_NONE )
{//within range of my fist or withing ground-shaking range and not in the air
G_Knockdown( radiusEnt );//, NPC, vec3_origin, 100, qtrue );
}
}
}
}
}
示例6: NAVNEW_ResolveEntityCollision
qboolean NAVNEW_ResolveEntityCollision( gentity_t *self, gentity_t *blocker, vec3_t movedir, vec3_t pathDir, qboolean setBlockedInfo )
{
vec3_t blocked_dir;
float blocked_dist;
//Doors are ignored
if ( Q_stricmp( blocker->classname, "func_door" ) == 0 )
{
vec3_t center;
CalcTeamDoorCenter ( blocker, center );
if ( DistanceSquared( self->r.currentOrigin, center ) > MIN_DOOR_BLOCK_DIST_SQR )
return qtrue;
}
VectorSubtract( blocker->r.currentOrigin, self->r.currentOrigin, blocked_dir );
blocked_dist = VectorNormalize( blocked_dir );
//First, attempt to walk around the blocker or shove him out of the way
if ( NAVNEW_Bypass( self, blocker, blocked_dir, blocked_dist, movedir, setBlockedInfo ) )
return qtrue;
//Can't get around him... see if I'm blocking him too... if so, I need to just keep moving?
if ( NAVNEW_CheckDoubleBlock( self, blocker, blocked_dir ) )
return qtrue;
if ( setBlockedInfo )
{
//Complain about it if we can
NPC_SetBlocked( self, blocker );
}
return qfalse;
}
示例7: SVector2
SVector2 EvadeBehavior::Update(float deltaTime)
{
SVector2 returnForce = SVector2(0.0f, 0.0f);
if (mPreviousDestination != SVector2(-1.0f, -1.0f))
{
SVector2 targetVelocity = (mpAgent->GetDestination() - mPreviousDestination)/deltaTime;
float maxSpeed = mpAgent->GetMaxSpeed();
float distFromTarget = Length(mpAgent->GetDestination() - mpAgent->GetPosition());
float expectedTime = distFromTarget/maxSpeed;
mTargetDestination = mpAgent->GetDestination() + targetVelocity * expectedTime;
// FLEE
const float panicDistanceSq = maxSpeed * maxSpeed;
if (DistanceSquared(mpAgent->GetPosition(), mpAgent->GetDestination()) > panicDistanceSq)
{
return SVector2( 0, 0);
}
SVector2 positionToDestination = mpAgent->GetPosition() - mTargetDestination;
SVector2 desiredVelocity = Normalize(positionToDestination) * mpAgent->GetMaxSpeed();
returnForce = desiredVelocity - mpAgent->GetVelocity();
}
mPreviousDestination = mpAgent->GetDestination();
return returnForce;
}
示例8: G_CheckSightEvents
/*
-------------------------
NPC_CheckSightEvents
-------------------------
*/
static int G_CheckSightEvents( gentity_t *self, int hFOV, int vFOV, float maxSeeDist, int ignoreAlert, qboolean mustHaveOwner, int minAlertLevel )
{
int bestEvent = -1;
int bestAlert = -1;
int bestTime = -1;
float dist, radius;
maxSeeDist *= maxSeeDist;
for ( int i = 0; i < level.numAlertEvents; i++ )
{
//are we purposely ignoring this alert?
if ( i == ignoreAlert )
continue;
//We're only concerned about sounds
if ( level.alertEvents[i].type != AET_SIGHT )
continue;
//must be at least this noticable
if ( level.alertEvents[i].level < minAlertLevel )
continue;
//must have an owner?
if ( mustHaveOwner && !level.alertEvents[i].owner )
continue;
//Must be within range
dist = DistanceSquared( level.alertEvents[i].position, self->currentOrigin );
//can't see it
if ( dist > maxSeeDist )
continue;
radius = level.alertEvents[i].radius * level.alertEvents[i].radius;
if ( dist > radius )
continue;
//Must be visible
if ( InFOV( level.alertEvents[i].position, self, hFOV, vFOV ) == qfalse )
continue;
if ( G_ClearLOS( self, level.alertEvents[i].position ) == qfalse )
continue;
//FIXME: possibly have the light level at this point affect the
// visibility/alert level of this event? Would also
// need to take into account how bright the event
// itself is. A lightsaber would stand out more
// in the dark... maybe pass in a light level that
// is added to the actual light level at this position?
//See if this one takes precedence over the previous one
if ( level.alertEvents[i].level >= bestAlert //higher alert level
|| (level.alertEvents[i].level==bestAlert&&level.alertEvents[i].timestamp >= bestTime) )//same alert level, but this one is newer
{//NOTE: equal is better because it's later in the array
bestEvent = i;
bestAlert = level.alertEvents[i].level;
bestTime = level.alertEvents[i].timestamp;
}
}
return bestEvent;
}
示例9: Rancor_Bite
void Rancor_Bite( void )
{
int radiusEntNums[128];
int numEnts;
const float radius = 100;
const float radiusSquared = (radius*radius);
int i;
vec3_t boltOrg;
numEnts = NPC_GetEntsNearBolt( radiusEntNums, radius, NPC->client->renderInfo.crotchBolt, boltOrg );//was gutBolt?
for ( i = 0; i < numEnts; i++ )
{
gentity_t *radiusEnt = &g_entities[radiusEntNums[i]];
if ( !radiusEnt->inuse )
{
continue;
}
if ( radiusEnt == NPC )
{//Skip the rancor ent
continue;
}
if ( radiusEnt->client == NULL )
{//must be a client
continue;
}
if ( (radiusEnt->client->ps.eFlags2&EF2_HELD_BY_MONSTER) )
{//can't be one already being held
continue;
}
if ( DistanceSquared( radiusEnt->r.currentOrigin, boltOrg ) <= radiusSquared )
{
G_Damage( radiusEnt, NPC, NPC, vec3_origin, radiusEnt->r.currentOrigin, Q_irand( 15, 30 ), DAMAGE_NO_ARMOR|DAMAGE_NO_KNOCKBACK, MOD_MELEE );
if ( radiusEnt->health <= 0 && radiusEnt->client )
{//killed them, chance of dismembering
if ( !Q_irand( 0, 1 ) )
{//bite something off
int hitLoc = Q_irand( G2_MODELPART_HEAD, G2_MODELPART_RLEG );
if ( hitLoc == G2_MODELPART_HEAD )
{
NPC_SetAnim( radiusEnt, SETANIM_BOTH, BOTH_DEATH17, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD );
}
else if ( hitLoc == G2_MODELPART_WAIST )
{
NPC_SetAnim( radiusEnt, SETANIM_BOTH, BOTH_DEATHBACKWARD2, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD );
}
//radiusEnt->client->dismembered = qfalse;
//FIXME: the limb should just disappear, cuz I ate it
G_Dismember( radiusEnt, NPC, radiusEnt->r.currentOrigin, hitLoc, 90, 0, radiusEnt->client->ps.torsoAnim, qtrue);
//G_DoDismemberment( radiusEnt, radiusEnt->r.currentOrigin, MOD_SABER, 1000, hitLoc, qtrue );
}
}
G_Sound( radiusEnt, CHAN_AUTO, G_SoundIndex( "sound/chars/rancor/chomp.wav" ) );
}
}
}
示例10: SetFarClip
/*
** SetFarClip
*/
static void SetFarClip( void )
{
float farthestCornerDistance = 0;
int i;
// if not rendering the world (icons, menus, etc)
// set a 2k far clip plane
if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
tr.viewParms.zFar = 2048;
return;
}
//
// set far clipping planes dynamically
//
for ( i = 0; i < 8; i++ )
{
vec3_t v;
float distance;
if ( i & 1 )
{
v[0] = tr.viewParms.visBounds[0][0];
}
else
{
v[0] = tr.viewParms.visBounds[1][0];
}
if ( i & 2 )
{
v[1] = tr.viewParms.visBounds[0][1];
}
else
{
v[1] = tr.viewParms.visBounds[1][1];
}
if ( i & 4 )
{
v[2] = tr.viewParms.visBounds[0][2];
}
else
{
v[2] = tr.viewParms.visBounds[1][2];
}
distance = DistanceSquared(tr.viewParms.or.origin, v);
if ( distance > farthestCornerDistance )
{
farthestCornerDistance = distance;
}
}
// Bring in the zFar to the distanceCull distance
// The sky renders at zFar so need to move it out a little
// ...and make sure there is a minimum zfar to prevent problems
tr.viewParms.zFar = Com_Clamp(2048.0f, tr.distanceCull * (1.732), sqrtf( farthestCornerDistance ));
}
示例11: Normalize
LightInfo ProjectionLight::Sample_L(const Point &p, float pEpsilon,
const LightSample &ls, float time) const {
auto wi = Normalize(lightPos - p);
VisibilityTester visibility;
visibility.SetSegment(p, pEpsilon, lightPos, 0., time);
auto L = Intensity * Projection(-wi) / DistanceSquared(lightPos, p);
return LightInfo{L,wi,1.f,visibility};
}
示例12: while
/*
================
G_SelectSpawnBuildable
find the nearest buildable of the right type that is
spawned/healthy/unblocked etc.
================
*/
static gentity_t *G_SelectSpawnBuildable( vec3_t preference, buildable_t buildable )
{
gentity_t *search = nullptr;
gentity_t *spot = nullptr;
while ( ( search = G_IterateEntitiesOfClass( search, BG_Buildable( buildable )->entityName ) ) != nullptr )
{
if ( !search->spawned )
{
continue;
}
if ( G_Dead( search ) )
{
continue;
}
if ( search->s.groundEntityNum == ENTITYNUM_NONE )
{
continue;
}
if ( search->clientSpawnTime > 0 )
{
continue;
}
Entity* blocker = nullptr;
Vec3 spawnPoint;
search->entity->CheckSpawnPoint(blocker, spawnPoint);
if (blocker)
{
continue;
}
if ( !spot || DistanceSquared( preference, search->s.origin ) <
DistanceSquared( preference, spot->s.origin ) )
{
spot = search;
}
}
return spot;
}
示例13: Scale
Spectrum GonioPhotometricLight::Sample_L(const Point &P, float u1, float u2,
Vector *wo, float *pdf,
VisibilityTester *visibility) const {
*wo = Normalize(lightPos - P);
*pdf = 1.f;
visibility->SetSegment(P, lightPos);
return Intensity * Scale(-*wo) / DistanceSquared(lightPos, P);
}
示例14: Falloff
Spectrum SpotLight::Sample_Li(const Interaction &ref, const Point2f &u,
Vector3f *wi, Float *pdf,
VisibilityTester *vis) const {
*wi = Normalize(pLight - ref.p);
*pdf = 1.f;
*vis = VisibilityTester(ref, Interaction(pLight, ref.time, medium));
return intensity * Falloff(-*wi) / DistanceSquared(pLight, ref.p);
}
示例15: DistanceSquared
void Bot::CheckAlertSpots(const StaticVector<edict_t *, MAX_CLIENTS> &visibleTargets)
{
float scores[MAX_ALERT_SPOTS];
// First compute scores (good for instruction cache)
for (unsigned i = 0; i < alertSpots.size(); ++i)
{
float score = 0.0f;
const auto &alertSpot = alertSpots[i];
const float squareRadius = alertSpot.radius * alertSpot.radius;
const float invRadius = 1.0f / alertSpot.radius;
for (const edict_t *ent: visibleTargets)
{
float squareDistance = DistanceSquared(ent->s.origin, alertSpot.origin.Data());
if (squareDistance > squareRadius)
continue;
float distance = Q_RSqrt(squareDistance + 0.001f);
score += 1.0f - distance * invRadius;
// Put likely case first
if (!(ent->s.effects & EF_CARRIER))
score *= alertSpot.regularEnemyInfluenceScale;
else
score *= alertSpot.carrierEnemyInfluenceScale;
}
// Clamp score by a max value
clamp_high(score, 3.0f);
// Convert score to [0, 1] range
score /= 3.0f;
// Get a square root of score (values closer to 0 gets scaled more than ones closer to 1)
score = 1.0f / Q_RSqrt(score + 0.001f);
// Sanitize
clamp(score, 0.0f, 1.0f);
scores[i] = score;
}
// Then call callbacks
const unsigned levelTime = level.time;
for (unsigned i = 0; i < alertSpots.size(); ++i)
{
auto &alertSpot = alertSpots[i];
unsigned nonReportedFor = levelTime - alertSpot.lastReportedAt;
if (nonReportedFor >= 1000)
alertSpot.lastReportedScore = 0.0f;
// Since scores are sanitized, they are in range [0.0f, 1.0f], and abs(scoreDelta) is in range [-1.0f, 1.0f];
float scoreDelta = scores[i] - alertSpot.lastReportedScore;
if (scoreDelta >= 0)
{
if (nonReportedFor >= 1000 - scoreDelta * 500)
alertSpot.Alert(this, scores[i]);
}
else
{
if (nonReportedFor >= 500 - scoreDelta * 500)
alertSpot.Alert(this, scores[i]);
}
}
}