Tiled terrain scene node
Tiled terrain scene node
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.
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
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.
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.
arras,
I'm getting compile errors on this line (line 53):
TlMeshBuffer.h:
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:
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];
...
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);
}
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
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:
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;
}
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Ugh, I'm probably becoming a nuisance here... sorry
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.
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.
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.
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.
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
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.
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:
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.
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
}
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?
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?
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.
Anyway, I replaced these two lines in TlMeshBuffer.h:
with this via "#include <vector>":
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:
so, I changed it to this as a temporary fix:
But it's working now with VC++ 2005. 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;
Anyway, I replaced these two lines in TlMeshBuffer.h:
Code: Select all
const u32 IDsize = size;
u16 vertexID[IDsize][IDsize][4];
Code: Select all
std::vector< std::vector< std::vector<u16>>> vertexID(size,std::vector<std::vector<u16>>(size,std::vector<u16>(4,0)));
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();
Code: Select all
f32 distance = 0;
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;