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


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

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


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

示例1: Init

// bool numPartitionBased
// true if worldDivision is num of partition for the world
bool SpatialPartitionManager::Init(Vector2 minWorldDimension, Vector2 maxWorldDimension, Vector2 worldDivision, bool numPartitionBased, Mesh* mesh)
{
	worldDimension.Set(maxWorldDimension.x - minWorldDimension.x, maxWorldDimension.y - minWorldDimension.y);

	// ensure the data are not 0
	if (worldDimension.IsZero() || worldDivision.IsZero())
	{
		return false;
	}

	else
	{
		// divide the world base on the number of partition given
		if (numPartitionBased)
		{
			numPartition.Set(worldDivision.x, worldDivision.y);
			partitionDimension.Set(worldDimension.x / worldDivision.x, worldDimension.y / worldDivision.y);
		}

		else
		{
			partitionDimension.Set(worldDivision.x, worldDivision.y);
			numPartition.Set(worldDimension.x / partitionDimension.x, worldDimension.y / partitionDimension.y);
		}
	}

	type = PARTITION_2D;
	this->minWorldDimension.Set(minWorldDimension.x, minWorldDimension.y);
	this->maxWorldDimension.Set(maxWorldDimension.x, maxWorldDimension.y);

	int id = 0;
	for (int j = 0; j < numPartition.y; ++j)
	{
		for (int i = 0; i < numPartition.x; ++i)
		{
			id = i + j * (int)numPartition.x;

			Partition* partition = new Partition();
			partition->Init(partitionDimension,
				Vector3(minWorldDimension.x + i * partitionDimension.x, 
						minWorldDimension.y + j * partitionDimension.y),
				Vector3(minWorldDimension.x + (i + 1) * partitionDimension.x, 
						minWorldDimension.y + (j + 1) * partitionDimension.y), 
						id, 
						mesh);

			partitions.push_back(partition);
		}
	}

	return true;
}
开发者ID:Chongjx,项目名称:Alpha,代码行数:54,代码来源:SpatialPartitionManager.cpp

示例2: ComputeSeperation

