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


C++ Vector2::LengthSqr方法代码示例

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


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

示例1: GetDistanceSqr

float AIController::GetDistanceSqr(const Vector3 &pos1,const Vector3 &pos2)const
{
	Vector2 distance ;//since the board gemeotry is mostly flat,we can use 2D vector
	distance.x = pos1.x - pos2.x;
	distance.y = pos1.z - pos2.z;

	return distance.LengthSqr();
}
开发者ID:kakashidinho,项目名称:pathman2010,代码行数:8,代码来源:AI.cpp

示例2: Control

void AIController::Control(const Board *board,const MovableObject *player,bool playerInv)
{
	const Vector3 & pos1 = object->GetPosition();//ghost position in world space
	float velocity = object->GetVelocity();
	//get ghost location in board
	board->GetTileInfo(pos1,currentTile.row,currentTile.col);
	
	float diff;
	switch (object->GetDirection())
	{
	case LEFT:
		diff = pos1.x - destination.x;
		if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
			break;
		if (diff > velocity + FLOAT_DELTA)
		{
			this->object->Update();
			return;
		}
		else
		{
			posOffset = velocity - diff;
			this->object->SetPosition(destination);
			return;
		}
		break;
	case RIGHT:
		diff = destination.x - pos1.x;
		if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
			break;
		if (diff > velocity + FLOAT_DELTA)
		{
			this->object->Update();
			return;
		}
		else
		{
			posOffset = velocity - diff;
			this->object->SetPosition(destination);
			return;
		}
		break;
	case UP:
		diff = pos1.z - destination.y;
		if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
			break;
		if (diff > velocity + FLOAT_DELTA)
		{
			this->object->Update();
			return;
		}
		else
		{
			posOffset = velocity - diff;
			this->object->SetPosition(destination);
			return;
		}
		break;
	case DOWN:
		diff = destination.y - pos1.z;
		if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
			break;
		if (diff > velocity + FLOAT_DELTA)
		{
			this->object->Update();
			return;
		}
		else
		{
			posOffset = velocity - diff;
			this->object->SetPosition(destination);
			return;
		}
		break;
	}
	if(playerInv)//player is invisible
	{
		Wandering(board);
		return;
	}
	Vector2 distance ;//since the board gemeotry is mostly flat,we can use 2D vector
	float distSqr;

	const Vector3 & pos2 = player->GetPosition();
	
	distance.x = pos1.x - pos2.x;
	distance.y = pos1.z - pos2.z;

	distSqr = distance.LengthSqr();
	if (distSqr <= rosSqr)//player is in ghost's range of sight
		Chasing(board,player);
	else
	{
		Wandering(board);
	}
}
开发者ID:kakashidinho,项目名称:pathman2010,代码行数:96,代码来源:AI.cpp


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