Beispiel #1
0
/**
 * @brief Only moves the camera to the given target location if its not yet close enough
 */
void CL_CheckCameraRoute (const pos3_t from, const pos3_t target)
{
	pos3_t current;
	VecToPos(cl.cam.origin, current);
	const float minDistToMove = 4.0f;
	const float dist = Vector2Dist(target, current);
	if (dist < minDistToMove) {
		if (target[2] != current[2])
			Cvar_SetValue("cl_worldlevel", target[2]);
		return;
	}
	CL_CameraRoute(from, target);
}
Beispiel #2
0
/**
 * @brief Center the camera on the local entity's origin
 * @param le The local entity which origin is used to center the camera
 * @sa CL_CenterView
 * @sa CL_ViewCenterAtGridPosition
 * @sa CL_CameraRoute
 */
void LE_CenterView (const le_t* le)
{
	if (!cl_centerview->integer)
		return;

	assert(le);
	if (le->team == cls.team) {
		const float minDistToMove = 4.0f * UNIT_SIZE;
		const float dist = Vector2Dist(cl.cam.origin, le->origin);
		if (dist < minDistToMove) {
			pos3_t currentCamPos;
			VecToPos(cl.cam.origin, currentCamPos);
			if (le->pos[2] != currentCamPos[2])
				Cvar_SetValue("cl_worldlevel", le->pos[2]);
			return;
		}

		VectorCopy(le->origin, cl.cam.origin);
	} else {
		pos3_t pos;
		VecToPos(cl.cam.origin, pos);
		CL_CheckCameraRoute(pos, le->pos);
	}
}
Beispiel #3
0
/**
 * @brief Calculate some radar values that won't change during a mission
 * @note Called for every new map (client_state_t is wiped with every
 * level change)
 */
static void UI_InitRadar (const uiNode_t* node)
{
	int i, j;
	const vec3_t offset = {MAP_SIZE_OFFSET, MAP_SIZE_OFFSET, MAP_SIZE_OFFSET};
	float distAB, distBC;
	vec2_t gridSize;		/**< Size of the whole grid (in tiles units) */
	vec2_t nodepos;
	vec2_t min;
	vec2_t max;

	UI_FreeRadarImages();
	UI_BuildRadarImageList(CL_GetConfigString(CS_TILES), CL_GetConfigString(CS_POSITIONS));

	UI_GetNodeAbsPos(node, nodepos);
	radar.x = nodepos[0] + node->box.size[0] / 2;
	radar.y = nodepos[1] + node->box.size[1] / 2;

	/* only check once per map whether all the needed images exist */
	for (j = 0; j < radar.numImages; j++) {
		hudRadarImage_t* tile = &radar.images[j];
		/* map_mins, map_maxs */
		for (i = 0; i < PATHFINDING_HEIGHT; i++) {
			char imagePath[MAX_QPATH];
			const image_t* image;
			if (!UI_CheckRadarImage(tile->name, i + 1)) {
				if (i == 0) {
					/* there should be at least one level */
					Com_Printf("No radar images for map: '%s'\n", tile->name);
					radar.numImages = 0;
					return;
				}
				continue;
			}

			Com_sprintf(imagePath, sizeof(imagePath), "radars/%s_%i", tile->name, i + 1);
			tile->path[i] = Mem_StrDup(imagePath);
			tile->maxlevel++;

			image = R_FindImage(va("pics/%s", tile->path[i]), it_pic);
			tile->width = image->width;
			tile->height = image->height;
			if (tile->isTile) {
				tile->gridWidth = round(image->width / 94.0f);
				tile->gridHeight = round(image->height / 94.0f);
				tile->mapWidth = tile->gridWidth * 8 * UNIT_SIZE;
				tile->mapHeight = tile->gridHeight * 8 * UNIT_SIZE;
			} else {
				tile->mapX = cl.mapData->mapBox.getMinX();
				tile->mapY = cl.mapData->mapBox.getMinY();
				tile->mapWidth = cl.mapData->mapBox.getWidthX();
				tile->mapHeight = cl.mapData->mapBox.getWidthY();
			}
		}
		if (tile->isTile) {
			tile->mapY = cl.mapData->mapBox.getMaxY() - tile->mapY - tile->mapHeight;
		}
	}

	/* center tiles into the minMap/maxMap */
	Vector2Copy(cl.mapData->mapBox.maxs, min);
	Vector2Copy(cl.mapData->mapBox.mins, max);
	for (j = 0; j < radar.numImages; j++) {
		hudRadarImage_t* tile = &radar.images[j];
		if (tile->mapX < min[0])
			min[0] = tile->mapX;
		if (tile->mapY < min[1])
			min[1] = tile->mapY;
		if (tile->mapX + tile->mapWidth > max[0])
			max[0] = tile->mapX + tile->mapWidth;
		if (tile->mapY + tile->mapHeight > max[1])
			max[1] = tile->mapY + tile->mapHeight;
	}
	/* compute translation */
	min[0] = cl.mapData->mapBox.getMinX() + (cl.mapData->mapBox.getWidthX() - (max[0] - min[0])) * 0.5 - min[0];
	min[1] = cl.mapData->mapBox.getMinY() + (cl.mapData->mapBox.getWidthY() - (max[1] - min[1])) * 0.5 - min[1];
	for (j = 0; j < radar.numImages; j++) {
		hudRadarImage_t* tile = &radar.images[j];
		tile->mapX += min[0];
		tile->mapY += min[1];
	}

	/* get the three points of the triangle */
	VectorSubtract(cl.mapData->mapBox.mins, offset, radar.a);
	VectorAdd(cl.mapData->mapBox.maxs, offset, radar.c);
	VectorSet(radar.b, radar.c[0], radar.a[1], 0);

	distAB = (Vector2Dist(radar.a, radar.b) / UNIT_SIZE);
	distBC = (Vector2Dist(radar.b, radar.c) / UNIT_SIZE);

	UI_GetRadarWidth(node, gridSize);

	/* get the dimensions for one grid field on the radar map */
	radar.gridWidth = radar.w / distAB;
	radar.gridHeight = radar.h / distBC;

	/* shift the x and y values according to their grid width/height and
	 * their gridX and gridY position */
	{
		const float radarLength = std::max(1.0f, fabsf(gridSize[0]));
		const float radarHeight = std::max(1.0f, fabsf(gridSize[1]));
		/* image grid relations */
		const float gridFactorX = radar.w / radarLength;
		const float gridFactorY = radar.h / radarHeight;
		for (j = 0; j < radar.numImages; j++) {
			hudRadarImage_t* image = &radar.images[j];

			image->x = (image->gridX - radar.gridMin[0]) * gridFactorX;
			image->y = radar.h - (image->gridY - radar.gridMin[1]) * gridFactorY - image->height;
		}
	}

	/* now align the screen coordinates like it's given by the node */
	radar.x -= (radar.w / 2);
	radar.y -= (radar.h / 2);
}