:title Some tips
:h3 Placing ISO tiles on a map.

Placing ISO tiles might be a problem if you don't know how to handle them.
In maps with rectangular tiles the checkbox "allow tile overlap" ensures that you can not place tiles that overlap. 

If you use that checkbox (unchecked) in ISO mode, you can place only a tile on every "second" spacing" - this is not fun. (this happens since ISO tiles are made from normal "rectangle" tiles).
To have a similar behaviour do the following:
- build a grid fitting for your ISO tiles
- enable the grid
- enable "snap" to grid
- check "allow tile overlap" (allowing overlap!)
- check "single position" (tiles in one map can not be placed on exactly the same position)

Voila - you can now easily place ISO tiles that don't overlap!


:h3 Programmers point - where in an ISO-Map am I?
Maping mouse coordinates to the correct ISO tile seems to be one of the big questions of the 20th century. Here is how I do the correct mapping:~~

I will use an even, regular, complete and ordered ISO map.

height is the height of one ISO-tile, width... dito

I can divide the map in "half columns" and "half rows".
I number these half rows and half columns and will have even and odd half columns.
Easy example:~~
a ISO-tile might be 64x48 pixel~~
than even columns are: 0, 64, 128...~~
and odd columns are: 32, 96, 160...~~
(rows respectivly)~~


Than I know: ~~
- the mapHeight of the map is (n+1/2)*height
- the mapWidth of the map is (m+1/2)*width
- every other row/column starts at an offset of 1/2 heigth or width
- each point lies "over" two rectangles of the tile map, one of the rectangles starts allways at an even half column and the other starts allways at an odd half column.

Since I have to start somewhere I calculate the "even" column for my point.

This is easly done by:~~
::___int evenBaseX = (x/width)*width;~~
___int evenBaseY = (y/height)*height;~~
::~~
The base is than the upper left corner (point 0,0 from the tile) of the tile.~~

The offset from that base to the point position I am interested in than is:~~
::___int baseOffsetX=x%evenBaseX;~~
___int baseOffsetY=y%evenBaseY;~~
::~~
Consider the following crude picture.

:image ISOCoordinates.png|ISO Coordinates|fileopen

The above calculated offsets all lie in one ISO-Rectangle. All I have to do now is determine the quadrants, which is also easily done:~~

::___int quadrantColumnIndex = (x / (width/2) )%2; ~~
___int quadrantRowIndex = (y / (height/2) )%2; ~~
::

Once I have the quadrant I can use an easy formular to determine where the point lies in respect to the diagonal.

You use a Vectorproduct, which is defined by:~~
**::Vectorproduct: u x v = u.x * v.y - v.x * u.y~~ ~~::**

If you define the diagonal and the point we are interested in as follows.
The diagonal line is defined by to points: ~~
::u = line(i+1) - line(i)::~~

The point we are interested in, in relation to the line: ~~
::v = p - line(i)::~~

The result of the vectorproduct gives us the answer whether the point is on the left side, the ride side or on the diagonal.~~
::~~
___u x v < 0 => p lies left of the line~~
___u x v = 0 => p lies on the line~~
___u x v > 0 => p lies right of the line   ~~   
::~~

One code example for the test in "stupidish java":~~
::~~ 
___if ( (quadrantColumnIndex==0) && (quadrantRowIndex==0) )~~ 
___{~~ 
            ______int diagX1 = 0;~~ 
            ______int diagY1 = height/2;~~ 
            ______int diagX2 = width/2;~~ 
            ______int diagY2 = 0;~~ 
            
            ~~ 
            
            ______int ux = diagX2-diagX1;~~ 
            ______int uy = diagY2-diagY1;~~ 
            ~~ 
            ______int vx = x-diagX1;~~ 
            ______int vy = y-diagY1;~~ 
            ~~ 
            ______int uxv = ux*vy-vx*uy;~~ 
            ~~ 
            ______if (uxv<0) return 1; / / 1 return means it is not on ISO tile in quadrant 1~~ 
            ______return 0; / / 0 return means is on ISO-Tile~~ 
___}     
::            

If you do that for the correct quadrant you know that:   ~~ 
- either the even tile is correct (above returns 0)
- the neighbouring odd tile (in relation to the quadrant) is the correct tile
- (or null, if we are out of bounds)

         
