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


C++ AI::getState方法代码示例

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


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

示例1: update

void SecurityCam::update(const double &dt, Vector3 &playerPos, std::vector<GameObject*> m_goList)
{

	Vector3 SCPos = pos;
	Vector3 SCLookat = Lookat;

	SCPos.y = SCLookat.y = 0;

	switch(c_State)
	{
	case SPOTTED:
		{
			float rotationdiff = (CalAnglefromPosition(playerPos, pos, true) - CalAnglefromPosition(Lookat, pos, true)) * 2.f;

			Mtx44 rotation;
			Lookat = Lookat - pos;
			f_rotationLimiter += rotationdiff * static_cast<float>(dt);
			rotation.SetToRotation(rotationdiff * static_cast<float>(dt), 0, 1, 0);
			Lookat = rotation * Lookat;
			Lookat = Lookat + pos;

			//Check whether player is still in the fov of security camera
			if (((isVisible(SCPos, SCLookat, static_cast<float>(f_cameraFOV), playerPos)) && (SCPos - playerPos).LengthSquared() < f_cameraRange))
			{
				//Give player 1 sec to prevent detection by the security camera
				if (alerttimer < 1)
				{
					alerttimer += static_cast<float>(dt);
				}
				else
				{
					c_State = FOUND;
					alerttimer = 0;
				}
			}
			else
			{
				//if player is no longer in the fov of the security camera
				c_State = NOTFOUND;
				alerttimer = 0;
			}
		}
		break;

	case FOUND:
		{
			float rotationdiff = (CalAnglefromPosition(playerPos, pos, true) - CalAnglefromPosition(Lookat, pos, true));

			if (rotationdiff >= 180)
			{
				Mtx44 rotation;
				Lookat = Lookat - pos;
				rotation.SetToRotation(-360, 0, 1, 0);
				Lookat = rotation * Lookat;
				Lookat = Lookat + pos;
				rotationdiff -= 360;
			}
			else if (rotationdiff <= -180)
			{
				Mtx44 rotation;
				Lookat = Lookat - pos;
				rotation.SetToRotation(360, 0, 1, 0);
				Lookat = rotation * Lookat;
				Lookat = Lookat + pos;
				rotationdiff += 360;
			}

			Mtx44 rotation;
			Lookat = Lookat - pos;
			f_rotationLimiter += rotationdiff * static_cast<float>(dt);
			rotation.SetToRotation(rotationdiff * 2 * static_cast<float>(dt), 0, 1, 0);
			Lookat = rotation * Lookat;
			Lookat = Lookat + pos;

			//Alert all the ai to the camera's position
			if (b_alertAI)
			{
				for (std::vector<GameObject*>::iterator it = m_goList.begin(); it != m_goList.end(); it++)
				{
					GameObject *go = (GameObject *)*it;
					AI *ai = dynamic_cast<AI*>(go);
					if (ai != NULL)
					{
						if (ai->getState() == AI::WALKING)
						{
							ai->setState(AI::ALERT);
							ai->setcurrentLookat(pos);
							ai->setDestination(pos);
						}
					}
				}
				b_alertAI = false;
			}
			else
			{
				if (!isVisible(pos, Lookat, f_cameraFOV, playerPos) || (playerPos - pos).LengthSquared() > f_cameraRange)
				{
					c_State = NOTFOUND;
				}
			}
//.........这里部分代码省略.........
开发者ID:Auranapse,项目名称:Studio-Project-3---Potato-Locomotive,代码行数:101,代码来源:SecurityCam.cpp


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