Jump to content

Recommended Posts

Posted

I am trying to procedurally generate terrain heights, but with no luck.

 

terrain = Terrain::Create(512, true);
terrain->SetLayerTexture(0, Texture::Load("AddOns/Terrain Textures/mountain_grass.tex"), 0);
terrain->SetLayerTexture(0, Texture::Load("AddOns/Terrain Textures/mountain_grassdot3.tex"), 1);
perlinNoise = new Perlin(0);
fractalNoise = new FractalNoise(0.1, 2, 1, perlinNoise);
for (int y = 0; y < 512; y++) {
 for (int x = 0; x < 512; x++) {
  float height = fractalNoise->HybridMultifractal((float)x / 100.0, (float)y / 100.0, 1.0);
  terrain->SetHeight(x, y, height);
 }
}
terrain->Update();
terrain->UpdateHeightmap(0, 0, 512, 512);
terrain->UpdateShape();

 

This is what I have. I'm using my own perlin noise that I know works.

It doesn't seem to be setting any heights and the collision isn't working (you just fall through the terrain).

As there is no documentation on this, could someone please give me a hand with this?

Posted

Assuming the terrain works similar to LE2 terrain, the height used in SetHeight() is a value between 0 and 1, where 1 was equal to the max altitude. In lua, I do not see what sets this altitude and currently I can only get the terrain to move up 1 meter.

 

As for the collision, its working automatically for me, so not sure why it isn't for you.

 

Edit-- I take that back... the altitude is set just like it was in LE2 - by using SetScale().

 

terrain:SetScale(1,10,1) will set the max altitude to 10 meters. So if your perlin noise generator sets the height between 0 and 1 then you should see results.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

Thanks macklebee, turns out SetScale did the trick. Not sure why there was no collision without it though?

Edit: I think I was just falling onto the terrain from too high, that's why I was falling through it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...