本文整理汇总了C++中Missile::getVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ Missile::getVelocity方法的具体用法?C++ Missile::getVelocity怎么用?C++ Missile::getVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Missile
的用法示例。
在下文中一共展示了Missile::getVelocity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enemyMissUpdate
//////// Missile tracks player and follows them ////////
//////// Has a limited turning radius. ////////
//////// Has a limited lifetime until it ////////
//////// explodes ////////
void AI::enemyMissUpdate(Missile &proj, GSP420::ABC *player, const float dt)
{
D3DXVECTOR3 currDir, newDir;
// Get the missiles current direction from its velocity
currDir = proj.getVelocity();
D3DXVec3Normalize(&currDir, &currDir);
// Get the missiles new direction according to player position
newDir = player->getPosition() - proj.getPosition();
D3DXVec3Normalize(&newDir, &newDir);
// Find the angle between the two vectors
float angle = D3DXVec3Dot(&currDir, &newDir);
angle = acos(angle);
// Re-use newDir vector for updating projectile velocity
newDir = proj.getVelocity();
D3DXMATRIX rotMat;
// Check if angle is larger than our missile's turning radius
// Then update the missiles velocity by rotating it in the
// direction of the angle
if (abs(angle) > ENEMY_MISSILE_TURN_RADIUS)
{
if (angle > 0.0f)
{
D3DXMatrixRotationY(&rotMat, ENEMY_MISSILE_TURN_RADIUS);
newDir.x = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.y = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.z = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
proj.setVelocity(newDir);
}
else
{
D3DXMatrixRotationY(&rotMat, -ENEMY_MISSILE_TURN_RADIUS);
newDir.x = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.y = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.z = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
proj.setVelocity(newDir);
}
}
else
{
D3DXMatrixRotationY(&rotMat, angle);
newDir.x = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.y = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
newDir.z = (rotMat._11 * newDir.x) + (rotMat._12 * newDir.y) + (rotMat._13 * newDir.z);
proj.setVelocity(newDir);
}