mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-11 11:27:16 +07:00
Improved isometric camera API
Documented isometric camera API Implemented pix and tile offsets instead of just offset Made pix and tile offsets private -- pix offset set via offset and tile offset set automatically toTile50 may be deprecated in the future if I cannot find a use for it (tile offset may have superseded it)
This commit is contained in:
parent
1d6365dcbe
commit
d6105d9f9a
@ -8,13 +8,16 @@ import com.riiablo.util.EngineUtils;
|
||||
public class IsometricCamera extends OrthographicCamera {
|
||||
|
||||
private final Vector2 tmp = new Vector2();
|
||||
public final Vector2 offset = new Vector2();
|
||||
public final Vector2 position = new Vector2();
|
||||
|
||||
private final Vector2 pixOffset = new Vector2();
|
||||
private final Vector2 tileOffset = new Vector2();
|
||||
|
||||
public IsometricCamera() {}
|
||||
|
||||
public void offset(float x, float y) {
|
||||
offset.set(x, y);
|
||||
pixOffset.set(x, y);
|
||||
toWorld(pixOffset.x, pixOffset.y, tileOffset.setZero());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,7 +29,7 @@ public class IsometricCamera extends OrthographicCamera {
|
||||
public void translate(float x, float y) {
|
||||
position.add(x, y);
|
||||
toScreen(position.x, position.y, tmp);
|
||||
super.position.set(tmp, 0).add(offset.x, offset.y, 0);
|
||||
super.position.set(tmp, 0).add(pixOffset.x, pixOffset.y, 0);
|
||||
}
|
||||
|
||||
public void set(Vector2 vec) {
|
||||
@ -36,44 +39,72 @@ public class IsometricCamera extends OrthographicCamera {
|
||||
public void set(float x, float y) {
|
||||
position.set(x, y);
|
||||
toScreen(position.x, position.y, tmp);
|
||||
super.position.set(tmp, 0).add(offset.x, offset.y, 0);
|
||||
super.position.set(tmp, 0).add(pixOffset.x, pixOffset.y, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts tile coords to screen coords.
|
||||
*/
|
||||
public Vector2 toScreen(Vector2 worldCoords) {
|
||||
return toScreen(worldCoords.x, worldCoords.y, worldCoords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts tile coords to screen coords.
|
||||
*/
|
||||
public Vector2 toScreen(float x, float y, Vector2 dst) {
|
||||
return EngineUtils.worldToScreenCoords(x, y, dst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts screen coords to tile coords.
|
||||
*/
|
||||
public Vector2 toWorld(Vector2 screenCoords) {
|
||||
return toWorld(screenCoords.x, screenCoords.y, screenCoords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts screen coords to tile coords.
|
||||
*/
|
||||
public Vector2 toWorld(float x, float y, Vector2 dst) {
|
||||
x /= Tile.SUBTILE_WIDTH50;
|
||||
y /= Tile.SUBTILE_HEIGHT50;
|
||||
dst.x = ( x - y) / 2 - 0.5f;
|
||||
dst.y = (-x - y) / 2 - 0.5f;
|
||||
dst.x = ( x - y) / 2 - tileOffset.x;
|
||||
dst.y = (-x - y) / 2 - tileOffset.y;
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds tile coords to the floor integer tile coords from the specified float tile coords.
|
||||
*/
|
||||
public Vector2 toTile(Vector2 worldCoords) {
|
||||
return toTile(worldCoords.x, worldCoords.y, worldCoords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds tile coords to the floor integer tile coords from the specified float tile coords.
|
||||
*/
|
||||
public Vector2 toTile(float x, float y, Vector2 dst) {
|
||||
x += tileOffset.x;
|
||||
y += tileOffset.y;
|
||||
dst.x = x < 0 ? MathUtils.floor(x) : MathUtils.floorPositive(x);
|
||||
dst.y = y < 0 ? MathUtils.floor(y) : MathUtils.floorPositive(y);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds tile coords to the closest integer tile coords from the specified float tile coords.
|
||||
*/
|
||||
public Vector2 toTile50(Vector2 worldCoords) {
|
||||
return toTile50(worldCoords.x, worldCoords.y, worldCoords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds tile coords to the closest integer tile coords from the specified float tile coords.
|
||||
*/
|
||||
public Vector2 toTile50(float x, float y, Vector2 dst) {
|
||||
x += tileOffset.x;
|
||||
y += tileOffset.y;
|
||||
dst.x = x < 0 ? MathUtils.round(x) : MathUtils.roundPositive(x);
|
||||
dst.y = y < 0 ? MathUtils.round(y) : MathUtils.roundPositive(y);
|
||||
return dst;
|
||||
|
@ -175,7 +175,7 @@ public class CameraTool extends ApplicationAdapter {
|
||||
iso.unproject(vec2);
|
||||
iso.toWorld(vec2);
|
||||
wrld.set(vec2);
|
||||
iso.toTile50(vec2);
|
||||
iso.toTile(vec2);
|
||||
loc.set(vec2);
|
||||
iso.toScreen(vec2);
|
||||
|
||||
@ -189,7 +189,7 @@ public class CameraTool extends ApplicationAdapter {
|
||||
} shapes.end();
|
||||
|
||||
pos.set(iso.position);
|
||||
iso.toTile50(pos);
|
||||
iso.toTile(pos);
|
||||
|
||||
shapes.begin(ShapeRenderer.ShapeType.Filled); {
|
||||
vec2.set(pos);
|
||||
|
Loading…
Reference in New Issue
Block a user