0
\$\begingroup\$

I'm having the following problem creating this hexa tiled map.

this is what I wanted :

desired output

[EDIT] Ok I've Managed to do this:

const float scaleX = ((float)tileWidth) / 10000,
    scaleY = ((float)tileHeight ) / 10000;
    const float hexagon_r = scaleY / 2;
    const float hexagon_dx = hexagon_r * cosf(30*3.14f / 180.0);
    const float hexagon_dy = hexagon_r * sinf(30*3.14f / 180.0);
    const float hexagon_gx = 2.0*hexagon_dx;
    const float hexagon_gy = 2.0*hexagon_dx*sinf(60*3.14f / 180.0);
    Vector2 auxPos;
    auxPos.x = 0;
    auxPos.y = 0;
    float j = 0;
    for (unsigned int y = 0; y < layer->layerHeight; y++, j += hexagon_gx * 2)
    {
        auxPos.y = y * (hexagon_gy * -2 );
        auxPos.x = j;
        for (unsigned int x = 0; x < layer->layerWidth; x++)
        {

            auxPos.x += hexagon_gx * 2;

            float angle =90 * 3.14f / 180;

            auxPos.y += hexagon_gy * 2;

            SetData(stack->vData, stack->vCounter + 0, auxPos.x + ((-scaleX) * cosf(angle) + (-scaleY) * -sinf(angle)));
            SetData(stack->vData, stack->vCounter + 1, auxPos.y + ((-scaleX) * sinf(angle) + (-scaleY) * cosf(angle)));
            SetData(stack->vData, stack->vCounter + 2, layer->layerDepth);

            SetData(stack->vData, stack->vCounter + 3, auxPos.x + ((scaleX) * cosf(angle) + (-scaleY) * -sinf(angle)));
            SetData(stack->vData, stack->vCounter + 4, auxPos.y + ((scaleX) * sinf(angle) + (-scaleY) * cosf(angle)));
            SetData(stack->vData, stack->vCounter + 5, layer->layerDepth);

            SetData(stack->vData, stack->vCounter + 6, auxPos.x + ((scaleX) * cosf(angle) + (scaleY) * -sinf(angle)));
            SetData(stack->vData, stack->vCounter + 7, auxPos.y + ((scaleX) * sinf(angle) + (scaleY) * cosf(angle)));
            SetData(stack->vData, stack->vCounter + 8, layer->layerDepth);

            SetData(stack->vData, stack->vCounter + 9, auxPos.x + ((-scaleX) * cosf(angle) + (scaleY) * -sinf(angle)));
            SetData(stack->vData, stack->vCounter + 10, auxPos.y + ((-scaleX) * sinf(angle) + (scaleY) * cosf(angle)));
            SetData(stack->vData, stack->vCounter + 11, layer->layerDepth);
        }
    }

output

can't seem to make this work...

\$\endgroup\$
  • \$\begingroup\$ please help me!! \$\endgroup\$ – David Neves Dec 23 '18 at 1:50
  • \$\begingroup\$ I think you would have more luck using (1/3)$pi$ (60 degrees) instead of (1/2)$pi$ (90 degrees). \$\endgroup\$ – Jay Dec 23 '18 at 2:39
  • \$\begingroup\$ come on... that doesn't help anything.... what do you mean? \$\endgroup\$ – David Neves Dec 23 '18 at 3:50
  • \$\begingroup\$ What happens when you use 'angle = 60 * 3.14f / 180;' ... It looks like your tiles are getting stretched because of this \$\endgroup\$ – Jay Dec 23 '18 at 3:58
  • \$\begingroup\$ the tiles get rotated 60 degrees. the gap continues.. I've tred auxPos.y += scaleY * 2; Which makes the tiles evenly spaced out but there's still gaps in between I'l edit the question... \$\endgroup\$ – David Neves Dec 23 '18 at 4:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.