I'm trying to create a Hexagonal Map, creating several Entities to create a "Hexagonal Map tool" to use later in a game
The algorithm that I used is the next:
Code: Select all
float offset = y % 2 != 0 ? f_eWidth / 2 : 0;
float _x = x * f_eWidth + offset;
float _y = y * f_eHeight * .75f;
The values of f_eWidth and f_eHeight is calculated as follow:
Code: Select all
f_eWidth = e_hexagon->getBoundingBox().getSize().x;
f_eHeight = e_hexagon->getBoundingBox().getSize().z;
Can you help me with this little problem? Thanks very much!
The complete code is here:
Code: Select all
Ogre::Entity *e_hexagon = mSceneMgr->createEntity("e_hexagon", "hexagon.mesh");
//Get hexagon scale
f_eWidth = e_hexagon->getBoundingBox().getSize().x;
f_eHeight = e_hexagon->getBoundingBox().getSize().z;
for(int x = 0; x < 24; x++)
{
for(int y = 0; y < 24; y++)
{
std::ostringstream os_name;
std::ostringstream os_node;
os_name << "e" << y << "," << x;
os_node << "n" << y << "," << x;
float offset = y % 2 != 0 ? f_eWidth / 2 : 0;
float _x = x * f_eWidth + offset;
float _y = y * f_eHeight * .75f;
Ogre::Entity *e_hexa = mSceneMgr->createEntity(os_name.str(), "hexagon.mesh");
Ogre::SceneNode *sn_hexa = mSceneMgr->getRootSceneNode()->createChildSceneNode(os_node.str());
sn_hexa->setPosition(_x, 0, _y);
sn_hexa->attachObject(e_hexa);
}
}
abreu20011