Tiled terrain scene node

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Tiled terrain scene node

Post by arras »

PLEASE NOTE THAT THERE IS IMPROVED VERSION OF THIS NODE NAMED ShTlTerrainSceneNode:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=20940

YOU CAN CONSIDER THIS CLASS OBSOLETE

Small demo testing TlTerrainSceneNode.
Creates random terrain 1000 / 1000 tiles large.
Area of 100 / 100 tiles is visible, giving range of 50 tiles around camera.

Image

TlTerrainSceneNode create tile based terrain which can be nearly limitless in size. This is accomplished by storing data about terrain (height, normal, UV coordinates) in data array. Only terrain in specified size around camera (or anything specified) is rendered. Each tile can be textured independently by part of texture. This is accomplished by setting its texture UV coordinates. This class is still work in process and I would welcome any constructive critique, suggestions or bug reports from you. You are allowed to use it freely.

Class include getHeight and getIntersectionWithLine functions.

demo (3.75MB):
http://members.lycos.co.uk/arras1/downl ... inDemo.zip

header files:
http://members.lycos.co.uk/arras1/downl ... 61228b.zip

source code of demo:
http://members.lycos.co.uk/arras1/downl ... 061228.zip
Last edited by arras on Thu Aug 30, 2007 6:22 pm, edited 4 times in total.
ErUs
Posts: 165
Joined: Thu Oct 07, 2004 6:13 pm

Post by ErUs »

very nice job :)
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Impressive! Fast, massive terrains. Took me about 5 mins to reach the corner! :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
lug
Posts: 79
Joined: Tue May 02, 2006 5:15 am
Contact:

Post by lug »

arras,

I'm getting compile errors on this line (line 53):

TlMeshBuffer.h:

Code: Select all


...
        // vertex ID later used to fill indice array
        u16 vertexID[size][size][4];
...

It said error C2540: non-constant expression as array bound. It doesn't like using "size" as array indice since "size" is declared non-constant.

MSDN on error C2540:

Code: Select all


Error Message 
non-constant expression as array bound


An array must have a constant bound.

The following sample generates C2540:

  Copy Code 
// C2540.cpp
void func(int n, int pC[]) {
   int i = ((int [n])pC)[1];   // C2540
}

void func2(int n, int pC[]) {
   int i = (pC)[1];   // OK
}

int main() {
   int pC[100];
   func(100, pC);
   func2(100, pC);
}
 
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Could you supply the source code of the demo? I can't seem to get the construction right ;)
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Thanks :)

lug >> Thanks for reporting. Myself I am using DevC++. Code should work now, I did some small changes to TlMeshBuffer.h. I updated download link above. Please report here if it is working properly.

monkeycracks >> To construct tiled terrain:

Code: Select all

#include <irrlicht.h>
using namespace irr;

#include"TlTerrainSceneNode.h"

int main()
{
    u32 sizeX = 200;
    u32 sizeZ = 200;
    u32 vradius = 25;
    f32 tileSize = 1.0f;
    
    IrrlichtDevice *device =
		createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600), 32, false, false, false, 0);
    
    video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
	
    scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 30.0f, 10.0f);
	camera->setPosition(core::vector3df(sizeX/2,1,sizeZ/2));

	TlTerrainSceneNode* terrain = new TlTerrainSceneNode(smgr, core::dimension2d<u32>(sizeX,sizeZ), vradius, tileSize);
	terrain->drop();
	terrain->setTexture("Media/grass.bmp");
	terrain->setPosition(core::vector3df(0,0,0));
	terrain->lighting(false);
	terrain->setHeight(core::vector2d<s32>(100,105),1.0f);
	terrain->setHeight(core::vector2d<s32>(101,107),1.0f);
	terrain->setHeight(core::vector2d<s32>(102,107),1.2f);
	terrain->smoothNormals();
	
	terrain->update();
	
	terrain->follow(camera);
	
	while(device->run())
    {
        driver->beginScene(true, true, video::SColor(255,100,101,140));
        
        core::vector3df pos = camera->getPosition();
        pos.Y = terrain->getHeight(pos) + 1.0f;
        camera->setPosition(pos);
        
		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
    }
    device->drop();
    
    return 0;
}
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Thanks, I see what I was doing wrong now... and this is great, doesn't kill my FPS at all and I'm on a decently low end card. Love it :D

EDIT : I noticed that in the demo the terrain had bumpy parts to it, was that accomplished using the setHeight() or elsewise?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Glad you like it :)
If you mean shadows than it is acomplished by creating and positioning some light source and seting lighting(true) to accept it. Then call smoothNormals() to recalculate normals to work.

