3

Using Firemonkey XE2 , I was able to use the TCube component to create a cubed map, But I am now wanting a hexagon map. There was no option for a 3d hexagon shape i could find. I figured you could create a THex similar to the TCube but I have not been able to do this or even get close. Can anyone supply a sample of doing this?

The shape I'm looking for is a hexagon prism.

enter image description here

LU RD
  • 34,438
  • 5
  • 88
  • 296
Glen Morse
  • 2,437
  • 8
  • 51
  • 102
  • A hexagon isn't a 3D Shape, [a 3D "spherical" shape using hexagonal tiles isn't really possible](http://stackoverflow.com/questions/12847654/hexagon-grid-on-sphere-without-pentagon). Do you mean to create a [Dodecahedron](http://en.wikipedia.org/wiki/Dodecahedron)? – James Jun 18 '14 at 08:16
  • um, no more of a hexagon prism http://en.wikipedia.org/wiki/Uniform_prism – Glen Morse Jun 18 '14 at 08:21
  • Better answer anyone! dont think any of these are worth the 500 rep – Glen Morse Jun 23 '14 at 08:17

3 Answers3

4

I am doing the same thing that you are doing and developing a strategic game with a hexagon map in Delphi.

You have the object that you need in Delphi itself and that is TCylinder. You should set SubdivisionAxes from 12 to 6 (12 is default for this object) and that is all you need to have the object that you want.

for implementing your map I suggest you to check this link as well. http://www.redblobgames.com/grids/hexagons/

good luck.

Loghman
  • 1,500
  • 1
  • 14
  • 30
3

You'll need to derive from TCustomMesh and override Render to pass in you calculated vertices.

Start with a center and a radius and the points are as follows. Assuming the shape is constructed parallel to a plane and subsequently transformed. The following creates a vertical Hexagonal Prism (I have no IDE atm and no way of testing this!).

ClearPoints();
prismEnd := -1;
while prismEnd < 2 do
begin
    Z := Center.Z + (prismEnd * length)
    angle = 0;
    AddPoint(0, 0, Z);
    while angle < 360 do
    begin
        X := Center.X + (radius * Cos(DegToRad(angle)));
        Y := Center.Y + (radius * Sin(DegToRad(angle)));
        AddPoint(X, Y, Z);
        Inc(angle, 60);
    end;
    Inc(prismEnd, 2);
end;

For the 6 values this creates the TexCoords should be

Tex X   Tex Y 
1       0.5
0.75    1
0.25    1
0       0.5
0.25    0
0.75    0

You'll need 24 Triangles to render this, which depending on your draw method could require up to 72 indices.

but that will depend on how you map your textures.

I found this link which has examples of inheriting and using TCustomMesh

This should in theory provide a shape such as

enter image description here

James
  • 9,774
  • 5
  • 34
  • 58
  • Delphi has no step possibility in for loops. There is a possibility to use some of the the constructs shown [here](http://stackoverflow.com/a/16371783/576719) though. – LU RD Jun 18 '14 at 09:58
  • @LURD it's been too long since I worked with Delphi I think! I'll fix it now – James Jun 18 '14 at 10:01
  • I understand how or the calculations on how to get the data as you have shown, but how do i incorporate this into X component to draw it. – Glen Morse Jun 18 '14 at 10:40
  • @GlenMorse You don't draw it, you provide vertices, indices and tex coords and pass them all to DrawTriangles in the override of the `Render` method – James Jun 18 '14 at 10:43
  • @JamesBarrass going to give this a try and see if i can get it working using the custom mesh..dont go far :D – Glen Morse Jun 19 '14 at 03:48
  • @JamesBarrass ok so far i copied all of the TAnnulus stuff, with an error in the `uses FMX.Materials` Not sure if it goes by another name or if i can download it somewhere.. Anyhow now from here i can make the `THex = class(TAnnulus)` Correct? – Glen Morse Jun 19 '14 at 06:51
  • You can, but you're likely replacing most of it's functionality. The TexCoords are part of the VertexBuffer in the DrawTriangles call. You can see them being assigned in the BuildAnnulus Function (Which for you becomes a BuildHex function) – James Jun 19 '14 at 06:56
  • @JamesBarrass thanks for the help , but i think i will need an answer with full example. As i seem to be missing something. – Glen Morse Jun 19 '14 at 08:09
1

You can use TMesh to create whatever shape you need.

Use the Data property to specify the points, normals and textures for each point, and the order in which the resulting triangles are drawn.

All you need is precalculated points and normals for desired hexagon shape (I guess this can be found with google, or created in specialized shape editor)

VitaliyG
  • 1,837
  • 1
  • 11
  • 11