本文整理汇总了C++中DVector3::Resized方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector3::Resized方法的具体用法?C++ DVector3::Resized怎么用?C++ DVector3::Resized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVector3
的用法示例。
在下文中一共展示了DVector3::Resized方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: P_Thing_Projectile
//.........这里部分代码省略.........
if (leadTarget && speed > 0 && !targ->Vel.isZero())
{
// Aiming at the target's position some time in the future
// is basically just an application of the law of sines:
// a/sin(A) = b/sin(B)
// Thanks to all those on the notgod phorum for helping me
// with the math. I don't think I would have thought of using
// trig alone had I been left to solve it by myself.
DVector3 tvel = targ->Vel;
if (!(targ->flags & MF_NOGRAVITY) && targ->waterlevel < 3)
{ // If the target is subject to gravity and not underwater,
// assume that it isn't moving vertically. Thanks to gravity,
// even if we did consider the vertical component of the target's
// velocity, we would still miss more often than not.
tvel.Z = 0.0;
if (targ->Vel.X == 0 && targ->Vel.Y == 0)
{
goto nolead;
}
}
double dist = aim.Length();
double targspeed = tvel.Length();
double ydotx = -aim | tvel;
double a = g_acos (clamp (ydotx / targspeed / dist, -1.0, 1.0));
double multiplier = double(pr_leadtarget.Random2())*0.1/255+1.1;
double sinb = -clamp (targspeed*multiplier * g_sin(a) / speed, -1.0, 1.0);
// Use the cross product of two of the triangle's sides to get a
// rotation vector.
DVector3 rv(tvel ^ aim);
// The vector must be normalized.
rv.MakeUnit();
// Now combine the rotation vector with angle b to get a rotation matrix.
DMatrix3x3 rm(rv, g_cos(g_asin(sinb)), sinb);
// And multiply the original aim vector with the matrix to get a
// new aim vector that leads the target.
DVector3 aimvec = rm * aim;
// And make the projectile follow that vector at the desired speed.
mobj->Vel = aimvec * (speed / dist);
mobj->AngleFromVel();
}
else
{
nolead:
mobj->Angles.Yaw = mobj->AngleTo(targ);
mobj->Vel = aim.Resized (speed);
}
if (mobj->flags2 & MF2_SEEKERMISSILE)
{
mobj->tracer = targ;
}
}
else
{
mobj->Angles.Yaw = angle;
mobj->VelFromAngle(speed);
mobj->Vel.Z = vspeed;
}
// Set the missile's speed to reflect the speed it was spawned at.
if (mobj->flags & MF_MISSILE)
{
mobj->Speed = mobj->VelToSpeed();
}
// Hugger missiles don't have any vertical velocity
if (mobj->flags3 & (MF3_FLOORHUGGER|MF3_CEILINGHUGGER))
{
mobj->Vel.Z = 0;
}
if (mobj->flags & MF_SPECIAL)
{
mobj->flags |= MF_DROPPED;
}
if (mobj->flags & MF_MISSILE)
{
if (P_CheckMissileSpawn (mobj, spot->radius))
{
rtn = true;
}
}
else if (!P_TestMobjLocation (mobj))
{
// If this is a monster, subtract it from the total monster
// count, because it already added to it during spawning.
mobj->ClearCounters();
mobj->Destroy ();
}
else
{
// It spawned fine.
rtn = 1;
}
}
} while (dest != 0 && (targ = tit.Next()));
}
spot = iterator.Next();
}
return rtn != 0;
}
示例2: InterceptDefaultAim
void InterceptDefaultAim(AActor *mobj, AActor *targ, DVector3 aim, double speed)
{
if (mobj == nullptr || targ == nullptr) return;
mobj->Angles.Yaw = mobj->AngleTo(targ);
mobj->Vel = aim.Resized(speed);
}