当前位置: 首页>>代码示例>>C++>>正文


C++ vec2::GetLength方法代码示例

本文整理汇总了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! :)
		}
	}
}
开发者ID:highfestiva,项目名称:life,代码行数:35,代码来源:launcher.cpp


注:本文中的vec2::GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。