2017-05-05 3 views
0

그래서 나는이 방법 ....방법을 바꾸시겠습니까?

public static Vector2 cellsToIso(float row, float col) { 
    float halfTileWidth = tileWidth *0.5f; 
    float halfTileHeight = tileHeight *0.5f; 

    float x = (col * halfTileWidth) + (row * halfTileWidth); 
    float y = (row * halfTileHeight) - (col * halfTileHeight); 

    return new Vector2(x,y); 
} 

을하고 난 반대 방법 isoToCells(float x, float y)

나는이 시도를하고 싶지만, 그것은 나

public static Vector2 isoToCell(float x, float y) { 
    float halfTileWidth = tileWidth * 0.5f; 
    float halfTileHeight = tileHeight * 0.5f; 

    float row = (y/halfTileWidth) - (x/halfTileWidth); 
    float col = (x/halfTileHeight) + (y/halfTileHeight); 

    return new Vector2(row,col); 
} 
+1

구체적인 문제를 명확히하거나 필요한 것을 정확하게 강조하기 위해 자세한 내용을 추가하십시오. 현재 작성된 내용이므로 귀하가 원하는 내용을 정확하게 말하기는 어렵습니다. –

+0

왜 당신에게 이해가되지 않는 것을 시도 했습니까? – shmosel

답변

2
float x = (col * halfTileWidth) + (row * halfTileWidth); 
float y = (row * halfTileHeight) - (col * halfTileHeight); 
이해가 나던

이 두 방정식으로 쓸 수 있습니다

xy의 측면에서 그래서 row

,

row = (1.0/2) * (x/halfTileWidth + y/halfTileHeight); 
column = (1.0/2) * (x/halfTileWidth - y/halfTileHeight); 

다시 rowcolumn를 얻기 위해 역 방법이 교체합니다.

public static Vector2 isoToCell(float x, float y) { 
    float halfTileWidth = tileWidth * 0.5f; 
    float halfTileHeight = tileHeight * 0.5f; 

    float row = (1.0/2) * (x/halfTileWidth + y/halfTileHeight); 
    float col = (1.0/2) * (x/halfTileWidth - y/halfTileHeight); 

    return new Vector2(row,col); 
} 
관련 문제