Prelude :
So in theory we need a Tile class/struct and a TileMap array contains a Tiles
For example:
Code: Select all
#define MapW 5
#define MapH 5
#define TileSize 50.f
struct Tile
{
int i,j;//Tile coords in TileMap
bool walkable; //can we walk there?
};
Tile TileMap[MapW][MapH];
void initTileMap()
{
for (int x=0;x<MapW;x++)
{
for(int y=0;y<MapW;y++)
{
tilemap[x][y].walkable=true;
tilemap[x][y].i=x;
tilemap[x][y].j=y;
}
}
}
Suggestion No 1: Use addHillPlaneMesh like this:
Code: Select all
struct Tile
{
bool walkable;
int i,j;
ISceneNode* node;
};
Tile TileMap[MapW][MapH];
void initTileMap()
{
IAnimatedMesh* floor=managerScene->addHillPlaneMesh("floor",
core::dimension2d<f32>(50.f,50.f), // Tile size
core::dimension2d<u32>(1,1), // Tile count
0, // Material
0.0f, // Hill height
core::dimension2d<f32>(0.0f, 0.0f), // countHills
core::dimension2d<f32>(1.f,1.f));// texture repeat
for (int x=0;x<MapW;x++)
{
for(int y=0;y<MapW;y++)
{
TileMap[x][y].walkable=true;
TileMap[x][y].i=x;
TileMap[x][y].j=y;
tilemap[x][y].node=managerScene->addAnimatedMeshSceneNode(floor);
tilemap[x][y].node->setMaterialTexture
(
0, driverVideo->getTexture("floor.bmp")
);
tilemap[x][y].node->setPosition(vector3df(x*TileSize,0.f,y*TileSize));
tilemap[x][y].node->setMaterialFlag(EMF_LIGHTING, false);
}
}
}
Suggestion No 2: Use ITerrainScene node and create an *Imaginary* Tiles like this:
Code: Select all
ITerrainSceneNode* nodeTerrain = managerScene->addTerrainSceneNode(
"terrain-heightmap.bmp",
0,
-1,
vector3df(0.f, 0.f, 0.f)
,vector3df(0.f, 0.f, 0.f),
vector3df(40.f, 4.f, 40.f),
SColor ( 255, 255, 255, 255 ),
5,
ETPS_17,
4);
nodeTerrain->setMaterialFlag(EMF_LIGHTING, false);
nodeTerrain->setMaterialTexture(0,driverVideo->getTexture("terrain-texture.jpg"));
nodeTerrain->setMaterialTexture(1,driverVideo->getTexture("detailmap3.jpg"));
nodeTerrain->setMaterialType(EMT_DETAIL_MAP);
nodeTerrain->scaleTexture(10.0f, 20.0f);
position3df objectPos;
int TileX=(int)objectPos.X/TileSize;
int tileY=(int)objectPos.Y/TileSize;
//if object have position (100.f,10,223.f) then
it on tile (2,4)
position3df TileCenter=position3df(TileX*TileSize/2,0.f,TileY*TileSize/2)
Question No 3: How set for one node several meshes on it? e.g. we have HillPlaneMesh textured and wanna a chest on it or door on 1 TileNode, but door and Hillplane position change with node->setPosition, how position them separately?
P.S I downloaded Nethack3D Sources created with Irrlicht on SourceForge, but they very complicated, maybe there is better example?.
