Precision loss when transforming from cartesian to isometric

Posted by Justin Skiles on Game Development See other posts from Game Development or by Justin Skiles
Published on 2013-09-19T04:07:31Z Indexed on 2013/11/03 4:14 UTC
Read the original article Hit count: 298

My goal is to display a tile map in isometric projection. This tile map has 25 tiles across and 25 tiles down. Each tile is 32x32. See below for how I'm accomplishing this.

World Space

enter image description here

World Space to Screen Space Rotation (45 degrees)

enter image description here

Using a 2D rotation matrix, I use the following:

double rotation = Math.PI / 4;
double rotatedX = ((tileWorldX * Math.Cos(rotation)) - ((tileWorldY * Math.Sin(rotation)));
double rotatedY = ((tileWorldX * Math.Sin(rotation)) + (tileWorldY * Math.Cos(rotation)));

World Space to Screen Space Scale (Y-axis reduced by 50%)

enter image description here

Here I simply scale down the Y value by a factor of 0.5.

Problem

And it works, kind of. There are some tiny 1px-2px gaps between some of the tiles when rendering. I think there's some precision loss somewhere, or I'm not understanding how to get these tiles to fit together perfectly. I'm not truncating or converting my values to non-decimal types until I absolutely have to (when I pass to the render method, which only takes integers). I'm not sure how to guarantee pixel perfect rendering precision when I'm rotating and scaling on a level of higher precision. Any advice? Do I need to supply for information?

© Game Development or respective owner

Related posts about rendering

Related posts about matrix