Formula Rotation & Heightmap Slope

The title is extremely vague and I’m sorry.
I would like to know if anyone did a Formula to get the right rotation to fit on the slope of the HeighMap or a 2d array of height point.
And to be more specific, I am trying to place some model in a mountain and they are floating in the sky or are inside the mountain. :persevere:

I can find the formula my self but if there is something already existing i won’t lose time on this! thank you!

Hi,

you can use the quad.getHeight() to receive the height at a given point. You then take 4 or more points of the bound of the object to receive the height at these points. Another solution would be to project the object onto the surface, but this is more work and i haven’t done this already. see Project Decals

My current formular for this is:
x= (position.x - worldBound.getXExtent()) * (widthOfMap/(2* worldBound.getXExtent()))), and similar for z.

1 Like

What you’ve showed me is not actually what i really need but it s quite interesting, and i will use this for sure once i have the time to polish the game a little :slight_smile: Thank you @b00n!

I was looking for a way to make the fern in the picture bellow be in the right angle so it doesn’t seem off.

Hey, it seems like you are using a noise algorithm to generate the ferns. I did something similar once. Here is the topic:

To get the correct rotation you could maybe (somehow) get the normal vector of the position of the terrain and then rotate the model to this normal vector. I don’t know if that works since I haven’t tried it myself yet, but maybe you get it done :slight_smile:

Not that it’s not just a matter of rotating the batch, plants grow vertically no matter on what slope they are.if you just rotate them they’ll be perpendicular to the ground which will look very unnatural.
What i’d do is to have just individual ferns, place them on the slop and then batch them.

I suppose you are right, but every time I’ve use the batchNode in a concurrency thread I’ve ended with a memory exception… (it start to use a shit load of memory for some reason…).
I will give it a try again and give a feed back if it work properly!

The trick to doing batching on the background thread is to avoid touching anything that the main thread has access to. “But I was only reading this one thing…” reading counts.

For example, don’t batch meshes that are also in the scene already.

That wouldn’t happen, normally i would

Node tile = new Node("Tile");
Node copy = asset.clone();
for(i = 0; i < 10 ; i++){
    for(j = 0; j < 10 ; j++){
        tile.attachChild(copy.clone());
    }
}
tile = (Node)GeometryBatchFactory.optimize(tile);
return tile;

//end thread
Node tile = (Node) Future.get();
rootNode.attachChild(tile);//this

But to be honest i will retry, maybe i did a mistake last time. It should be simple to test, i will try this tomorow morning.

If that asset is in the scene and you didn’t clone its meshes then the mesh is being shared. So one thread might be iterating over its Buffers casuing the pos/etc. to be invalid when viewed from another thread.

Normally if you are only attaching as part of a batch then it should be ok. But I think there is no magic in GeometryBatchFactory.optimize() that would be confounded by threading… so…

But GeometryBatchFactory.optimize(); Is what i should be using to batch right? or i m mistaking this with BatchNode?

If you want to batch in the background thread then yes.

BatchNode is for when you want potentially dynamically moving children in the scene that are also batched. I don’t think I’d use it from a background thread and I’d definitely not use it for static content.

Alright thank you, then i will work on this and get back in this thread with the result.

Alright this is the result, it seem to have worked properly, my lag FPS seem stable :stuck_out_tongue:

So go into the ground since there size varies. I will need to get the scale given and move the node accordingly!

3 Likes

I will try to work on a way to animated the whole thing now