Installer project example/Game/Source/Map.cpp
// L05: DONE 2: Add orthographic world to map coordinates
DONE 2: Add orthographic world to map coordinates
DONE 2 : Add orthographic world to map coordinates
iPoint Map::WorldToMap(int x, int y) const
{
	iPoint ret(0, 0);
	if (data.type == MAPTYPE_ORTHOGONAL)
	{
		ret.x = x / data.tileWidth;
		ret.y = y / data.tileHeight;
	}
	else if (data.type == MAPTYPE_ISOMETRIC)
	{
		float half_width = data.tileWidth * 0.5f;
		float half_height = data.tileHeight * 0.5f;
		ret.x = int((x / half_width + y / half_height) / 2);
		ret.y = int((y / half_height - (x / half_width)) / 2);
	}
	else
	{
		LOG("Unknown map type");
		ret.x = x; ret.y = y;
	}
	return ret;
}
iPoint Map :: WorldToMap ( int x , int y ) const { iPoint ret ( 0 , 0 ) ; if ( data . type == MAPTYPE_ORTHOGONAL ) { ret . x = x / data . tileWidth ; ret . y = y / data . tileHeight ; } else if ( data . type == MAPTYPE_ISOMETRIC ) { float half_width = data . tileWidth * 0.5f ; float half_height = data . tileHeight * 0.5f ; ret . x = int ( ( x / half_width + y / half_height ) / 2 ) ; ret . y = int ( ( y / half_height - ( x / half_width ) ) / 2 ) ; } else { LOG ( " " ) ; ret . x = x ; ret . y = y ; } return ret ; }
L05: DONE 2: Add orthographic world to map coordinates
L05 : DONE 2 : Add orthographic world to map coordinates
// L05: DONE 3: Add the case for isometric maps to WorldToMap