Esempio n. 1
0
	bool Restraint::GetCMatrix(const Plane structureOrientation, arma::mat & CN)
	{
		// Check if restraint plane differs from global plane
		if (structureOrientation.CompareTo(this->_orientation))
			return false;

		// If different
		CN = arma::mat(6, 6, arma::fill::zeros);

		Vector3d drX = this->GetXDir();
		Vector3d drY = this->GetYDir();
		Vector3d drZ = this->GetZDir();

		Vector3d strX = structureOrientation.GetX();
		Vector3d strY = structureOrientation.GetY();
		Vector3d strZ = structureOrientation.GetZ();

		double nxx = drX.DotProduct(strX);
		double nxy = drY.DotProduct(strY);
		double nxz = drZ.DotProduct(strZ);

		double nyx = drX.DotProduct(strX);
		double nyy = drY.DotProduct(strY);
		double nyz = drZ.DotProduct(strZ);

		double nzx = drX.DotProduct(strX);
		double nzy = drY.DotProduct(strY);
		double nzz = drZ.DotProduct(strZ);

		// Two times for same transformations for translations (1) and rotations(2)
		for (int i = 0; i < 2; i++)
		{
			CN[0 + i * 3, 0 + i * 3] = nxx;
			CN[0 + i * 3, 1 + i * 3] = nxy;
			CN[0 + i * 3, 2 + i * 3] = nxz;

			CN[1 + i * 3, 0 + i * 3] = nyx;
			CN[1 + i * 3, 1 + i * 3] = nyy;
			CN[1 + i * 3, 2 + i * 3] = nyz;

			CN[2 + i * 3, 0 + i * 3] = nyx;
			CN[2 + i * 3, 1 + i * 3] = nyy;
			CN[2 + i * 3, 2 + i * 3] = nyz;
		}

		return true;
	}
