Passing arrays to functions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Passing arrays to functions

Post by larztheloser »

Hi all,
With the help of Travis from the advanced forum, I added this method to the ITerrainSceneNode object:

Code: Select all

bool CTerrainSceneNode::loadHeightMapFromArray(irr::f32 heights[], int width, video::SColor vertexColor, s32 smoothFactor)
Then I added another method to the sceneManager, addArrTerrainSceneNode, which works almost like addTerrainSceneNode except that rather than passing a file, you pass irr::f32 heights[] and int width as the first 2 parameters.

BUT now I can't pass an array to addArrTerrainSceneNode! I get a compiler error, although Irrlicht compiles fine. Here's what I'm trying to do:

Code: Select all

scene::ITerrainSceneNode* getTerrainFromImage(video::IImage* idata,const core::vector3df &position,const core::vector3df &rotation,const core::vector3df &scale,const video::SColor vertexColor)
{
     short data_size=idata->getDimension().Width*idata->getDimension().Height;
     irr::f32 darray[data_size];
     for (s32 x = 0; x < idata->getDimension().Width; ++x)
     {
			for (s32 z = 0; z < idata->getDimension().Height; ++z)
			{
			    darray[x*idata->getDimension().Width+z]=(irr::f32)idata->getPixel(x,z).getAverage();
			}
     }
     scene::ITerrainSceneNode* terr=smgr->addArrTerrainSceneNode(darray, (int)idata->getDimension().Width, position, rotation, scale, vertexColor);
     return terr;
}
Which all compiles fine except for "smgr->addArrTerrainSceneNode(darray, (int)idata->getDimension().Width, position, rotation, scale, vertexColor);" because "386 C:\Users\Lars\Desktop\irrlicht-1.6\Haka\haka_enj.h no matching function for call to `irr::scene::ISceneManager::addArrTerrainSceneNode(irr::f32[((unsigned int)((int)data_size))]..." - indeed, for some reason DevCpp expects the first parameter to be irr::f32*! Does anybody have any idea why?

I'm posting here because I think this is a c++ mistake by me and thus I don't want to post in a forum which clearly states "NO questions about C++...".
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, I don't see any relation between the two things. Your method is called completely different. If you want to call this new method, then do it. Otherwise you have to add different methods to the scene manager.
However, your efforts seem to be wasted. The terrain scene node offers a RAW loader, which can also take float arrays. Just create a terrain without heightmap and call the raw loader.
Post Reply