Friday, 26 February 2016


Sometimes making things easy makes things harder.

Since we just have a single basic coordinate system for the whole game, and a grid system to tell the player where to go on the pitch, the game doesn't have any local/world transformations built in.

This means, if we don't want to manually configure each position twice (once for facing north and once for facing south), and we don't want to calculate a rotated point in game, each frame for each player (we don't!), then the tactics creator needs some fancy goings on to export the target sectors for both orientations.

It's more of a brainphuck than it first seems!

Anyway, after pulling my hair out for a few hours trying to come up with an elegant mathematical solution for rotating target sectors (there isn't one dammit!), I came up with this little snippet, which I think is rather nifty:

1:  // for all ball positions  
2:  for (int j = 0; j < PositionList.SECTORS; ++j) {  
4:    // 1. get the reversed ball position  
5:    int x = grid.getReversed(j);  
7:    // 2. get the players position for the new perspective  
8:    int p = player.positions.get(x);  
10:   // 3. flip the player position  
11:   int r = grid.getReversed(p);  
13:   // save flipped position to list  
14:   player.positions_flipped.set(j, r);  
15:  }  

Basically, when creating the grid to begin with, we save a list of the sector id's in reverse order. Then when calculating the sector for a player facing south, we take the original sector (configured in tactics editor) and do the following steps:

1. Find what the ball sector number would be if the grid was reversed. This is like saying "if I was playing down the pitch, which sector would the ball be in from my perspective?"

2. Get the players configured target sector for this new ball sector.

3. Like step 1, find what this target sector would look like from the perspective of a player facing south.

4. Voila.

The clever, "powerful" bit is that the list of reversed indices magically tells you how any sector will look from the perspective of a player facing the other way. This will be obvious to some, but took me a bit of working out!

No comments:

Post a Comment