Пример #1
0
bool Turret::canFollowTarget(DrawableObject & target, bool TargetInvisible)
{
	float distance = (float)sqrt(pow(target.getPosition().x - _position.x,2) +
			pow(target.getPosition().y - _position.y, 2));
	Angle direction = (float)atan2(_position.y - target.getPosition().y,
			_position.x - target.getPosition().x) / _pi * 180 ;

	if(distance < _lockDistance && (direction.getAngle() - DrawableObject::_direction.getAngle() < 5
			&& direction.getAngle() - DrawableObject::_direction.getAngle() > -5)
			&& (direction > _range.x && direction < _range.y)
			&& !TargetInvisible)
	{
		DrawableObject::_direction = direction;
		return true;
	}
	else
		return false;
}
Пример #2
0
void DrawStack3D::updatePositions() {

	tilt*=0.95;

	int len = stack.length();

	float cosTilt = cos(tilt);
	float sinTilt = sin(tilt);

	for(int i = 0; i < len; i++) {
		DrawableObject* e = stack.getElement(i);

		vec3 charPos = e->getPosition();

		float dy = charPos.y-camera.y;
		float dx = charPos.x-camera.x;
		float dz = charPos.z-camera.z;

		float charAngle = atan2f(dy, dx);

		float dAngle = mod(angle, 2.0f*PI) - mod(charAngle, 2.0f*PI);

		//Clamp dAngle between -PI and PI
		if(dAngle > PI) {
			dAngle -= PI*2.0f;
		}

		if(dAngle < -PI) {
			dAngle += PI*2.0f;
		}

		float distance = length(vec3(dx, dy, dz));

		//Used for weapon 'raycasts'.
		e->setPlayerAngle2(charAngle);
		e->setPlayerAngle(dAngle);
		e->setPlayerDistance(distance);
		//

		float absDAngle = abs(dAngle);

		distance = length(vec3(dx, dy, dz));

		if(distance > DETAIL_OBJECT_DESTROY_DISTANCE && e->entityType == 1) {
			//Destroy detail object.
			e->destroy = true;
		}

		if(distance > 500.0f || dAngle > PI/2 || dAngle < -PI/2) {
			e->setVisibility(false);
		} else {
			e->setVisibility(true);

			//Fake some field of view perspective stuff.
			float dX = dAngle*FIELD_OF_VIEW_WIDTH*(0.9f+0.1f*abs(sin(dAngle)));

			float dZ = 400.0f*(dz)/distance;

			float scale = 1.0f/distance;


			if(distance < PI) {
				dZ += cos(distance/2.0f)*150.0f;
			}



			//Tilt offsets:
			float oX = -sinTilt*dZ+cosTilt*dX;
			float oY = sinTilt*dX+cosTilt*dZ;


			e->setImageParameters(vec2(640+oX, 360+oY), scale, tilt);
			e->priority = scale;
		}
	}
}