本文整理汇总了C++中idVec3::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ idVec3::Normalize方法的具体用法?C++ idVec3::Normalize怎么用?C++ idVec3::Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idVec3
的用法示例。
在下文中一共展示了idVec3::Normalize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TryStartPursuit
void rvMonsterStroggHover::TryStartPursuit ( void )
{
if ( GetEnemy() )
{
inPursuit = false;
if ( !marker.GetEntity() ) {
//wtf?!
assert(0);
return;
}
attackPosOffset.Set( gameLocal.random.CRandomFloat()*500.0f, gameLocal.random.CRandomFloat()*500.0f, 0.0f );
if ( attackPosOffset.Length() < 150.0f )
{
attackPosOffset.Normalize();
attackPosOffset *= 150.0f;
}
attackPosOffset.z = (gameLocal.random.CRandomFloat()*30.0f)+50.0f + move.fly_offset;
marker.GetEntity()->GetPhysics()->SetOrigin( GetEnemy()->GetPhysics()->GetOrigin()+attackPosOffset );
if ( MarkerPosValid() )
{
if ( MoveToEntity( marker ) )
{
inPursuit = true;
holdPosTime = 0;
SetState( "State_Pursue" );
}
}
}
}
示例2: R_SetLightProject
void R_SetLightProject(idPlane lightProject[4],
const idVec3 &origin,
const idVec3 &target,
idVec3 &right,
idVec3 &up,
const idVec3 &start,
const idVec3 &stop)
{
float dist;
float scale;
float rLen, uLen;
idVec3 normal;
float ofs;
idVec3 startGlobal;
idVec4 targetGlobal;
rLen = right.Normalize();
uLen = up.Normalize();
normal = up.Cross(right);
normal.Normalize();
dist = target * normal; // - (origin * normal);
if(dist < 0)
{
dist = -dist;
normal = -normal;
}
scale = (0.5f * dist) / rLen;
right *= scale;
scale = -(0.5f * dist) / uLen;
up *= scale;
lightProject[2] = normal;
lightProject[2][3] = -(origin * lightProject[2].Normal());
lightProject[0] = right;
lightProject[0][3] = -(origin * lightProject[0].Normal());
lightProject[1] = up;
lightProject[1][3] = -(origin * lightProject[1].Normal());
// now offset to center
targetGlobal.ToVec3() = target + origin;
targetGlobal[3] = 1;
ofs = 0.5f - (targetGlobal * lightProject[0].ToVec4()) / (targetGlobal * lightProject[2].ToVec4());
lightProject[0].ToVec4() += ofs * lightProject[2].ToVec4();
ofs = 0.5f - (targetGlobal * lightProject[1].ToVec4()) / (targetGlobal * lightProject[2].ToVec4());
lightProject[1].ToVec4() += ofs * lightProject[2].ToVec4();
// set the falloff vector
normal = stop - start;
dist = normal.Normalize();
if (dist <= 0)
{
dist = 1;
}
lightProject[3] = normal * (1.0f / dist);
startGlobal = start + origin;
lightProject[3][3] = -(startGlobal * lightProject[3].Normal());
}
示例3: Killed
/*
================
idExplodingBarrel::Killed
================
*/
void idExplodingBarrel::Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ) {
if ( IsHidden() || state == EXPLODING || state == BURNING ) {
return;
}
float f = spawnArgs.GetFloat( "burn" );
if ( f > 0.0f && state == NORMAL ) {
state = BURNING;
PostEventSec( &EV_Explode, f );
StartSound( "snd_burn", SND_CHANNEL_ANY, 0, false, NULL );
AddParticles( spawnArgs.GetString ( "model_burn", "" ), true );
return;
} else {
state = EXPLODING;
if ( gameLocal.isServer ) {
idBitMsg msg;
byte msgBuf[MAX_EVENT_PARAM_SIZE];
msg.Init( msgBuf, sizeof( msgBuf ) );
msg.WriteLong( gameLocal.time );
ServerSendEvent( EVENT_EXPLODE, &msg, false, -1 );
}
}
// do this before applying radius damage so the ent can trace to any damagable ents nearby
Hide();
physicsObj.SetContents( 0 );
const char *splash = spawnArgs.GetString( "def_splash_damage", "damage_explosion" );
if ( splash && *splash ) {
gameLocal.RadiusDamage( GetPhysics()->GetOrigin(), this, attacker, this, this, splash );
}
ExplodingEffects( );
//FIXME: need to precache all the debris stuff here and in the projectiles
const idKeyValue *kv = spawnArgs.MatchPrefix( "def_debris" );
// bool first = true;
while ( kv ) {
const idDict *debris_args = gameLocal.FindEntityDefDict( kv->GetValue(), false );
if ( debris_args ) {
idEntity *ent;
idVec3 dir;
idDebris *debris;
//if ( first ) {
dir = physicsObj.GetAxis()[1];
// first = false;
//} else {
dir.x += gameLocal.random.CRandomFloat() * 4.0f;
dir.y += gameLocal.random.CRandomFloat() * 4.0f;
//dir.z = gameLocal.random.RandomFloat() * 8.0f;
//}
dir.Normalize();
gameLocal.SpawnEntityDef( *debris_args, &ent, false );
if ( !ent || !ent->IsType( idDebris::Type ) ) {
gameLocal.Error( "'projectile_debris' is not an idDebris" );
}
debris = static_cast<idDebris *>(ent);
debris->Create( this, physicsObj.GetOrigin(), dir.ToMat3() );
debris->Launch();
debris->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = ( gameLocal.time + 1500 ) * 0.001f;
debris->UpdateVisuals();
}
kv = spawnArgs.MatchPrefix( "def_debris", kv );
}
physicsObj.PutToRest();
CancelEvents( &EV_Explode );
CancelEvents( &EV_Activate );
f = spawnArgs.GetFloat( "respawn" );
if ( f > 0.0f ) {
PostEventSec( &EV_Respawn, f );
} else {
PostEventMS( &EV_Remove, 5000 );
}
if ( spawnArgs.GetBool( "triggerTargets" ) ) {
ActivateTargets( this );
}
}
示例4: AddSection
/*
================
sdVehiclePathGrid::AddSection
================
*/
void sdVehiclePathGrid::AddSection( idVec3& lastPos, idVec3& inVector, const idVec3& newPos, const idVec3& finalPos, bool canSkip, idList< splineSection_t >& spline ) const {
idVec3 dist = newPos - lastPos;
idAngles pathAngles = dist.ToAngles();
float pitch = idMath::AngleNormalize180( pathAngles.pitch );
if ( fabs( pitch ) > 30 ) {
idVec3 newInVector;
splineSection_t& section1 = spline.Alloc();
idVec3 verticalPos;
if ( pitch < -30 ) {
verticalPos[ 0 ] = lastPos[ 0 ] + ( ( newPos[ 0 ] - lastPos[ 0 ] ) * 0.3f );
verticalPos[ 1 ] = lastPos[ 1 ] + ( ( newPos[ 1 ] - lastPos[ 1 ] ) * 0.3f );
verticalPos[ 2 ] = lastPos[ 2 ] + ( ( newPos[ 2 ] - lastPos[ 2 ] ) * 0.9f );
} else if ( pitch > 30 ) {
verticalPos[ 0 ] = newPos[ 0 ] + ( ( lastPos[ 0 ] - newPos[ 0 ] ) * 0.3f );
verticalPos[ 1 ] = newPos[ 1 ] + ( ( lastPos[ 1 ] - newPos[ 1 ] ) * 0.3f );
verticalPos[ 2 ] = newPos[ 2 ] + ( ( lastPos[ 2 ] - newPos[ 2 ] ) * 0.9f );
}
newInVector = ( verticalPos - lastPos );
float scale = inVector.Normalize();
section1.AddValue( 0.f, lastPos );
section1.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale * 0.5f ) ) );
section1.AddValue( 2.f / 3.f, verticalPos - ( newInVector * ( scale * 0.5f ) ) );
section1.AddValue( 1.f, verticalPos );
splineSection_t& section2 = spline.Alloc();
newInVector = ( newPos - verticalPos );
scale = newInVector.Normalize();
section2.AddValue( 0.f, verticalPos );
section2.AddValue( 1.f / 3.f, verticalPos + ( inVector * ( scale * 0.5f ) ) );
section2.AddValue( 2.f / 3.f, newPos - ( newInVector * ( scale * 0.5f ) ) );
section2.AddValue( 1.f, newPos );
lastPos = newPos;
inVector = newInVector;
return;
}
if ( canSkip ) {
idVec3 dist;
dist = newPos - lastPos;
dist[ 2 ] = 0;
idAngles angles1 = dist.ToAngles();
dist = finalPos - lastPos;
dist[ 2 ] = 0;
idAngles angles2 = dist.ToAngles();
float yawdiff = idMath::AngleDelta( angles1.yaw, angles2.yaw );
if ( fabs( yawdiff ) > 10.f ) {
return;
}
}
idVec3 newInVector = ( newPos - lastPos );
float scale = newInVector.Normalize();
splineSection_t& section = spline.Alloc();
section.AddValue( 0.f, lastPos );
section.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale * 0.5f ) ) );
section.AddValue( 2.f / 3.f, newPos - ( newInVector * ( scale * 0.5f ) ) );
section.AddValue( 1.f, newPos );
lastPos = newPos;
inVector = newInVector;
}
示例5: PredictTrajectory
/*
=====================
idAI::PredictTrajectory
returns true if there is a collision free trajectory for the clip model
aimDir is set to the ideal aim direction in order to hit the target
=====================
*/
bool idAI::PredictTrajectory( const idVec3 &firePos, const idVec3 &target, float projectileSpeed, const idVec3 &projGravity, const idClipModel *clip, int clipmask, float max_height, const idEntity *ignore, const idEntity *targetEntity, int drawtime, idVec3 &aimDir ) {
int n, i, j;
float zVel, a, t, pitch, s, c;
trace_t trace;
ballistics_t ballistics[2];
idVec3 dir[2];
idVec3 velocity;
idVec3 lastPos, pos;
assert( targetEntity );
// check if the projectile starts inside the target
if ( targetEntity->GetPhysics()->GetAbsBounds().IntersectsBounds( clip->GetBounds().Translate( firePos ) ) ) {
aimDir = target - firePos;
aimDir.Normalize();
return true;
}
// if no velocity or the projectile is not affected by gravity
if ( projectileSpeed <= 0.0f || projGravity == vec3_origin ) {
aimDir = target - firePos;
aimDir.Normalize();
gameLocal.clip.Translation( trace, firePos, target, clip, mat3_identity, clipmask, ignore );
if ( drawtime ) {
gameRenderWorld->DebugLine( colorRed, firePos, target, drawtime );
idBounds bnds( trace.endpos );
bnds.ExpandSelf( 1.0f );
gameRenderWorld->DebugBounds( ( trace.fraction >= 1.0f || ( gameLocal.GetTraceEntity( trace ) == targetEntity ) ) ? colorGreen : colorYellow, bnds, vec3_zero, drawtime );
}
return ( trace.fraction >= 1.0f || ( gameLocal.GetTraceEntity( trace ) == targetEntity ) );
}
n = Ballistics( firePos, target, projectileSpeed, projGravity[2], ballistics );
if ( n == 0 ) {
// there is no valid trajectory
aimDir = target - firePos;
aimDir.Normalize();
return false;
}
// make sure the first angle is the smallest
if ( n == 2 ) {
if ( ballistics[1].angle < ballistics[0].angle ) {
a = ballistics[0].angle; ballistics[0].angle = ballistics[1].angle; ballistics[1].angle = a;
t = ballistics[0].time; ballistics[0].time = ballistics[1].time; ballistics[1].time = t;
}
}
// test if there is a collision free trajectory
for ( i = 0; i < n; i++ ) {
pitch = DEG2RAD( ballistics[i].angle );
idMath::SinCos( pitch, s, c );
dir[i] = target - firePos;
dir[i].z = 0.0f;
dir[i] *= c * idMath::InvSqrt( dir[i].LengthSqr() );
dir[i].z = s;
zVel = projectileSpeed * dir[i].z;
if ( ai_debugTrajectory.GetBool() ) {
t = ballistics[i].time / 100.0f;
velocity = dir[i] * projectileSpeed;
lastPos = firePos;
pos = firePos;
for ( j = 1; j < 100; j++ ) {
pos += velocity * t;
velocity += projGravity * t;
gameRenderWorld->DebugLine( colorCyan, lastPos, pos );
lastPos = pos;
}
}
if ( TestTrajectory( firePos, target, zVel, projGravity[2], ballistics[i].time, firePos.z + max_height, clip, clipmask, ignore, targetEntity, drawtime ) ) {
aimDir = dir[i];
return true;
}
}
aimDir = dir[0];
// there is no collision free trajectory
return false;
}
示例6: TraceToMeshFace
static float TraceToMeshFace( const srfTriangles_t *highMesh, int faceNum,
float minDist, float maxDist,
const idVec3 &point, const idVec3 &normal, idVec3 &sampledNormal,
byte sampledColor[4] ) {
int j;
float dist;
const idVec3 *v[3];
const idPlane *plane;
idVec3 edge;
float d;
idVec3 dir[3];
float baseArea;
float bary[3];
idVec3 testVert;
v[0] = &highMesh->verts[ highMesh->indexes[ faceNum * 3 + 0 ] ].xyz;
v[1] = &highMesh->verts[ highMesh->indexes[ faceNum * 3 + 1 ] ].xyz;
v[2] = &highMesh->verts[ highMesh->indexes[ faceNum * 3 + 2 ] ].xyz;
plane = highMesh->facePlanes + faceNum;
// only test against planes facing the same direction as our normal
d = plane->Normal() * normal;
if ( d <= 0.0001f ) {
return DIST_NO_INTERSECTION;
}
// find the point of impact on the plane
dist = plane->Distance( point );
dist /= -d;
testVert = point + dist * normal;
// if this would be beyond our requested trace distance,
// don't even check it
if ( dist > maxDist ) {
return DIST_NO_INTERSECTION;
}
if ( dist < minDist ) {
return DIST_NO_INTERSECTION;
}
// if normal is inside all edge planes, this face is hit
VectorSubtract( *v[0], point, dir[0] );
VectorSubtract( *v[1], point, dir[1] );
edge = dir[0].Cross( dir[1] );
d = DotProduct( normal, edge );
if ( d > 0.0f ) {
return DIST_NO_INTERSECTION;
}
VectorSubtract( *v[2], point, dir[2] );
edge = dir[1].Cross( dir[2] );
d = DotProduct( normal, edge );
if ( d > 0.0f ) {
return DIST_NO_INTERSECTION;
}
edge = dir[2].Cross( dir[0] );
d = DotProduct( normal, edge );
if ( d > 0.0f ) {
return DIST_NO_INTERSECTION;
}
// calculate barycentric coordinates of the impact point
// on the high poly triangle
bary[0] = idWinding::TriangleArea( testVert, *v[1], *v[2] );
bary[1] = idWinding::TriangleArea( *v[0], testVert, *v[2] );
bary[2] = idWinding::TriangleArea( *v[0], *v[1], testVert );
baseArea = idWinding::TriangleArea( *v[0], *v[1], *v[2] );
bary[0] /= baseArea;
bary[1] /= baseArea;
bary[2] /= baseArea;
if ( bary[0] + bary[1] + bary[2] > 1.1 ) {
bary[0] = bary[0];
return DIST_NO_INTERSECTION;
}
// triangularly interpolate the normals to the sample point
sampledNormal = vec3_origin;
for ( j = 0 ; j < 3 ; j++ ) {
sampledNormal += bary[j] * highMesh->verts[ highMesh->indexes[ faceNum * 3 + j ] ].normal;
}
sampledNormal.Normalize();
sampledColor[0] = sampledColor[1] = sampledColor[2] = sampledColor[3] = 0;
for ( int i = 0 ; i < 4 ; i++ ) {
float color = 0.0f;
for ( j = 0 ; j < 3 ; j++ ) {
color += bary[j] * highMesh->verts[ highMesh->indexes[ faceNum * 3 + j ] ].color[i];
}
sampledColor[i] = color;
}
return dist;
}