Esempio n. 2
0
void MainWindow::Update(int timeElapsed)
{
	float kt = timeElapsed / 16.0f;

	static int dir = 1;
	static float anim = 0.0f;
	anim += 0.01f * dir * kt;
	grassShader->Uniform("anim", anim);

	for (int i = 0; i < numTargets; i++)
	{
		Target &t = targets[i];
		if (t.fAnim)
		{
			const float delta = 5.0f * kt;
			t.rotAngle += delta;
			t.model->rotation *= Quaternion(Vector3f(1,0,0), delta);
			if (t.rotAngle >= 70.0f) t.fAnim = false;
		}
	}

	if (fGunAnim)
	{
		static int dir = 1;
		static int t = 0;
		float maxAnim = 15.0f;

		if (dir == 1)
			gunAnim += 0.5f * (maxAnim - gunAnim) * kt;
		else gunAnim -= 1.0f * kt;

		gun->rotation = Quaternion(Vector3f(1,0,0), gunAnim);

		if (gunAnim >= maxAnim - 0.4f) {
			dir = -1;
			gunAnim = maxAnim;
		}
		else if (dir == -1 && gunAnim <= 0.0f) {
			dir = 1;
			fGunAnim = false;
			fShowMuzzleFlash = false;
			t = 0;
			gun->rotation = Quaternion::Identity();
		}

		if (t >= 70) {
			fShowMuzzleFlash = false;
			t = 0;
		}
		t += timeElapsed;
	}

	const float step = 0.01875f * timeElapsed;
	const float maxAngle = (float)cos(DEG_TO_RAD(45.0f));
	bool moved = false;
	float dx = 0.0f, dz = 0.0f;

	if (GetAsyncKeyState('W'))
		dz = -step;
	else if (GetAsyncKeyState('S'))
		dz = step;

	if (GetAsyncKeyState('A'))
		dx = -step;
	else if (GetAsyncKeyState('D'))
		dx = step;

	if (dx != 0.0f || dz != 0.0f) {
		Vector3f pos = camera.GetPosition();
		float curHeight = terrain->GetHeightAt(pos.x, pos.z);

		camera.MoveX(dx);
		camera.MoveZ(dz);
		pos = camera.GetPosition();
	
		Plane eq = terrain->GetPolyEquation(pos.x, pos.z);
		float newHeight = eq.GetY(pos.x, pos.z);

		if (newHeight < curHeight) {
			moved = true;
		}
		else {
			float cosAngle = abs(eq.B) / sqrt(eq.A*eq.A + eq.B*eq.B + eq.C*eq.C);
			if (cosAngle >= maxAngle) {
				moved = true;
			}
			else {
				camera.MoveX(-dx);
				camera.MoveZ(-dz);
			}
		}
	}

	if (moved)
	{
		Vector3f pos = camera.GetPosition();
		finalHeight = growth + terrain->GetHeightAt(pos.x, pos.z);

		if (!CmpReal(pos.y, finalHeight))
		{
			float diff = pow(finalHeight - pos.y, 3)*0.1f;

			pos.y = min(pos.y + diff, finalHeight);
			camera.SetPosition(pos.x, pos.y, pos.z);
		}
	}
}
Esempio n. 3
0
void Bullet::BulletMove()
{
	double radian;

	switch (m_BulletType)
	{
	case 0:	//ÔÈËÙ×Óµ¯
		radian = m_iDirection/180 * PI;

		SetX(m_iX + m_iSpeed*sin(radian));
		SetY(m_iY + m_iSpeed*cos(radian));
		break;

	case 1:	//ÔÝÍ£×Óµ¯
		if (m_iStep == STEP_1 && m_iSpeed > 0)
		{
			m_iSpeed -= m_iAcceleration;
			if (m_iSpeed <= 0)
			{
				m_iSpeed = 0;
				m_Time = g_Time;
				m_iStep = STEP_2;
			}
		} 
		else if (m_iStep == STEP_2)
		{
			 if (g_Time - m_Time > m_PauseTime)
			 {
				 m_iStep = STEP_3;
			 }
		}
		else if (m_iStep == STEP_3)
		{
			m_iSpeed += m_iAcceleration;
			if (m_iSpeed >= m_iFinalSpeed)
			{
				m_iSpeed = m_iFinalSpeed;
			}
		}

		radian = m_iDirection/180 * PI;

		SetX(m_iX + m_iSpeed*sin(radian));
		SetY(m_iY + m_iSpeed*cos(radian));
		break;

	case 2:	//ÔÝÍ£ºó±ä¸ü·½Ïò
		if (m_iStep == STEP_1 && m_iSpeed > 0)
		{
			m_iSpeed -= m_iAcceleration;
			if (m_iSpeed <= 0)
			{
				m_iSpeed = 0;
				m_Time = g_Time;
				m_iStep = STEP_2;
			}
		} 
		else if (m_iStep == STEP_2)
		{
			if (g_Time - m_Time > m_PauseTime)
			{
				double temp;
				if (m_DirectChange == -1)
				{
					temp = rand()%180;
				}
				else
				{
					temp = m_DirectChange;
				}
				m_iDirection += temp;
				m_iStep = STEP_3;
			}
		}
		else if (m_iStep == STEP_3)
		{
			m_iSpeed += m_iAcceleration;
			if (m_iSpeed >= m_iFinalSpeed)
			{
				m_iSpeed = m_iFinalSpeed;
			}
		}

		radian = m_iDirection/180 * PI;

		SetX(m_iX + m_iSpeed*sin(radian));
		SetY(m_iY + m_iSpeed*cos(radian));
		break;

	case 3:	//×·×Ùµ¼µ¯
		switch (m_iStep)
		{
		case STEP_1:
			m_iAngle = m_iDirection/180 * PI;

			SetX(m_iX + m_iSpeed*sin(m_iAngle));
			SetY(m_iY + m_iSpeed*cos(m_iAngle));

			if (g_Time - m_Time > 500)
			{
				m_iStep = STEP_2;
			}
			break;

		case STEP_2:
			{
				vector<Plane *>* tempPlanes = g_Manager.GetPlaneVector();

				for (int i=1; i<(int)tempPlanes->size(); i++)
				{
					if ((*tempPlanes)[i])
					{
						m_iTarget = i;
						break;
					}
				}

				m_iStep = STEP_3;
			}
			break;

		case STEP_3:
			if (m_iTarget != -1)
			{
				Plane *target = (*g_Manager.GetPlaneVector())[m_iTarget];
				if (target)
				{
					m_iDesX = target->GetX();
					m_iDesY = target->GetY();

					m_iAngle = atan((double)(m_iDesX-m_iX)/(double)(m_iDesY-m_iY));
					m_iDirection = m_iAngle*180/PI;

					if (m_iDesY > m_iY)
					{
						SetX(m_iX + m_iSpeed*sin(m_iAngle));
						SetY(m_iY + m_iSpeed*cos(m_iAngle));
					}
					else if(m_iDesY < m_iY)
					{
						SetX(m_iX - (int)(m_iSpeed*sin(m_iAngle)));
						SetY(m_iY - (int)(m_iSpeed*cos(m_iAngle)));
					}
					else
					{
						if (m_iDesX > m_iX)
						{
							SetX(m_iX+m_iSpeed);
						}
						else
						{
							SetX(m_iX-m_iSpeed);
						}
					}
				}
				else
				{
					m_iTarget = -1;
				}	
			}
			else
			{
				m_iAngle = m_iDirection/180 * PI;

				SetX(m_iX + m_iSpeed*sin(m_iAngle));
				SetY(m_iY + m_iSpeed*cos(m_iAngle));
			}
			break;
		}
		break;
	}

}
void PlaneGuard::UpdatePlane()
{
	Plane *target = (*g_Manager.GetPlaneVector())[m_Target];

	if (!target)
	{
		m_iState = P_DISAPPEAR;
		return;
	}

	if (m_bMoveable)
	{
		m_iDirection += m_iSpeed;
		if (m_iDirection >= 360)
		{
			m_iDirection -= 360;
		}
		m_Angle = m_iDirection/180 * PI;

		SetX(target->GetX() + (int)(m_Distance*sin(m_Angle)));
		SetY(target->GetY() + (int)(m_Distance*cos(m_Angle)));

		//¸üз¢ÉäÆ÷µÄλÖÃ
		for (int i=0; i<(int)m_vShooterGroup.size(); i++)
		{
			for (int j=0; j<(int)m_vShooterGroup[i].size(); j++)
			{
				m_vShooterGroup[i][j]->SetPos(m_iX, m_iY);
			}
		}
	}

	//·¢Éä
	m_bFireOver = true;
	vector<Shooter*> *pShooters = &m_vShooterGroup[m_iNowShooterGroup];
	for (int i=0; i<(int)pShooters->size(); i++)
	{
		if (m_bFireCommand)
		{
			(*pShooters)[i]->SetCommand(true);
			m_bFireOver &= (*pShooters)[i]->Fire(false); 
		}
	}

	if (m_bFireOver)
	{
		m_iNowShooterGroup++;
		if (m_iNowShooterGroup >= (int)pShooters->size())
		{
			m_iNowShooterGroup = 0;
		}

		for (int i=0; i<(int)pShooters->size(); i++)
		{
			(*pShooters)[i]->SetCommand(false);
			(*pShooters)[i]->Reload(); 
		}
	}

	if (m_bImpactable)
	{
		//Åöײ²¿·Ö
	}
}