我正在尝试为游戏绘制基于平铺的地板。
基本上每个瓷砖都有一个高度值,我试图让每个短号以平滑的方式连接到相邻的瓷砖。因此,如果瓷砖高度为2,并且旁边的瓷砖高度为3,那么它们将平滑地连接在斜坡上。
这是我现在的代码:
- 请参阅下面的更新代码 -
瓷砖的高度由Tile.getCenter()获得; 我不知道从哪里开始,我使用的是libGDX。
px和py只是加载点的中心,floor是楼层的LibGDX模型批次,希望最终包含每个楼层时间。
提前致谢!
-Bc
- 编辑 -
再多一点信息,顶点类基本上只存储两个整数。
tl,tr,bl,br,是让瓷砖知道左上方高度,右上方高度(等)。 - 我将所有内容重命名为更清晰
这个类只是为了找到我需要的角度,基本上每个角都被渲染,一旦我有了,我就可以找到自己渲染的方法。
在tl,tr等的音符上我应该找到角落吗?还是两边的中心?我之前从未做过3d gfx。
- 编辑3 -
我自己做了一些工作,希望这更接近:
private Map<Vertex, Tile> tiles = new HashMap<Vertex, Tile>();
public float getMode(float[] data)
{
int total = 0;
for (int i = 1; i < data.length; i++){
total += data[i];
}
return total / data.length;
}
protected void loadTiles(int px, int py){
//load tile from file
int FIXTHISTOSIZE = 10;
for (int x = px - (FIXTHISTOSIZE / 2); x <= FIXTHISTOSIZE; x++){
for (int y = (py - FIXTHISTOSIZE / 2); y <= FIXTHISTOSIZE; y++){
int aY = py - y;
int aX = px - x;
Tile tile = new Tile(aX, aY);
tiles.put(new Vertex(aX, aY) , tile);
}
}
for (int x = px - (FIXTHISTOSIZE / 2); x <= FIXTHISTOSIZE; x++){
for (int y = py - (FIXTHISTOSIZE / 2); y <= FIXTHISTOSIZE; y++){
int aY = py + y;
int aX = px + x;
Vertex pos = new Vertex(aX, aY);
float TOP_LEFT = -65536, TOP_RIGHT = -65536, BOTTOM_LEFT = -65536, BOTTOM_RIGHT = -65536; //TODO these should be 0, they are this number to demonstrate unloaded tiles for now
Tile TILE_CENTER = tiles.get(pos);
Tile TILE_TOP_RIGHT = tiles.get(new Vertex(aX + 1, aY + 1));
Tile TILE_TOP = tiles.get(new Vertex(aX, aY + 1));
Tile TILE_RIGHT = tiles.get(new Vertex(aX + 1, aY));
Tile TILE_BOTTOM_RIGHT = tiles.get(new Vertex(aX + 1, aY - 1));
Tile TILE_BOTTOM = tiles.get(new Vertex(aX, aY - 1));
Tile TILE_BOTTOM_LEFT = tiles.get(new Vertex(aX - 1, aY - 1));
Tile TILE_LEFT = tiles.get(new Vertex(aX - 1, aY));
Tile TILE_TOP_LEFT = tiles.get(new Vertex(aX - 1, aY + 1));
//TOP_RIGHT
if (TILE_TOP != null && TILE_TOP_RIGHT != null && TILE_RIGHT != null){
float[] dub = {TILE_TOP.getCenter(), TILE_TOP_RIGHT.getCenter(),TILE_RIGHT.getCenter(),TILE_CENTER.getCenter()};
TOP_RIGHT = getMode(dub);
}
//TOP_LEFT
if (TILE_TOP != null && TILE_TOP_LEFT != null && TILE_LEFT != null){
float[] dub = {TILE_TOP.getCenter(), TILE_TOP_LEFT.getCenter(),TILE_LEFT.getCenter(),TILE_CENTER.getCenter()};
TOP_LEFT = getMode(dub);
}
//TODO BOTTOM_RIGHT
//TODO BOTTOM_LEFT
TILE_CENTER.setConditions(TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT);
}
}
答案 0 :(得分:0)
我最终想出来了!
初始化:
int FIXTHISTOSIZE = 10;
for (int x = px - (FIXTHISTOSIZE / 2); x <= FIXTHISTOSIZE; x++){
for (int y = py - (FIXTHISTOSIZE / 2); y <= FIXTHISTOSIZE; y++){
int aY = py + y;
int aX = px + x;
float TOP_LEFT = 0, TOP_RIGHT = 0, BOTTOM_LEFT = 0, BOTTOM_RIGHT = 0;
Tile TILE_CENTER = tiles.get("" + aX + "." + aY);
if (TILE_CENTER.isLoaded()) {
continue;
}
Tile TILE_TOP_RIGHT = tiles.get("" + (aX + 1) + "." + (aY + 1));
Tile TILE_TOP = tiles.get("" + aX + "." + (aY + 1));
Tile TILE_RIGHT = tiles.get("" + (aX + 1) + "." + aY);
Tile TILE_BOTTOM_RIGHT = tiles.get("" + (aX + 1) + "." + (aY - 1));
Tile TILE_BOTTOM = tiles.get("" + aX + "." + (aY - 1));
Tile TILE_BOTTOM_LEFT = tiles.get("" + (aX - 1) + "." + (aY - 1));
Tile TILE_LEFT = tiles.get("" + (aX - 1) + "." + aY);
Tile TILE_TOP_LEFT = tiles.get("" + (aX - 1) + "." + (aY + 1));
//TOP_RIGHT
if (TILE_TOP != null && TILE_TOP_RIGHT != null && TILE_RIGHT != null){
float[] dub = {TILE_TOP.getCenter(), TILE_TOP_RIGHT.getCenter(),TILE_RIGHT.getCenter(),TILE_CENTER.getCenter()};
TOP_RIGHT = getMedian(dub);
}
//TOP_LEFT
if (TILE_TOP != null && TILE_TOP_LEFT != null && TILE_LEFT != null){
float[] dub = {TILE_TOP.getCenter(), TILE_TOP_LEFT.getCenter(),TILE_LEFT.getCenter(),TILE_CENTER.getCenter()};
TOP_LEFT = getMedian(dub);
}
//BOTTOM_LEFT
if (TILE_BOTTOM != null && TILE_BOTTOM_LEFT != null && TILE_LEFT != null){
float[] dub = {TILE_BOTTOM.getCenter(), TILE_BOTTOM_LEFT.getCenter(),TILE_LEFT.getCenter(),TILE_CENTER.getCenter()};
BOTTOM_LEFT = getMedian(dub);
}
//BOTTOM_RIGHT
if (TILE_BOTTOM != null && TILE_BOTTOM_RIGHT != null && TILE_RIGHT != null){
float[] dub = {TILE_BOTTOM.getCenter(), TILE_BOTTOM_RIGHT.getCenter(),TILE_RIGHT.getCenter(),TILE_CENTER.getCenter()};
BOTTOM_RIGHT = getMedian(dub);
}
TILE_CENTER.setConditions(TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT);
主循环(loadTiles):
public static float getMedian(float[] data) {
float[] copy = Arrays.copyOf(data, data.length);
Arrays.sort(copy);
return (copy.length % 2 != 0) ? copy[copy.length / 2] : (copy[copy.length / 2] + copy[(copy.length / 2) - 1]) / 2;
}
中位数:
{{1}}
希望这将有助于未来的人
结果: