Пример #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;
	}
Пример #2
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;
	}

}
Пример #3
0
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)
	{
		//Åöײ²¿·Ö
	}
}