-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#200] implement isometric positioning
- Loading branch information
Showing
14 changed files
with
367 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
2d/src/main/java/de/bitbrain/braingdx/tmx/IsometricPositionTranslator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.bitbrain.braingdx.tmx; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
|
||
public class IsometricPositionTranslator implements PositionTranslator { | ||
|
||
private final State state; | ||
private final Vector2 xAxis, yAxis; | ||
|
||
public IsometricPositionTranslator(State state) { | ||
this.state = state; | ||
this.xAxis = new Vector2(); | ||
this.yAxis = new Vector2(); | ||
} | ||
|
||
@Override | ||
public float toWorldX(int indexX) { | ||
return toWorldX(indexX * state.getCellWidth()); | ||
} | ||
|
||
@Override | ||
public float toWorldY(int indexY) { | ||
return toWorldY(indexY * state.getCellHeight()); | ||
} | ||
|
||
@Override | ||
public float toWorldX(float mapX) { | ||
return toWorld(mapX, 0f).x; | ||
} | ||
|
||
@Override | ||
public float toWorldY(float mapY) { | ||
return toWorld(0f, mapY).y; | ||
} | ||
|
||
@Override | ||
public Vector2 toWorld(float x, float y) { | ||
xAxis.set(state.getCellWidth() / 2f, -state.getCellHeight() / 2f); | ||
yAxis.set(state.getCellWidth() / 2f, state.getCellHeight() / 2f); | ||
float scalar = yAxis.len() / state.getCellHeight(); | ||
return xAxis.nor().scl(x).scl(scalar) | ||
.add(yAxis.nor().scl(y).scl(scalar)) | ||
.add(0f, state.getCellHeight() / 2f); | ||
} | ||
|
||
@Override | ||
public float toMapX(float worldX) { | ||
return worldX; | ||
} | ||
|
||
@Override | ||
public float toMapY(float worldY) { | ||
return worldY; | ||
} | ||
|
||
@Override | ||
public int toIndexX(float worldX) { | ||
float mapX = toMapX(worldX); | ||
return (int) Math.floor(mapX / state.getCellWidth()); | ||
} | ||
|
||
@Override | ||
public int toIndexY(float worldY) { | ||
float mapY = toMapY(worldY); | ||
return (int) Math.floor(mapY / state.getCellHeight()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
2d/src/main/java/de/bitbrain/braingdx/tmx/OrthogonalPositionTranslator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package de.bitbrain.braingdx.tmx; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
|
||
public class OrthogonalPositionTranslator implements PositionTranslator { | ||
|
||
private final State state; | ||
|
||
public OrthogonalPositionTranslator(State state) { | ||
this.state = state; | ||
} | ||
|
||
@Override | ||
public float toWorldX(int indexX) { | ||
return (float) Math.floor(indexX * state.getCellWidth()); | ||
} | ||
|
||
@Override | ||
public float toWorldY(int indexY) { | ||
return (float) Math.floor(indexY * state.getCellHeight()); | ||
} | ||
|
||
@Override | ||
public float toWorldX(float mapX) { | ||
return mapX; | ||
} | ||
|
||
@Override | ||
public float toWorldY(float mapY) { | ||
return mapY; | ||
} | ||
|
||
@Override | ||
public Vector2 toWorld(float x, float y) { | ||
return new Vector2(x, y); | ||
} | ||
|
||
@Override | ||
public float toMapX(float worldX) { | ||
return worldX; | ||
} | ||
|
||
@Override | ||
public float toMapY(float worldY) { | ||
return worldY; | ||
} | ||
|
||
@Override | ||
public int toIndexX(float worldX) { | ||
return calculateIndex(worldX, state.getCellWidth()); | ||
} | ||
|
||
@Override | ||
public int toIndexY(float worldY) { | ||
return calculateIndex(worldY, state.getCellHeight()); | ||
} | ||
|
||
private static int calculateIndex(float value, float cellSize) { | ||
return (int) Math.round(Math.floor(value / cellSize)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
2d/src/main/java/de/bitbrain/braingdx/tmx/PositionTranslator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.bitbrain.braingdx.tmx; | ||
|
||
import com.badlogic.gdx.math.Vector2; | ||
|
||
/** | ||
* Translates positions depending on the current map orientation | ||
*/ | ||
public interface PositionTranslator { | ||
|
||
float toWorldX(int indexX); | ||
|
||
float toWorldY(int indexY); | ||
|
||
float toWorldX(float mapX); | ||
|
||
float toWorldY(float mapY); | ||
|
||
Vector2 toWorld(float x, float y); | ||
|
||
float toMapX(float worldX); | ||
|
||
float toMapY(float worldY); | ||
|
||
int toIndexX(float worldX); | ||
|
||
int toIndexY(float worldY); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
2d/src/main/java/de/bitbrain/braingdx/tmx/PositionTranslatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.bitbrain.braingdx.tmx; | ||
|
||
interface PositionTranslatorFactory { | ||
PositionTranslator create(State state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.