本文整理汇总了C++中VectorNormalizeFast函数的典型用法代码示例。如果您正苦于以下问题:C++ VectorNormalizeFast函数的具体用法?C++ VectorNormalizeFast怎么用?C++ VectorNormalizeFast使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VectorNormalizeFast函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CG_RainParticleGenerate
/**
* @brief Generate rain particle
* @details Attempt to 'spot' a raindrop somewhere below a sky texture.
*/
static qboolean CG_RainParticleGenerate(cg_atmosphericParticle_t *particle, vec3_t currvec, float currweight)
{
float angle = random() * 2 * M_PI, distance = 20 + MAX_ATMOSPHERIC_DISTANCE * random();
float groundHeight, skyHeight;
particle->pos[0] = cg.refdef_current->vieworg[0] + sin(angle) * distance;
particle->pos[1] = cg.refdef_current->vieworg[1] + cos(angle) * distance;
// choose a spawn point randomly between sky and ground
skyHeight = BG_GetSkyHeightAtPoint(particle->pos);
if (skyHeight >= MAX_ATMOSPHERIC_HEIGHT)
{
return qfalse;
}
groundHeight = BG_GetSkyGroundHeightAtPoint(particle->pos);
if (groundHeight + particle->height + ATMOSPHERIC_PARTICLE_OFFSET >= skyHeight)
{
return qfalse;
}
particle->pos[2] = groundHeight + random() * (skyHeight - groundHeight);
// make sure it doesn't fall from too far cause it then will go over our heads ('lower the ceiling')
if (cg_atmFx.baseHeightOffset > 0)
{
if (particle->pos[2] - cg.refdef_current->vieworg[2] > cg_atmFx.baseHeightOffset)
{
particle->pos[2] = cg.refdef_current->vieworg[2] + cg_atmFx.baseHeightOffset;
if (particle->pos[2] < groundHeight)
{
return qfalse;
}
}
}
// rain goes in bursts - allow max raindrops every 10 seconds
if (cg_atmFx.oldDropsActive > (0.50 * cg_atmFx.numDrops + 0.001 * cg_atmFx.numDrops * (10000 - (cg.time % 10000))))
{
return qfalse;
}
CG_SetParticleActive(particle, ACT_FALLING);
particle->colour[0] = 0.6 + 0.2 * random() * 0xFF;
particle->colour[1] = 0.6 + 0.2 * random() * 0xFF;
particle->colour[2] = 0.6 + 0.2 * random() * 0xFF;
VectorCopy(currvec, particle->delta);
particle->delta[2] += crandom() * 100;
VectorCopy(particle->delta, particle->deltaNormalized);
VectorNormalizeFast(particle->deltaNormalized);
particle->height = ATMOSPHERIC_RAIN_HEIGHT + crandom() * 100;
particle->weight = currweight;
particle->effectshader = &cg_atmFx.effectshaders[0];
//particle->effectshader = &cg_atmFx.effectshaders[ (int) (random() * ( cg_atmFx.numEffectShaders - 1 )) ];
return qtrue;
}
示例2: CG_BladeImpact
/*
* CG_BladeImpact
*/
void CG_BladeImpact( vec3_t pos, vec3_t dir )
{
lentity_t *le;
vec3_t angles;
vec3_t end;
trace_t trace;
//find what are we hitting
VectorNormalizeFast( dir );
VectorMA( pos, -1.0, dir, end );
CG_Trace( &trace, pos, vec3_origin, vec3_origin, end, cg.view.POVent, MASK_SHOT );
if( trace.fraction == 1.0 )
return;
VecToAngles( dir, angles );
if( trace.surfFlags & SURF_FLESH ||
( trace.ent > 0 && cg_entities[trace.ent].current.type == ET_PLAYER )
|| ( trace.ent > 0 && cg_entities[trace.ent].current.type == ET_CORPSE ) )
{
le = CG_AllocModel( LE_ALPHA_FADE, pos, angles, 3, //3 frames for weak
1, 1, 1, 1, //full white no inducted alpha
0, 0, 0, 0, //dlight
CG_MediaModel( cgs.media.modBladeWallHit ), NULL );
le->ent.rotation = rand() % 360;
le->ent.scale = 1.0f;
trap_S_StartFixedSound( CG_MediaSfx( cgs.media.sfxBladeFleshHit[(int)( random()*3 )] ), pos, CHAN_AUTO,
cg_volume_effects->value, ATTN_NORM );
}
else if( trace.surfFlags & SURF_DUST )
{
// throw particles on dust
CG_ParticleEffect( trace.endpos, trace.plane.normal, 0.30f, 0.30f, 0.25f, 30 );
//fixme? would need a dust sound
trap_S_StartFixedSound( CG_MediaSfx( cgs.media.sfxBladeWallHit[(int)( random()*2 )] ), pos, CHAN_AUTO,
cg_volume_effects->value, ATTN_NORM );
}
else
{
le = CG_AllocModel( LE_ALPHA_FADE, pos, angles, 3, //3 frames for weak
1, 1, 1, 1, //full white no inducted alpha
0, 0, 0, 0, //dlight
CG_MediaModel( cgs.media.modBladeWallHit ), NULL );
le->ent.rotation = rand() % 360;
le->ent.scale = 1.0f;
CG_ParticleEffect( trace.endpos, trace.plane.normal, 0.30f, 0.30f, 0.25f, 15 );
trap_S_StartFixedSound( CG_MediaSfx( cgs.media.sfxBladeWallHit[(int)( random()*2 )] ), pos, CHAN_AUTO,
cg_volume_effects->value, ATTN_NORM );
if( !( trace.surfFlags & SURF_NOMARKS ) )
CG_SpawnDecal( pos, dir, random()*360, 8, 1, 1, 1, 1, 10, 1, qfalse, CG_MediaShader( cgs.media.shaderBulletMark ) );
}
}
示例3: AI_infront2D
qboolean AI_infront2D( vec3_t lookDir, vec3_t origin, vec3_t point, float accuracy )
{
vec3_t vec;
float dot;
vec3_t origin2D, point2D, lookDir2D;
VectorSet( origin2D, origin[0], origin[1], 0 );
VectorSet( point2D, point[0], point[1], 0 );
VectorSet( lookDir2D, lookDir[0], lookDir[1], 0 );
VectorNormalizeFast( lookDir2D );
VectorSubtract( point2D, origin2D, vec );
VectorNormalizeFast( vec );
dot = DotProduct( vec, lookDir2D );
clamp( accuracy, -1, 1 );
return ( dot > accuracy );
}
示例4: vector_NormalizeFast
static int vector_NormalizeFast(lua_State * L)
{
vec_t *a;
a = lua_getvector(L, 1);
VectorNormalizeFast(a);
return 1;
}
示例5: R_StageTexCoord
/**
* @brief Generates a single texture coordinate for the specified stage and vertex.
*/
static void R_StageTexCoord (const materialStage_t *stage, const vec3_t v, const vec2_t in, vec2_t out)
{
if (stage->flags & STAGE_ENVMAP) { /* generate texcoords */
vec3_t tmp;
VectorSubtract(v, refdef.viewOrigin, tmp);
VectorNormalizeFast(tmp);
Vector2Copy(tmp, out);
} else { /* or use the ones we were given */
Vector2Copy(in, out);
}
}
示例6: PerpendicularVector
void PerpendicularVector(vec3_t dst, const vec3_t src) {
if (!src[0]) {
VectorSet(dst, 1, 0, 0);
} else if (!src[1]) {
VectorSet(dst, 0, 1, 0);
} else if (!src[2]) {
VectorSet(dst, 0, 0, 1);
} else {
VectorSet(dst, -src[1], src[0], 0);
VectorNormalizeFast(dst);
}
}
示例7: CG_SnowParticleGenerate
/**
* @brief Generate a snowflake
* @details Attempt to 'spot' a snowflake somewhere below a sky texture.
*/
static qboolean CG_SnowParticleGenerate(cg_atmosphericParticle_t *particle, vec3_t currvec, float currweight)
{
float angle = random() * 2 * M_PI, distance = 20 + MAX_ATMOSPHERIC_DISTANCE * random();
float groundHeight, skyHeight;
particle->pos[0] = cg.refdef_current->vieworg[0] + sin(angle) * distance;
particle->pos[1] = cg.refdef_current->vieworg[1] + cos(angle) * distance;
// choose a spawn point randomly between sky and ground
skyHeight = BG_GetSkyHeightAtPoint(particle->pos);
if (skyHeight >= MAX_ATMOSPHERIC_HEIGHT)
{
return qfalse;
}
groundHeight = BG_GetSkyGroundHeightAtPoint(particle->pos);
if (groundHeight + particle->height + ATMOSPHERIC_PARTICLE_OFFSET >= skyHeight)
{
return qfalse;
}
particle->pos[2] = groundHeight + random() * (skyHeight - groundHeight);
// make sure it doesn't fall from too far cause it then will go over our heads ('lower the ceiling')
if (cg_atmFx.baseHeightOffset > 0)
{
if (particle->pos[2] - cg.refdef_current->vieworg[2] > cg_atmFx.baseHeightOffset)
{
particle->pos[2] = cg.refdef_current->vieworg[2] + cg_atmFx.baseHeightOffset;
if (particle->pos[2] < groundHeight)
{
return qfalse;
}
}
}
CG_SetParticleActive(particle, ACT_FALLING);
VectorCopy(currvec, particle->delta);
particle->delta[2] += crandom() * 25;
VectorCopy(particle->delta, particle->deltaNormalized);
VectorNormalizeFast(particle->deltaNormalized);
particle->height = ATMOSPHERIC_SNOW_HEIGHT + random() * 2;
particle->weight = particle->height * 0.5f;
particle->effectshader = &cg_atmFx.effectshaders[0];
//particle->effectshader = &cg_atmFx.effectshaders[ (int) (random() * ( cg_atmFx.numEffectShaders - 1 )) ];
return qtrue;
}
示例8: VelocityForDamage
static void VelocityForDamage( int damage, vec3_t v )
{
v[0] = 10.0 * crandom();
v[1] = 10.0 * crandom();
v[2] = 20.0 + 10.0 * random();
VectorNormalizeFast( v );
if( damage < 50 )
VectorScale( v, 0.7, v );
else
VectorScale( v, 1.2, v );
}
示例9: CG_Event_Jump
/*
* CG_Event_Jump
*/
void CG_Event_Jump( entity_state_t *state, int parm )
{
#define MOVEDIREPSILON 0.25f
centity_t *cent;
int xyspeedcheck;
cent = &cg_entities[state->number];
xyspeedcheck = SQRTFAST( cent->animVelocity[0]*cent->animVelocity[0] + cent->animVelocity[1]*cent->animVelocity[1] );
if( xyspeedcheck < 100 )
{ // the player is jumping on the same place, not running
CG_PModel_AddAnimation( state->number, LEGS_JUMP_NEUTRAL, 0, 0, EVENT_CHANNEL );
CG_SexedSound( state->number, CHAN_BODY, va( S_PLAYER_JUMP_1_to_2, ( rand()&1 )+1 ), cg_volume_players->value );
}
else
{
vec3_t movedir, viewaxis[3];
movedir[0] = cent->animVelocity[0];
movedir[1] = cent->animVelocity[1];
movedir[2] = 0;
VectorNormalizeFast( movedir );
AngleVectors( tv( 0, cent->current.angles[YAW], 0 ), viewaxis[FORWARD], viewaxis[RIGHT], viewaxis[UP] );
// see what's his relative movement direction
if( DotProduct( movedir, viewaxis[FORWARD] ) > MOVEDIREPSILON )
{
cent->jumpedLeft = !cent->jumpedLeft;
if( !cent->jumpedLeft )
{
CG_PModel_AddAnimation( state->number, LEGS_JUMP_LEG2, 0, 0, EVENT_CHANNEL );
CG_SexedSound( state->number, CHAN_BODY, va( S_PLAYER_JUMP_1_to_2, ( rand()&1 )+1 ), cg_volume_players->value );
}
else
{
CG_PModel_AddAnimation( state->number, LEGS_JUMP_LEG1, 0, 0, EVENT_CHANNEL );
CG_SexedSound( state->number, CHAN_BODY, va( S_PLAYER_JUMP_1_to_2, ( rand()&1 )+1 ), cg_volume_players->value );
}
}
else
{
CG_PModel_AddAnimation( state->number, LEGS_JUMP_NEUTRAL, 0, 0, EVENT_CHANNEL );
CG_SexedSound( state->number, CHAN_BODY, va( S_PLAYER_JUMP_1_to_2, ( rand()&1 )+1 ), cg_volume_players->value );
}
}
#undef MOVEDIREPSILON
//racesow - lm: filter out other players
if( ISVIEWERENTITY( state->number ))
CG_AddJumpspeed();
//!racesow
}
示例10: AI_infront
qboolean AI_infront( edict_t *self, edict_t *other )
{
vec3_t vec;
float dot;
vec3_t forward;
AngleVectors( self->s.angles, forward, NULL, NULL );
VectorSubtract( other->s.origin, self->s.origin, vec );
VectorNormalizeFast( vec );
dot = DotProduct( vec, forward );
if( dot > 0.3 )
return qtrue;
return qfalse;
}
示例11: R_DecalComputeBasis
//-----------------------------------------------------------------------------
// compute the decal basis based on surface normal, and preferred saxis
//-----------------------------------------------------------------------------
void R_DecalComputeBasis( msurface_t *surf, vec3_t pSAxis, vec3_t textureSpaceBasis[3] )
{
vec3_t surfaceNormal;
// setup normal
if( surf->flags & SURF_PLANEBACK )
VectorNegate( surf->plane->normal, surfaceNormal );
else VectorCopy( surf->plane->normal, surfaceNormal );
VectorCopy( surfaceNormal, textureSpaceBasis[2] );
if( pSAxis )
{
// T = S cross N
CrossProduct( pSAxis, textureSpaceBasis[2], textureSpaceBasis[1] );
// Name sure they aren't parallel or antiparallel
// In that case, fall back to the normal algorithm.
if( DotProduct( textureSpaceBasis[1], textureSpaceBasis[1] ) > 1e-6 )
{
// S = N cross T
CrossProduct( textureSpaceBasis[2], textureSpaceBasis[1], textureSpaceBasis[0] );
VectorNormalizeFast( textureSpaceBasis[0] );
VectorNormalizeFast( textureSpaceBasis[1] );
return;
}
// Fall through to the standard algorithm for parallel or antiparallel
}
// original Half-Life algorithm: get textureBasis from linked surface
VectorCopy( surf->texinfo->vecs[0], textureSpaceBasis[0] );
VectorCopy( surf->texinfo->vecs[1], textureSpaceBasis[1] );
VectorNormalizeFast( textureSpaceBasis[0] );
VectorNormalizeFast( textureSpaceBasis[1] );
}
示例12: Mod_StudioGetAttachment
/*
====================
StudioGetAttachment
====================
*/
void Mod_StudioGetAttachment( const edict_t *e, int iAttachment, float *origin, float *angles )
{
mstudioattachment_t *pAtt;
vec3_t angles2;
model_t *mod;
mod = Mod_Handle( e->v.modelindex );
mod_studiohdr = (studiohdr_t *)Mod_Extradata( mod );
if( !mod_studiohdr ) return;
if( mod_studiohdr->numattachments <= 0 )
return;
ASSERT( pBlendAPI != NULL );
if( mod_studiohdr->numattachments > MAXSTUDIOATTACHMENTS )
{
mod_studiohdr->numattachments = MAXSTUDIOATTACHMENTS; // reduce it
MsgDev( D_WARN, "SV_StudioGetAttahment: too many attachments on %s\n", mod_studiohdr->name );
}
iAttachment = bound( 0, iAttachment, mod_studiohdr->numattachments );
// calculate attachment origin and angles
pAtt = (mstudioattachment_t *)((byte *)mod_studiohdr + mod_studiohdr->attachmentindex);
VectorCopy( e->v.angles, angles2 );
if( !( host.features & ENGINE_COMPENSATE_QUAKE_BUG ))
angles2[PITCH] = -angles2[PITCH];
pBlendAPI->SV_StudioSetupBones( mod, e->v.frame, e->v.sequence, angles2, e->v.origin,
e->v.controller, e->v.blending, pAtt[iAttachment].bone, e );
// compute pos and angles
if( origin != NULL )
Matrix3x4_VectorTransform( studio_bones[pAtt[iAttachment].bone], pAtt[iAttachment].org, origin );
if( sv_allow_studio_attachment_angles->integer && origin != NULL && angles != NULL )
{
vec3_t forward, bonepos;
Matrix3x4_OriginFromMatrix( studio_bones[pAtt[iAttachment].bone], bonepos );
VectorSubtract( origin, bonepos, forward ); // make forward
VectorNormalizeFast( forward );
VectorAngles( forward, angles );
}
}
示例13: FrustumVis
/**
* @brief Checks whether a point is visible from a given position
* @param[in] origin Origin to test from
* @param[in] dir Direction to test into
* @param[in] point This is the point we want to check the visibility for
*/
qboolean FrustumVis (const vec3_t origin, int dir, const vec3_t point)
{
/* view frustum check */
vec3_t delta;
byte dv;
delta[0] = point[0] - origin[0];
delta[1] = point[1] - origin[1];
delta[2] = 0;
VectorNormalizeFast(delta);
dv = dir & (DIRECTIONS - 1);
/* test 120 frustum (cos 60 = 0.5) */
if ((delta[0] * dvecsn[dv][0] + delta[1] * dvecsn[dv][1]) < 0.5)
return qfalse;
else
return qtrue;
}
示例14: CG_Event_WeaponBeam
/*
* CG_Event_WeaponBeam
*/
static void CG_Event_WeaponBeam( vec3_t origin, vec3_t dir, int ownerNum, int weapon, int firemode )
{
gs_weapon_definition_t *weapondef;
int range;
vec3_t end;
trace_t trace;
switch( weapon )
{
case WEAP_ELECTROBOLT:
weapondef = GS_GetWeaponDef( WEAP_ELECTROBOLT );
range = ELECTROBOLT_RANGE;
break;
case WEAP_INSTAGUN:
weapondef = GS_GetWeaponDef( WEAP_INSTAGUN );
range = weapondef->firedef.timeout;
break;
default:
return;
}
VectorNormalizeFast( dir );
VectorMA( origin, range, dir, end );
// retrace to spawn wall impact
CG_Trace( &trace, origin, vec3_origin, vec3_origin, end, cg.view.POVent, MASK_SOLID );
if( trace.ent != -1 && !(trace.surfFlags & (SURF_SKY|SURF_NOMARKS|SURF_NOIMPACT)) )
{
if( weapondef->weapon_id == WEAP_ELECTROBOLT )
CG_BoltExplosionMode( trace.endpos, trace.plane.normal, FIRE_MODE_STRONG );
else if( weapondef->weapon_id == WEAP_INSTAGUN )
CG_InstaExplosionMode( trace.endpos, trace.plane.normal, FIRE_MODE_STRONG );
}
// when it's predicted we have to delay the drawing until the view weapon is calculated
cg_entities[ownerNum].localEffects[LOCALEFFECT_EV_WEAPONBEAM] = weapon;
VectorCopy( origin, cg_entities[ownerNum].laserOrigin );
VectorCopy( trace.endpos, cg_entities[ownerNum].laserPoint );
}
示例15: G_ClientAddDamageIndicatorImpact
/*
* G_ClientAddDamageIndicatorImpact
*/
void G_ClientAddDamageIndicatorImpact( gclient_t *client, int damage, const vec3_t basedir )
{
edict_t *ent;
vec3_t dir;
float frac;
if( damage < 1 )
return;
if( !client || client - game.clients < 0 || client - game.clients >= gs.maxclients )
return;
ent = &game.edicts[ ( client - game.clients ) + 1 ];
if( !basedir )
{
VectorCopy( vec3_origin, dir );
}
else
{
VectorNormalize2( basedir, dir );
//#define ACCENT_SCALE 2.0f
#ifdef ACCENT_SCALE
// accent the vertical or horizontal aspect of the direction
if( VectorLengthFast( tv( dir[0], dir[1], 0 ) ) > dir[2] )
{
dir[0] *= ACCENT_SCALE;
dir[1] *= ACCENT_SCALE;
}
else
dir[2] *= ACCENT_SCALE;
VectorNormalizeFast( dir );
#endif
#undef ACCENT_SCALE
}
frac = damage / ( damage + client->resp.snap.damageTaken );
VectorLerp( client->resp.snap.damageTakenDir, frac, dir, client->resp.snap.damageTakenDir );
client->resp.snap.damageTaken += damage;
}