Question

My english knowlage is not good enought to tell my problems. and i am using stackoverflow second time.

i am hooking a directx application, i just can wrote something to screen and get input from screen and other things.

This game has a terrain, and a lot of players. I can directly edit the player location (x, z, y). But when i edit x and z coordinate, the player is flying :) because i don't know how to calculate the y coordinate (terrain height), i can't calculate it.

Player coordinate is 700, 5.41, 600

when game edit it to 800 and 700, game makes y to 6.50

when i edit it to 800 and 700, the y coordinate still 5.41

6.50 is coordinate, height of terrain of (800, 700), 5.41 is 700,600 terrain height.

Is there a any way to get height of the terrain for speficed coordinate?

Thank you much more.

Was it helpful?

Solution 2

It works on Knight OnLine. its a wrapper to CN3Terrain::GetHeight(float x, float z).

float getY(float x, float z) {
__asm {
    PUSH 0
    PUSH z
    PUSH x
    MOV ECX,DWORD PTR DS:[0x0C26C20]
    MOV ECX,DWORD PTR DS:[ECX+1Ch]
    MOV EDX,DWORD PTR DS:[ECX]
    CALL DWORD PTR DS:[EDX+34h]
}}

OTHER TIPS

I found it. Thanks to everyone.

The game is using N3Terrain :)

float CN3Terrain::GetHeight(float x, float z)

{ int ix, iz; ix = ((int)x) / TILE_SIZE; iz = ((int)z) / TILE_SIZE;

if(ix<0 || ix>(m_ti_MapSize-2)) return -FLT_MAX;
if(iz<0 || iz>(m_ti_MapSize-2)) return -FLT_MAX;

float dX, dZ;
dX = (x - (ix*TILE_SIZE)) / TILE_SIZE;
dZ = (z - (iz*TILE_SIZE)) / TILE_SIZE;

float y;
float h1, h2, h3, h12, h13;

if((ix+iz)%2==0)    //»ç°¢ÇüÀÌ / ¸ð¾ç.. 
{
    h1 = m_pMapData[ix*m_ti_MapSize + iz].fHeight;
    h3 = m_pMapData[(ix+1)*m_ti_MapSize + (iz+1)].fHeight;
    if (dZ > dX)    //À­ÂÊ »ï°¢Çü..
    {
        h2 = m_pMapData[ix*m_ti_MapSize + (iz+1)].fHeight;

        h12 = h1 + (h2-h1) * dZ;    // h1°ú h2»çÀÌÀÇ ³ôÀÌ°ª
        h13 = h1 + (h3-h1) * dZ;    // h1°ú h3»çÀÌÀÇ ³ôÀÌ°ª

        y = h12 + ((h13-h12) * (dX/dZ));    // ã°íÀÚ ÇÏ´Â ³ôÀÌ°ª
        return y;
    }
    else    //¾Æ·¡ÂÊ »ï°¢Çü..
    {
        if(dX==0.0f) return h1;

        h2 = m_pMapData[(ix+1)*m_ti_MapSize + iz].fHeight;

        h12 = h1 + (h2-h1) * dX;    // h1°ú h2»çÀÌÀÇ ³ôÀÌ°ª
        h13 = h1 + (h3-h1) * dX;    // h1°ú h3»çÀÌÀÇ ³ôÀÌ°ª

        y = h12 + ((h13-h12) * (dZ/dX));    // ã°íÀÚ ÇÏ´Â ³ôÀÌ°ª
        return y;
    }
}

else if ((ix+iz)%2==1)  //»ç°¢ÇüÀÌ ¿ª½½·¹½¬ ¸ð¾ç..
{
    h1 = m_pMapData[(ix+1)*m_ti_MapSize + iz].fHeight;
    h3 = m_pMapData[ix*m_ti_MapSize + (iz+1)].fHeight;

    if ((dX+dZ) > 1.0f) //À­ÂÊ »ï°¢Çü..
    {
        if(dZ==0.0f) return h1;
        h2 = m_pMapData[(ix+1)*m_ti_MapSize + (iz+1)].fHeight;

        h12 = h1 + (h2-h1) * dZ;
        h13 = h1 + (h3-h1) * dZ;

        y = h12 + ((h13-h12) * ((1.0f-dX)/dZ));
        return y;
    }
    else    //¾Æ·¡ÂÊ »ï°¢Çü..
    {
        if(dX==1.0f) return h1;
        h2 = m_pMapData[ix*m_ti_MapSize + iz].fHeight;

        h12 = h2+(h1-h2)*dX;    // h1°ú h2»çÀÌÀÇ ³ôÀÌ°ª
        h13 = h3+(h1-h3)*dX;    // h1°ú h3»çÀÌÀÇ ³ôÀÌ°ª

        y = h12 + ((h13-h12) * (dZ/(1.0f-dX)));
        return y;
    }
}

return -FLT_MAX;

}

One engine I used allowed you to cast rays and determine their intersection with objects. I found the "ground" by casting a ray from above aimed down and found the intersection with the terrain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top