Пример #1
0
// 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;
}
Пример #2
0
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);
}
Пример #3
0
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);
	}
}
Пример #4
0
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;
}
Пример #5
0
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();


		}
	}
}
Пример #6
0
/**
 *	MyApp::Update()
 *	毎フレームの処理
 */
void MyApp::Update()
{
	int i;

	bool _b = false;
	float _x = 0, _y = 0;
	if (HIWORD(GetAsyncKeyState(VK_UP))) {
		_y = 5.0f;	_b = true;
	}
	if (HIWORD(GetAsyncKeyState(VK_DOWN))) {
		_y = -5.0f;	_b = true;
	}
	if (HIWORD(GetAsyncKeyState(VK_LEFT))) {
		_x = -5.0f;	_b = true;
	}
	if (HIWORD(GetAsyncKeyState(VK_RIGHT))) {
		_x = 5.0f;	_b = true;
	}
	if (_b) Rotate(Vector2(_x, _y));



	// 頂点計算
	Vector4 pos(0.0f, 0.0f, 7.0f, 0.0f);	// 立体位置
	float n = 1;	// 焦点距離


	Matrix4 M, m;
	Matrix4Identity(M);

	// 回転
	Quaternion q;
	QuaternionRotationAxis(q, -angle/180.0f*3.141592f, Vector3(rot, 0));
	qRot *= q;
	Matrix4RotationQuaternion(m, qRot);
	M *= m;
	
	angle -= 0.1f;	// ちょっとずつ回転を弱くする
	if (angle < 0.0f) angle = 0.0f;

	// 拡縮
	Matrix4Scaling(m, scale, scale, scale);
	M *= m;

	// 平行移動
	Matrix4Translation(m, pos.x, pos.y, pos.z);
	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);
	}