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


C++ const_entity_handle::viewing_transform方法代码示例

本文整理汇总了C++中const_entity_handle::viewing_transform方法的典型用法代码示例。如果您正苦于以下问题:C++ const_entity_handle::viewing_transform方法的具体用法?C++ const_entity_handle::viewing_transform怎么用?C++ const_entity_handle::viewing_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在const_entity_handle的用法示例。


在下文中一共展示了const_entity_handle::viewing_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw_crosshair_lines

	void draw_crosshair_lines(
		std::function<void(vec2, vec2, rgba)> callback,
		std::function<void(vec2, vec2)> dashed_line_callback,
		const interpolation_system& interp,
		const const_entity_handle crosshair, 
		const const_entity_handle character) {
		if (crosshair.alive()) {
			const auto& cosmos = crosshair.get_cosmos();
			const auto& physics = cosmos.systems_temporary.get<physics_system>();

			vec2 line_from[2];
			vec2 line_to[2];

			const auto crosshair_pos = crosshair.viewing_transform(interp).pos;

			const auto guns = character.guns_wielded();

			auto calculate_color = [&](const const_entity_handle target) {
				const auto att = calculate_attitude(character, target);

				if (att == attitude_type::WANTS_TO_KILL || att == attitude_type::WANTS_TO_KNOCK_UNCONSCIOUS) {
					return red;
				}
				else if (att == attitude_type::WANTS_TO_HEAL) {
					return green;
				}
				else {
					return cyan;
				}
			};

			if (guns.size() >= 1) {
				const auto subject_item = guns[0];

				const auto& gun = subject_item.get<components::gun>();

				const auto rifle_transform = subject_item.viewing_transform(interp);
				const auto barrel_center = gun.calculate_barrel_center(rifle_transform);
				const auto muzzle = gun.calculate_muzzle_position(rifle_transform);

				line_from[0] = muzzle;
				
				const auto proj = crosshair_pos.get_projection_multiplier(barrel_center, muzzle);

				if (proj > 1.f) {
					line_to[0] = barrel_center + (muzzle - barrel_center) * proj;
					
					const auto raycast = physics.ray_cast_px(line_from[0], line_to[0], filters::bullet(), subject_item);

					auto col = cyan;

					if (raycast.hit) {
						dashed_line_callback(raycast.intersection, line_to[0]);

						line_to[0] = raycast.intersection;
						col = calculate_color(cosmos[raycast.what_entity]);
					}

					callback(line_from[0], line_to[0], col);
				}
			}

			if (guns.size() >= 2) {
				const auto subject_item = guns[1];

				const auto& gun = subject_item.get<components::gun>();

				const auto rifle_transform = subject_item.viewing_transform(interp);
				const auto barrel_center = gun.calculate_barrel_center(rifle_transform);
				const auto muzzle = gun.calculate_muzzle_position(rifle_transform);

				line_from[1] = muzzle;

				const auto proj = crosshair_pos.get_projection_multiplier(barrel_center, muzzle);

				if (proj > 1.f) {
					line_to[1] = barrel_center + (muzzle - barrel_center) * proj;
					
					const auto raycast = physics.ray_cast_px(line_from[1], line_to[1], filters::bullet(), subject_item);

					auto col = cyan;

					if (raycast.hit) {
						dashed_line_callback(raycast.intersection, line_to[1]);

						line_to[1] = raycast.intersection;
						col = calculate_color(cosmos[raycast.what_entity]);
					}

					callback(line_from[1], line_to[1], col);
				}
			}
		}
	}
开发者ID:,项目名称:,代码行数:94,代码来源:


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