1

I'm working with SMFL/C++ to make a 2D isometric game engine, i got this when i do the isometric calculations :

enter image description here

Here is my formula to calculate isometric coordinates in my 2D engine : For I-J coordinates i have :

x = (I - J) * (tileWidth / 2);
y = (J + I) * (tileHeight / 2);

//Totally working with classics tiles

EDIT: My problem is due to my tiles' shape wich is a cube, but i don't have a clue about how to fix it. Did i really have to do somes complicated maths to handle 3D objetcs(i would rather avoid this) or i can just change the formula a little bit ?

EDIT 2: Solution : int isoY = (x + y) * (height / 4);

Madz
  • 287
  • 3
  • 14

1 Answers1

1

First if it is a 2D engine I wonder why there are 3 dimensions, why and how you use z in your engine.

Assuming you want to have a plan of tiles in isometric projection ((x,y) in pixels) given the coordinates (I,J) in number of tiles in orthographic projection. In that case your formula for x and y are fine by me given tileWidth and tileHeight are correct (i.e. value in isometric projection). And you shouldn't have to use any z.

On the other hand if your problem is to get (x,y) pixels coordinates of a 3D object given (x,y,z) cartesian coordinates i suggest you read this: Computing the Pixel Coordinates of a 3D Point

In case i assumed wrong I'll edit or delete.

Rbtnk
  • 163
  • 1
  • 2
  • 11
  • It's isometric projection, and you're right, now i use z only for layers' position, my bad. But i'm still wondering why is my map not a perfect diamong :/ – Madz Nov 13 '15 at 15:31
  • I edited my post. I don't understand why it's not working since i read about this formula everywhere on internet and it's working for everybody... And the error isn't about how i coded, because the formula is exactly wrote(writed ?) like this :/ `int isoX = (x - y) * (width / 2); int isoY = (y + x) * (height / 2);` – Madz Nov 13 '15 at 15:38
  • What are the values of width and height? Because it should be the value in the isometric projection. (i edited in that way). And how do you draw your tiles? – Rbtnk Nov 13 '15 at 15:51
  • For the isometric calculation i have 2 `for loop` : `for(int y = 0; y < mapHeightInBlocks; y++` and in this loop i have : `for(int x = 0; x < mapWidthInBlocks; x++)` and then i give this x and y to my tile which calculate its isometric position. For `tileWidth` i have : 98, and `tileHeight : 97`. `mapHeightInBlocks` and same for width are the dimension of the map in blocks. I try to be able to create the map with the size i want and it's working, but no perfect diamond – Madz Nov 13 '15 at 16:11
  • The width and height are not the value of the edge of your tiles but the value of the isometric tile projected on the screen. I'll give you the math or a link later if you don't get it in between ( I'm on my phone). – Rbtnk Nov 13 '15 at 16:20
  • Is this the thing about rotate to 45° or something ? Sorry i'm not sure if i got it (^_ ^) here tileWidth and tileHeight are my tile's dimension. but you're right, this is not isometric hmm – Madz Nov 13 '15 at 16:22
  • Take a look at this: clintbellanger.net/articles/isometric_math/. I'll update the answer later – Rbtnk Nov 13 '15 at 16:27
  • i know why i have this problem after 2 nights spent on it ha ha and finally understand what u meant why the value of the edge(I didn't got that before i tested my code with normal tiles...) – Madz Nov 14 '15 at 02:34
  • I tried `(x + y) * (height / 4)` and it worked, thanks ! – Madz Nov 14 '15 at 02:44