Exemplo n.º 1
0
Tank::ExecResult Tank::executeMove(Vec2 p)
{
    if (surfaceId) {
        if (Planet* planet = _game->objs()->getByIdAs<Planet>(surfaceId)) {
            Polar src = planet->world2polar(_body->getPosition());
            Polar dst = planet->world2polar(p);
            float aDist = angleDistance(src.a, dst.a);
            if (fabsf(aDist) * src.r < getSize() / 10) {
                moveLeft(false);
                moveRight(false);
                return ExecResult::Done;
            } else if (aDist < 0) {
                moveRight(true);
                moveLeft(false);
                return ExecResult::InProgress;
            } else {
                moveRight(false);
                moveLeft(true);
                return ExecResult::InProgress;
            }
        } else {
            return ExecResult::Failed;
        }
    } else {
        return ExecResult::Delayed;
    }
}
Exemplo n.º 2
0
Tank::ExecResult Tank::executeAim(Vec2 p)
{
    if (surfaceId) {
        if (Planet* planet = _game->objs()->getByIdAs<Planet>(surfaceId)) {
            Vec2 fromPoint;
            Vec2 sourceDir;
            getShootParams(fromPoint, sourceDir);
            Vec2 targetDir = (p - getShootCenter()).getNormalized();
            if (targetDir.isSmall() || sourceDir.isSmall()) {
                gunRotationSpeed(0.0f);
                return ExecResult::Done; // We do not know where to aim, so we are done
            }
            float aDist = angleDistance(sourceDir.getAngle(), targetDir.getAngle());
            if (fabsf(aDist) < CC_DEGREES_TO_RADIANS(5)) {
                if (fabsf(aDist) < CC_DEGREES_TO_RADIANS(0.2)) {
                    gunRotationSpeed(0.0f);
                    return ExecResult::Done;
                } else if (aDist < 0) {
                    gunRotationSpeed(-0.1f);
                    return ExecResult::InProgress;
                } else {
                    gunRotationSpeed(0.1f);
                    return ExecResult::InProgress;
                }
            } else if (aDist < 0) {
                gunRotationSpeed(-1.0f);
                return ExecResult::InProgress;
            } else {
                gunRotationSpeed(1.0f);
                return ExecResult::InProgress;
            }
        } else {
            return ExecResult::Failed;
        }
    } else {
        return ExecResult::Delayed;
    }
}
Exemplo n.º 3
0
void AUD_ChannelMapperReader::calculateMapping()
{
	if(m_map_size < m_source_channels * m_target_channels)
	{
		delete[] m_mapping;
		m_mapping = new float[m_source_channels * m_target_channels];
		m_map_size = m_source_channels * m_target_channels;
	}

	for(int i = 0; i < m_source_channels * m_target_channels; i++)
		m_mapping[i] = 0;

	const AUD_Channel* source_channels = CHANNEL_MAPS[m_source_channels - 1];
	const AUD_Channel* target_channels = CHANNEL_MAPS[m_target_channels - 1];

	int lfe = -1;

	for(int i = 0; i < m_target_channels; i++)
	{
		if(target_channels[i] == AUD_CHANNEL_LFE)
		{
			lfe = i;
			break;
		}
	}

	const float* source_angles = CHANNEL_ANGLES[m_source_channels - 1];
	const float* target_angles = CHANNEL_ANGLES[m_target_channels - 1];

	if(m_source_channels == AUD_CHANNELS_MONO)
		source_angles = &m_mono_angle;

	int channel_left, channel_right;
	float angle_left, angle_right, angle;

	for(int i = 0; i < m_source_channels; i++)
	{
		if(source_channels[i] == AUD_CHANNEL_LFE)
		{
			if(lfe != -1)
				m_mapping[lfe * m_source_channels + i] = 1;

			continue;
		}

		channel_left = channel_right = -1;
		angle_left = -2 * M_PI;
		angle_right = 2 * M_PI;

		for(int j = 0; j < m_target_channels; j++)
		{
			if(j == lfe)
				continue;
			angle = angleDistance(source_angles[i], target_angles[j]);
			if(angle < 0)
			{
				if(angle > angle_left)
				{
					angle_left = angle;
					channel_left = j;
				}
			}
			else
			{
				if(angle < angle_right)
				{
					angle_right = angle;
					channel_right = j;
				}
			}
		}

		angle = angle_right - angle_left;
		if(channel_right == -1 || angle == 0)
		{
			m_mapping[channel_left * m_source_channels + i] = 1;
		}
		else if(channel_left == -1)
		{
			m_mapping[channel_right * m_source_channels + i] = 1;
		}
		else
		{
			m_mapping[channel_left * m_source_channels + i] = cos(M_PI_2 * angle_left / angle);
			m_mapping[channel_right * m_source_channels + i] = cos(M_PI_2 * angle_right / angle);
		}
	}

	/* AUD_XXX for(int i = 0; i < m_source_channels; i++)
	{
		for(int j = 0; j < m_target_channels; j++)
		{
			std::cout << m_mapping[i * m_source_channels + j] << " ";
		}
		std::cout << std::endl;
	}*/
}