seHeight() just do what it reads: sets Y coordinate of vertex.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Ah alright, I figured it out.
Once again, great work ;)
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Ugh, I'm probably becoming a nuisance here... sorry :D

But I notice that if I setHeight() specific areas and such, it looks a lot smoother in your demo than it does in my app.

Just curious how you did the random generation, if you could put the code up for download or pm it to me or anything I'd be grateful ;)

Sorry for bugging you to death.
Curved
Posts: 2
Joined: Thu Dec 28, 2006 11:42 am

Post by Curved »

Heya, it seems that the zip files are using a compression scheme that isn't supported on my Linux box here. Is there any chance you aren't using the default Windows zip thingy? -- and if you aren't would you mind zipping with the default one, or using another format all-together?

I'ld really like to give your extension a shot. :)

Edit: cancel that, it seems that it was just because of using the hotlinks. Via your website they work fine.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

monkeycracks >> no problem, thats what this forum is for, right? :)

setHeight only rise/lower individual points on terrain, nothing more, nothing less. To make my terrain look way you see I rise several such points using randomization function which use sinus function to create smooth hilly like terrain.

You can download demo source here:
http://members.lycos.co.uk/arras1/downl ... 061228.zip

terrain randomization function is in file named "SomeFunctions.h"

void makeRandomHills(TlTerrainSceneNode* node, s32 hillCount, s32 maxRadius)
node -pointer to terrain node
hillCount -number of hills placed
maxRadius -maximumradius of hill
Last edited by arras on Thu Dec 28, 2006 7:19 pm, edited 1 time in total.
lug
Posts: 79
Joined: Tue May 02, 2006 5:15 am
Contact:

Post by lug »

VS 2005 VC++ compiler still doesn't like your use of const variable. It's the same line. I'm getting a C2057 for

u16 vertexID[IDsize][IDsize][4];

which was declared as follows:

const u32 IDsize = size;

in TIMeshBuffer's constructor. Here's the MSDN writeup for C2057:

Code: Select all


The following sample generates C2057:

  Copy Code 
// C2057.cpp
int i;
int b[i];   // C2057
int main() {
   const int i = 8;
   int b[i];
}
 

C has more restrictive rules for constant expressions. The following sample generates C2057:

  Copy Code 
// C2057b.c
#define ArraySize1 10
int main() { 
   const int ArraySize2 = 10; 
   int h[ArraySize2];   // C2057
   int h[ArraySize1];   // OK
}
 

why not use irr::array which has ability to reallocate? I'm surprised that DevC++ let this type of errors go by. Does DevC++ flag it as an warning even? I've used DevC++ a long time ago before making the switch over to VC++ 2005.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

No, DevC++ is absolutly happy about it. And to be honest as much as I understant howe constants work expresion:

const u32 IDsize = size; (should be u16 obviously, u32 is my mistake)

should work fine since there is no way howe IDsize can be changed. But then I am not such a great programer so I might be wrong.

irr::array does not help since I dont know any way howe to make it 3D.

Only other solution I think of is to make it dinamic C like array similar to those I use on other places of code.

Or do you have some other idea?
lug
Posts: 79
Joined: Tue May 02, 2006 5:15 am
Contact:

Post by lug »

arras -- I got it to work with std::vector instead of core::array. Sorry, I should try something out first before making a suggestion like that. :cry:

Anyway, I replaced these two lines in TlMeshBuffer.h:

Code: Select all


        const u32 IDsize = size;
         u16 vertexID[IDsize][IDsize][4];

with this via "#include <vector>":

Code: Select all


        std::vector< std::vector< std::vector<u16>>> vertexID(size,std::vector<std::vector<u16>>(size,std::vector<u16>(4,0)));

unfortunately, it causes error C2668 in vector2d.h:

Error 46 error C2668: 'sqrt' : ambiguous call to overloaded function c:\irrlicht\include\vector2d.h 58

which is called in SomeFunctions.h:

Code: Select all

                f32 distance = irr::core::vector2d<s32>(i-radius, j-radius).getLength();

so, I changed it to this as a temporary fix:

Code: Select all

                f32 distance = 0;

But it's working now with VC++ 2005. :D Nice work. I had to switch to Direct3D renderer since vista ATI driver only fully supports v1.1 of OpenGL:

1.1 100 % 7/7
1.2 12% 1/8
1.3 0% 0/9
1.4 0% 0/15
1.5 0% 0/3
2.0 0% 0/10
2.1 0% 0/3

Not good at the moment, but hopefully ATI will come through soon.

Oh, also why do you use your own pi function instead of irrlicht, core::PI or core::PI64?

double pi = 3.1415926535;
Post Reply