Author Topic: Tiles, Sprites and Lofts/Loftemps  (Read 1962 times)

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Tiles, Sprites and Lofts/Loftemps
« on: April 05, 2022, 08:09:56 am »
I see tiles are 16x16x24

I see sprites 32x40

According to documentation loftemps are 16 x 16 x 12 and are double layered to it becomes 16x16x24, that part I can understand.

What I don't understand is how a sprite of 32x40 pixels can cover a tile of 16x16x24 (the diamonds) ?

How is this done/possible ?

Ok so from analyzing the graphics and drawing sprites manually and dividing width by 2 I think I am beginning to understand.

The left side of the sprite probably goes up,left 16 pixels or something or up 8 and right side goes right and up 8 or something.

but the height is 40... and the tile is supposed to be 24... so 40-24 = 16.

So probably top of tile goes back another 8...

So if my guess is correct then the sprite covers the tile more or less like this:

8                                5612
7                            34        34
6                        12                56
5                    90                        78
4               78                                 90
3          56                                          12
2      34                                                  34
1  12                                                          56
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
8 12                                                           56
7    34                                                    34
6        56                                            12
5             78                                  90
4                  90                         78
3                     12                 56
2                          34        34
1                              5612
                               bottom of tile and center.

So it seems it has 8 lines above and 8 lines below the normal 24 tile height, to form the diamond.

But now I am missing something, a tile is only 16x16x24.

So how can a sprite have 32 width and 40 height ?

Does a sprite paint over two tiles ?
« Last Edit: April 05, 2022, 08:34:44 am by Skybuck »

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #1 on: April 05, 2022, 09:14:34 am »
Ok I finally get it.

Since it's 3D a larger 2D sprite will actually contain 3D information, and since there are two dimensions it kinda makes sense.

^ 24

<---- -16, +16 ------->

but some of these movements are up/down to go diagonal which seems to be +8 or -8 down, top/bottom etc.

Here is a picture that clearifies this a bit: (this is the very first thing any openxcom doc should explain, took me a while to get this exactly... well almost exactly... still a bit fuzy about the center points top and bottom and perhaps corners.)





Offline kevL

  • Colonel
  • ****
  • Posts: 466
  • pitchforks and torches
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #2 on: April 05, 2022, 09:25:27 am »
this is the best page i've found describing isometric math (conversion between cartesian and isometric views)

https://clintbellanger.net/articles/isometric_math/

and here's a pic showing how sprites overlay other sprites. The black pixels are the borders of 32x40 sprites (but think of black as transparent).


ps. the coordinate system is arbitrary, decided by the programmer. Some use the top of the diamond as 0,0 while others use the top left corner of the draw surface as 0,0 ... elevation simply shifts the sprites up (or down, again depending on the coordinate system used).

the tricky part, as anyone who's worked on it can attest, is the sequence to draw things ...

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #3 on: April 05, 2022, 09:27:34 am »


Up is Z

But which is X and Y in the diamond ?

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #4 on: April 05, 2022, 09:30:33 am »
The link you posted does not describe the formula for when moving into Z direction, perhaps these formulas might still be somewhat usefull.

I always need to know how openXcom defines things... voxel x,y,z goes into a certain direction.

I assume tile and voxel coordinates go into the same direction.

I think bottom right corner might be 50, 50... so y might be right side, x left side... hmm

Offline kevL

  • Colonel
  • ****
  • Posts: 466
  • pitchforks and torches
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #5 on: April 05, 2022, 10:02:44 am »
The link you posted does not describe the formula for when moving into Z direction

... elevation simply shifts the sprites up (or down, again depending on the coordinate system used).

Quote
I always need to know how openXcom defines things... voxel x,y,z goes into a certain direction.

sorry I haven't looked at OxC code for a long time and wouldn't be comfortable stating those specifics. I imagine an increase in x shifts to the right, an increase in y shifts downward, and a (literal) increase in z also shifts downward ... for example, each tilepart has an MCD entry for "elevation" or similar -- it's usually a negative value that shifts a part's corresponding sprite upward on the screen. And elevation by Map level(s) should shift a sprite by multiples of <blargh> pixels per level (the exact value, before scaling for screen resolution, should be in or near Battlescape/Map::drawTerrain()

Quote
I assume tile and voxel coordinates go into the same direction.

i think that's a safe assumption ... /test

Quote
I think bottom right corner might be 50, 50... so y might be right side, x left side... hmm

uh, 0,0 (2d screenspace) is likely to be the top left corner. And 0,0,0 (3d tilespace) is likely to be close to there ...

Quote
But which is X and Y in the diamond ?

the x-axis goes upperleft to lowerright (west to east), the y-axis goes upperright to lowerleft (north to south) ... thats my best guess atm
« Last Edit: April 09, 2022, 03:48:19 am by kevL »

Offline kevL

  • Colonel
  • ****
  • Posts: 466
  • pitchforks and torches
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #6 on: April 05, 2022, 11:18:22 am »
here's a northwall sprite on its 32x40 grid

and how it draws in relation to the Map tiles (cuboids)

and its LoFTs

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #7 on: April 05, 2022, 11:31:25 am »
First of all, voxel space and sprites can be unrelated, game could have 100x100 graphic and it would still work fine.
Only moment when there is required transition is when game render bullets where they position is in voxels but displayed in 2d.
You can easy check how game convert coordinates between them.

Offline kevL

  • Colonel
  • ****
  • Posts: 466
  • pitchforks and torches
    • View Profile
Re: Tiles, Sprites and Lofts/Loftemps
« Reply #8 on: April 05, 2022, 11:16:16 pm »
here's the conversion codes for OxC

https://github.com/OpenXcom/OpenXcom/blob/94640aab1279ae268e0420a7b5c99cc44eb09473/src/Battlescape/Camera.cpp#L431

and similar in MapView2

https://github.com/kevL/OpenXCOM.Tools/blob/f5eccf594eb08adebcbec7db5759d20a486aa81e/MapView/Forms/MainView/MainViewPanel/MainViewOverlay.cs#L2212


ps. that level of math spooks me out ...

pps. projectile trajectory appears to be converted and traced at the start of Map::drawTerrain()

https://github.com/OpenXcom/OpenXcom/blob/94640aab1279ae268e0420a7b5c99cc44eb09473/src/Battlescape/Map.cpp#L482

( note: I seem to recall that projectiles also cast a shadow )

/anyway, there it is :|