Vector3 CFSM::ComputeSeperation(vector<CFSM*> ListOfCharacters)
{
	Vector2 steer;
	steer.SetZero();

	int count = 0;

	for (int i = 0; i < ListOfCharacters.size(); ++i)
	{
		if (ListOfCharacters[i] != this && ListOfCharacters[i]->GetAlive())
		{
			float distance = (m_CurrentPosition - ListOfCharacters[i]->GetPosition()).Length();
			if (distance < m_seperationZone)
			{
				Vector3 DirectionCopy = m_CurrentPosition - ListOfCharacters[i]->GetPosition();
				Vector2 diff = Vector2(DirectionCopy.x, DirectionCopy.z);
				if (!diff.IsZero())
				{
					diff = diff.Normalized();
					diff.x /= distance;
					diff.y /= distance;
				}
				steer += diff;
				count++;
			}
		}
	}

	if (count > 0)
	{
		steer.x /= (float)count;
		steer.y /= (float)count;
	}

	if (steer.Length() > 0)
	{
		steer = steer.Normalized();
		steer *= m_MovementSpeed;
		Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
		steer -= DirectionCopy;

		if (steer.Length() >= m_maxforce)
		{
			steer *= (m_maxforce / steer.Length());
		}
	}

	return Vector3(steer.x, 0, steer.y);
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:49,代码来源:FSM.cpp

示例3: ComputeAlignment

Vector3 CFSM::ComputeAlignment(vector<CFSM*> ListOfCharacters)
{
	Vector2 sum;
	int count = 0;

	for (int i = 0; i < ListOfCharacters.size(); ++i)
	{
		if (ListOfCharacters[i] != this && ListOfCharacters[i]->GetAlive())
			//if (ListOfCharacters[i] != this && ListOfCharacters[i]->TYPE != "BOSS")
		{
			float distance = (m_CurrentPosition - ListOfCharacters[i]->GetPosition()).Length();
			if (distance < m_flockZone)
			{
				Vector2 VelCopy = Vector2(ListOfCharacters[i]->GetCurrentDirection().x, ListOfCharacters[i]->GetCurrentDirection().z);
				sum += VelCopy;
				count++;
			}
		}
	}

	if (count > 0)
	{
		sum.x /= (float)count;
		sum.y /= (float)count;
		if (!sum.IsZero())
		{
			sum = sum.Normalized();
			sum *= m_MovementSpeed;
		}
		Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
		Vector2 steer = sum - DirectionCopy;

		if (steer.Length() >= m_maxforce)
		{
			steer *= (m_maxforce / steer.Length());
		}
		return Vector3(steer.x, 0, steer.y);

	}
	else
	{
		return Vector3(0, 0, 0);
	}
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:44,代码来源:FSM.cpp

示例4: seek

Vector2 CFSM::seek(Vector2 target)
{
	Vector2 PositionCopy = Vector2(m_CurrentPosition.x, m_CurrentPosition.z);
	Vector2 direction = target - PositionCopy;
	if (!direction.IsZero())
	{
		direction = direction.Normalized();
		direction *= m_MovementSpeed;
	}

	Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
	Vector2 steer = direction - DirectionCopy;

	if (steer.Length() >= m_maxforce)
	{
		steer *= (m_maxforce / steer.Length());
	}

	return steer;
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:20,代码来源:FSM.cpp

示例5: RenderPlayerStats

void SceneManagerCMPlay::RenderPlayerStats()
{
	float m_BillBoard;
	Mesh* drawMesh = resourceManager.retrieveMesh("FONT");
	drawMesh->textureID = resourceManager.retrieveTexture("STATUSFONT");

	string count = "Total Entities:" + to_string(TOTAL_COUNT);
	string FPS = "FPS: " + to_string(fps);
	RenderTextOnScreen(drawMesh, FPS, resourceManager.retrieveColor("White"), 25.f, 1500, 1050, 0);
	RenderTextOnScreen(drawMesh, count, resourceManager.retrieveColor("White"), 25.f, 1500, 1020, 0);
	RenderTextOnScreen(drawMesh, "F1 - To spawn tank", resourceManager.retrieveColor("White"), 25.f, 10, 1050, 0);
	RenderTextOnScreen(drawMesh, "F2 - To spawn mage", resourceManager.retrieveColor("White"), 25.f, 10, 1020, 0);
	RenderTextOnScreen(drawMesh, "F3 - To spawn healer", resourceManager.retrieveColor("White"), 25.f, 10, 990, 0);
	RenderTextOnScreen(drawMesh, "F4 - To spawn boss", resourceManager.retrieveColor("White"), 25.f, 10, 960, 0);
	RenderTextOnScreen(drawMesh, "F5 - Warrior hp = 10%", resourceManager.retrieveColor("White"), 25.f, 10, 930, 0);
	RenderTextOnScreen(drawMesh, "F6 - Kill warrior", resourceManager.retrieveColor("White"), 25.f, 10, 900, 0);
	RenderTextOnScreen(drawMesh, "F7 - Healer hp = 10%", resourceManager.retrieveColor("White"), 25.f, 10, 870, 0);
	RenderTextOnScreen(drawMesh, "F8 - Restore health", resourceManager.retrieveColor("White"), 25.f, 10, 840, 0);
	RenderTextOnScreen(drawMesh, "W & S - Cycle Camera", resourceManager.retrieveColor("White"), 25.f, 10, 810, 0);
	RenderTextOnScreen(drawMesh, "3 & 4 - Toggle status render", resourceManager.retrieveColor("White"), 25.f, 10, 780, 0);
	
	if (toggleStatusAndParticles)
	{
		for (int i = 0; i < ListOfCharacters.size(); ++i)
		{
			Vector2 CopyVector;
			Vector2 CopyVector2;

			CopyVector.Set(tpCamera.getPosition().x, tpCamera.getPosition().z);
			CopyVector2.Set(ListOfCharacters[i]->GetPosition().x, ListOfCharacters[i]->GetPosition().z);

			Vector2 Direction = (CopyVector - CopyVector2).Normalized();

			if (!Direction.IsZero())
			{
				m_BillBoard = Math::RadianToDegree(atan2(Direction.x, Direction.y));
			}

			modelStack.PushMatrix();
			modelStack.Translate(ListOfCharacters[i]->GetPosition().x, ListOfCharacters[i]->GetPosition().y + 15.f, ListOfCharacters[i]->GetPosition().z);
			modelStack.Rotate(m_BillBoard, 0, 1, 0);
			modelStack.Scale(2.f, 2.f, 2.f);
			modelStack.PushMatrix();
			modelStack.Translate(-2.5f, 0.f, 0.f);
			RenderText(drawMesh, ListOfCharacters[i]->PrintState(), resourceManager.retrieveColor("White"));
			modelStack.PopMatrix();

			float HPBARSCALE = 5.f;

			modelStack.PushMatrix();
			float newScale = (ListOfCharacters[i]->GetHpPercent() / 100) * HPBARSCALE;

			float theTranslate = 5.0f - (ListOfCharacters[i]->GetHpPercent() / 100) * HPBARSCALE;

			modelStack.Translate(-theTranslate * 0.5f, 2.f, 0.01f);
			modelStack.Scale(newScale, 1, 1);
			Render3DMesh(resourceManager.retrieveMesh("HPCURRENT"), true);
			modelStack.PopMatrix();

			modelStack.PushMatrix();
			modelStack.Translate(0.f, 2.f, 0.f);
			modelStack.Scale(HPBARSCALE, 1, 1);
			Render3DMesh(resourceManager.retrieveMesh("HPMAX"), true);
			modelStack.PopMatrix();

			modelStack.PopMatrix();


		}
	}
}
开发者ID:pongtato,项目名称:The-real-AI,代码行数:71,代码来源:SceneManagerCMPlay.cpp

示例6: Update


//.........这里部分代码省略.........
	M *= m;
	
	// ビュー変換
	Matrix4View(m, Vector3(0, 0, 0), Vector3(0, 0, n), Vector3(0, 1, 0));
	M *= m;

	// 射影行列
	Matrix4 Mproj;
	Matrix4Projection(Mproj, 120.0f/180.0f*3.141592f, (float)SCREEN_W/(float)SCREEN_H, 1, 500);

	// スクリーン座標変換行列
	Matrix4 Mscreen;
	Matrix4Screen(Mscreen, SCREEN_W, SCREEN_H);

	for (i = 0; i < CUBE_SIZE; ++i) {
		// 各種変換
		buf[i] = cube[i] * M;

		// 射影変換
		buf[i] = Mproj * buf[i];
		buf[i] /= buf[i].w;

		// スクリーン座標に変換
		buf[i] = buf[i] * Mscreen;
	}


	// 背景描画
	RECT rcBack = {0, 0, SCREEN_W, SCREEN_H};
	FillRect(backDC, &rcBack, (HBRUSH)GetStockObject(BLACK_BRUSH));

	// 愚直な色変化
	static int r = 0xff, g = 0x00, b = 0x00;
	static int a = 1;

	switch (a) {
		case 0: b-=4; if (b <= 0x00) { ++a; b=0x00; }	break;
		case 1: g+=4; if (g >= 0xff) { ++a; g=0xff; }	break;
		case 2: r-=4; if (r <= 0x00) { ++a; r=0x00; }	break;
		case 3: b+=4; if (b >= 0xff) { ++a; b=0xff; }	break;
		case 4: g-=4; if (g <= 0x00) { ++a; g=0x00; }	break;
		case 5: r+=4; if (r >= 0xff) { a=0; r=0xff; }	break;
	}

	// 図形描画
	HPEN hPenOld, hPen;
	hPen = CreatePen(PS_SOLID, 0, RGB(r, g, b));
	hPenOld = (HPEN)SelectObject(backDC, hPen);

	for (i = 0; i < CUBE_SIZE>>1; ++i) {
		MoveToEx(backDC, buf[i].x, buf[i].y, NULL);
		LineTo(backDC, buf[(i+1)&3].x, buf[(i+1)&3].y);

		MoveToEx(backDC, buf[i+4].x, buf[i+4].y, NULL);
		LineTo(backDC, buf[4+((i+1)&3)].x, buf[4+((i+1)&3)].y);

		MoveToEx(backDC, buf[i].x, buf[i].y, NULL);
		LineTo(backDC, buf[i+4].x, buf[i+4].y);
	}

	MoveToEx(backDC, buf[0].x-5, buf[0].y-5, NULL);
	LineTo(backDC, buf[0].x+5, buf[0].y+5);
	MoveToEx(backDC, buf[0].x+5, buf[0].y-5, NULL);
	LineTo(backDC, buf[0].x-5, buf[0].y+5);

	SelectObject(backDC, hPenOld);
	DeleteObject(hPen);

	// 軸描画
	Vector2 axis = rot * 50.0f;
	if (!axis.IsZero()) {
		axis.y = -axis.y;
		Vector2 allow1, allow2, u(SCREEN_W>>1, SCREEN_H>>1);
		
		Vector2Rotate(allow1, axis, (90.0f+45.0f)/180.0f*3.141592f);
		allow1.Normalize();
		allow1 *= 10;
		Vector2Rotate(allow2, axis,-(90.0f+45.0f)/180.0f*3.141592f);
		allow2.Normalize();
		allow2 *= 10;

		axis += u;
		allow1 += axis;
		allow2 += axis;
		
		hPen = CreatePen(PS_SOLID, 0, RGB(0xff, 0, 0));
		hPenOld = (HPEN)SelectObject(backDC, hPen);	

		MoveToEx(backDC, u.x, u.y, NULL);
		LineTo(backDC, axis.x, axis.y);
		
		MoveToEx(backDC, axis.x, axis.y, NULL);
		LineTo(backDC, allow1.x, allow1.y);
		
		MoveToEx(backDC, axis.x, axis.y, NULL);
		LineTo(backDC, allow2.x, allow2.y);

		SelectObject(backDC, hPenOld);
		DeleteObject(hPen);
	}
开发者ID:erio-nk,项目名称:MyCxxProgram2011,代码行数:101,代码来源:MyApp.cpp


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