MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / convertScreenToMap

Method convertScreenToMap

src/Battlescape/Camera.cpp:458–474  ·  view source on GitHub ↗

* Converts screen coordinates to map coordinates. * @param screenX Screen x position. * @param screenY Screen y position. * @param mapX Map x position. * @param mapY Map y position. */

Source from the content-addressed store, hash-verified

456 * @param mapY Map y position.
457 */
458void Camera::convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const
459{
460 // add half a tileheight to the mouseposition per layer we are above the floor
461 screenY += (-_spriteWidth/2) + (_mapOffset.z) * ((_spriteHeight + _spriteWidth / 4) / 2);
462
463 // calculate the actual x/y pixelposition on a diamond shaped map
464 // taking the view offset into account
465 *mapY = - screenX + _mapOffset.x + 2 * screenY - 2 * _mapOffset.y;
466 *mapX = screenY - _mapOffset.y - *mapY / 4 - (_spriteWidth/4);
467
468 // to get the row&col itself, divide by the size of a tile
469 *mapX /= (_spriteWidth / 4);
470 *mapY /= _spriteWidth;
471
472 minMaxInt(mapX, -1, _mapsize_x);
473 minMaxInt(mapY, -1, _mapsize_y);
474}
475
476/**
477 * Converts map coordinates X,Y,Z to screen positions X, Y.

Callers 2

drawTerrainMethod · 0.80
setSelectorPositionMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected