本文整理汇总了C++中vec2::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ vec2::GetLength方法的具体用法?C++ vec2::GetLength怎么用?C++ vec2::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec2
的用法示例。
在下文中一共展示了vec2::GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetBallisticData
void Launcher::GetBallisticData(const vec3& position1, const vec3& position2,
float pitch, float& guide_pitch, float& guide_yaw, float &time) const {
const vec3 delta = position1 - position2;
const vec2 yaw_vector(delta.x, delta.y);
guide_yaw = vec2(0, 1).GetAngle(yaw_vector);
const float h = delta.z;
const float v = game_->GetMuzzleVelocity();
const float vup = v * ::cos(pitch);
// g*t^2/2 - vup*t + h = 0
//
// Quaderatic formula:
// ax^2 + bx + c = 0
// =>
// -b +- sqrt(b^2 - 4ac)
// x = ---------------------
// 2a
const float a = +9.82f/2;
const float b = -vup;
const float c = +h;
const float b2 = b*b;
const float _4ac = 4*a*c;
if (b2 < _4ac) { // Does not compute.
guide_pitch = -PIF/4;
} else {
const float t = (-b + sqrt(b2 - _4ac)) / (2*a);
//deb_assert(t > 0);
time = t;
const float vfwd = yaw_vector.GetLength() / t;
guide_pitch = -::atan(vfwd/vup);
if (guide_pitch < pitch) { // Aiming downwards?
guide_pitch += (guide_pitch-pitch); // Tss! Homebrew... seems to be working somewhat! :)
}
}
}