Terrain quad diagonal

Hi,



for doing correct interpolation, I need to know the system behind terrain generation. Look to the linked picture. Most diagonals are from bottom left to top right. Few are in the other way. Why?



http://i.imgur.com/OP4BA.png

if i good understand you need to know how mesh look like.

set wireframe on(for terrain ofc), then you will see :wink:



sorry i dont read it to the end.



edit: remember that if you are using LOD, it can be changed in time. Terrain system have many methods like getHeight / etc. that are not affected by LOD / etc.

What do you want to interpolate? Theres interpolation going on for picking, display etc. already.

@oxplay2 said:
if i good understand you need to know how mesh look like.
set wireframe on(for terrain ofc), then you will see ;)

sorry i dont read it to the end.


Not me but the code have to know.

@normen said:
What do you want to interpolate? Theres interpolation going on for picking, display etc. already.


I want to do linear interpolation for height(x,z). But if I don't know in wich way the terrain mesh is builded, I cant do that.
@oxplay2 said:
edit: remember that it you are using LOD, it can be changed in time. Terrain system have many methods like getHeight / etc. that are not affected by LOD / etc.


LOD is disabled. And I want to implement the interface HeightMap. I have to write the method "public float getInterpolatedHeight(float x, float z)".

But, if I dont know the way the mesh is build, I cant interpolate.

ok i understand. But why do you want to create interface for HeightMap?



There is already interface for it(for importing only). there are also many interpolations for getHeight(x,y).

Do you try to export heightMap to image?

You have a flaw in our thinking, the height map and the mesh don’t have anything to do with each other per se. The mesh is constructed from the height map and the interpolation is mainly for picking afaik. So you do not need to know the mesh to do the interpolation.

Well, the same 2x2 heightmap, but two different situations.



http://i.imgur.com/x1YP8.png

http://i.imgur.com/nbVYs.png



I think it would be a good thing to know, if the sphere is above or under the ground.


@normen said:
You have a flaw in our thinking, the height map and the mesh don't have anything to do with each other per se. The mesh is constructed from the height map and the interpolation is mainly for picking afaik. So you do not need to know the mesh to do the interpolation.


When you keep care, that the four edgepoints are in the smae plane, than it don't care.

if you want to check it, just make raytrace or check position Y with height of terrain :slight_smile:



to tell more, you need to check bounding of sphere,

if it collide with terrain, then it collide,

if not then check position Y of object and height of terrain. if less then under, if not then over



some of tuts:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_terrain?s[]=terrain

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking?s[]=ray

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:mouse_picking?s[]=ray

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:collision_and_intersection?s[]=ray

Yeah I don’t get you. If you implement HeightMap you know yourself about your terrain, you cannot ask anybody, you have to give that information. Contrary, if you do want to get the information then simply do so by ray-picking or using the getInterpolatedHeight method yourself.

@oxplay2 said:
if you want to check it, just make raytrace or check position Y with height of terrain :)

to tell more, you need to check bounding of sphere,
if it collide with terrain, then it collide,
if not then check position Y of object and height of terrain. if less then under, if not then over



Sorry, but this sounds a little bit like a big overhead. :)
@usrr said:
Sorry, but this sounds a little bit like a big overhead. :)

But it isn't, there terrain uses very efficient bresenham picking when you do ray tests on it. Thats how 90% of all games move entities across the screen, by picking downwards each frame and putting the character at the height found by that.

need fast example?



pseudocode:



if(objvector.y < terrain.getHeight(x,y)) {

under

} else {

over

}



hmm? a collision was just an addon.



edit: and belive me. getHeight is interpolated properly.

@normen said:
Yeah I don't get you. If you implement HeightMap you know yourself about your terrain, you cannot ask anybody, you have to give that information. Contrary, if you do want to get the information then simply do so by ray-picking or using the getInterpolatedHeight method yourself.


Yes, you don't get the problem.
@usrr said:
Yes, you don't get the problem.

I think you want to use the mesh data to interpolate, at least thats what you said. Hence I don't want to understand your problem as it bases on wrong thinking as I said.

Mesh comes from HeightMap so you cannot use it to construct the height map. The other way round, you don't need to specify the mesh interpolation if you supply a height map, the mesh is constructed from the data you give. You only have to supply valid interpolation values for whatever terrain you want to describe.

Anyway, maybe you find somebody who understands your problem (as you obviously don't want to explain further).
@usrr said:
LOD is disabled. And I want to implement the interface HeightMap. I have to write the method "public float getInterpolatedHeight(float x, float z)".



I extend AbstractHeightMap and override the load method to initialize the heightData-array. Don't know if that is the way it is meant to be used but it works for my simple stuff. Then I get all the sweet interpolations for free :)

Well, I am not a native english speaker. I am from germany. Maybe there is really a missunderstanding in this thread. At this time I think the problem is not really clear.



Look at this Code from TerrainQuad.java:



[java] protected float getHeight(float x, float z) {

x-=0.5f;

z-=0.5f;

float col = FastMath.floor(x);

float row = FastMath.floor(z);

boolean onX = false;

if(1 - (x - col)-(z - row) < 0) // what triangle to interpolate on

onX = true;

// v1–v2 ^

// | / | |

// | / | |

// v3–v4 | Z

// |

// <


Y
// X
float v1 = getHeightmapHeight((int) FastMath.ceil(x), (int) FastMath.ceil(z));
float v2 = getHeightmapHeight((int) FastMath.floor(x), (int) FastMath.ceil(z));
float v3 = getHeightmapHeight((int) FastMath.ceil(x), (int) FastMath.floor(z));
float v4 = getHeightmapHeight((int) FastMath.floor(x), (int) FastMath.floor(z));
if (onX) {
return ((x - col) + (z - row) - 1f)*v1 + (1f - (x - col))*v2 + (1f - (z - row))*v3;
} else {
return (1f - (x - col) - (z - row))*v4 + (z - row)*v2 + (x - col)*v3;
}
}[/java]

The interpolation code is correct, but I think the fault is, that this is assumed:

[java] // v1--v2 ^
// | / | |
// | / | |
// v3--v4 | Z
// |
// <
Y
// X [/java]

If you look to the wireframe, you can see that this is also possible:

[java] // v1--v2 ^
// | \ | |
// | \ | |
// v3--v4 | Z
// |
// <
Y
// X [/java]

EDIT: I see in the last codeblock the backslashes are missing. They connect V1 and V4.

normen is from germany too, if i good remember :slight_smile:





btw: yes it is possible in situation where it can be, but what is the problem? it is made properly.



edit: but you know, the best way to solve your problem, is to do testcase.

All of this doesn’t have anything to do with getInterpolatedHeight()…?

@oxplay2 said:
edit: but you know, the best way to solve your problem, is to do testcase.


Give me some time. I am very new with jme.