Isometric issues

I have a little project, I am rendering paths over an isometric map using:

		xOffset = GameMap.tileWidth * GameMap.unitScale;
		yOffset = GameMap.tileHeight * GameMap.unitScale;

public static Vector2 orthToIso(float x, float y) {
		float drawingPosX = x * xOffset / 2 + y * xOffset / 2;
		float drawingPosY = y * yOffset / 2 - x * yOffset / 2;
		return new Vector2(drawingPosX, drawingPosY);
	}

This works great, the issue I have is being able to have a path go to the tile the mouse/touch is over

the mouse/touch position is going to be translated to iso via the above as part of the render loop. What I need help with is offseting the above code so that when the orth->iso kicks in, it lines up…

I hope this makes sense :slight_smile:

Anybody?

The mouse position is already in Isometric space, you need to translate that back to orthographic space to determine the click point. I have 3 functions that I use in my engine for this.


public static Point isoToCoarseWorld(Point isoPoint, Point viewportOrigin, Dimension isoDims) {
	int xOrg = viewportOrigin.x + (isoDims.width >> 1);
	int yOrg = viewportOrigin.y;

	int i = (int)Math.floor(((isoPoint.y - yOrg)/(double)isoDims.height
	        + (isoPoint.x - xOrg)/(double)isoDims.width) * 32);
	int j = (int)Math.floor(((isoPoint.y - yOrg)/(double)isoDims.height
        	- (isoPoint.x - xOrg)/(double)isoDims.width) * 32);

	return new Point(i, j);
}

public static Point coarseWorldToTile(Point coarseWorldPoint, Dimension worldTileDims) {
	return new Point((int)Math.floor(coarseWorldPoint.x / worldTileDims.width)
        	,(int)Math.floor(coarseWorldPoint.y / worldTileDims.height));
}

public static Point coarseWorldToTileFine(Point coarseWorldPoint, Dimension worldTileDims) {
	return new Point((coarseWorldPoint.x % worldTileDims.width)
        	,(coarseWorldPoint.y % worldTileDims.height));
}

Where the worldTileDims are 32x32 and the isoDims are 64x32. isoToCoarseWorld takes an isometric point and converts it into raw orthographic space. The other two functions are used to determine which tile that raw point is in, and the offset within the tile respectively.

When working out any path finding or logic, you should be working in orthographic space. Isometric space is only used for viewing. I think this is what you were asking about. If not could you clarify a bit?

Thank you for your fantastic reply. I have spent hours trying to figure this out. (Math is not my strong point). Thanks again.

No problem. Math isn’t my strong point either. I had to dig around on the Internet for what seems like forever before finally finding out what those functions should look like. They seem to work reliably. :slight_smile:

I have to rewrite it a little (due to float positions and Vector2 over Point). Could you please clarify what: isoPoint, viewportOrigin and isoDims are please. Thank you

Sure thing. isoDims are the dimensions of my isometric tiles (64x32px in my case). isoPoint is any point in isometric space; basically use the point that you get through a Java mouse event. viewportOrigin is an orthographic based measurement of how far the map is offset in the X and Y directions. This is used when scrolling the map. Please let me know if I can be of further assistance. :slight_smile: