Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Game Development
Game Library
Commits
9e4e0b1d
Commit
9e4e0b1d
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
cleanup some of the hexagon code
parent
34e44037
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3662
passed
2 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/demo/hexboard/board.cpp
+19
-30
19 additions, 30 deletions
demo/demo/hexboard/board.cpp
include/fggl/grid/layout.hpp
+15
-6
15 additions, 6 deletions
include/fggl/grid/layout.hpp
with
34 additions
and
36 deletions
demo/demo/hexboard/board.cpp
+
19
−
30
View file @
9e4e0b1d
...
@@ -35,10 +35,17 @@ namespace demo::hexboard {
...
@@ -35,10 +35,17 @@ namespace demo::hexboard {
grass
.
data
->
name
=
"grass"
;
grass
.
data
->
name
=
"grass"
;
grass
.
data
->
colour
=
{
0.0
F
,
1.0
F
,
0.0
};
grass
.
data
->
colour
=
{
0.0
F
,
1.0
F
,
0.0
};
fggl
::
grid
::
IntHex
islandPoint
{
3
,
3
};
std
::
array
<
fggl
::
grid
::
IntHex
,
4
>
islands
{{
auto
island
=
islandPoint
.
hexesInRange
(
2
);
{
3
,
3
},
for
(
auto
&
hex
:
island
)
{
{
7
,
7
},
m_board
->
setTerrain
(
hex
,
grass
);
{
10
,
10
},
{
7
,
3
}
}};
for
(
auto
islandPoint
:
islands
){
auto
island
=
islandPoint
.
hexesInRange
(
2
);
for
(
auto
&
hex
:
island
)
{
m_board
->
setTerrain
(
hex
,
grass
);
}
}
}
}
}
...
@@ -59,12 +66,10 @@ namespace demo::hexboard {
...
@@ -59,12 +66,10 @@ namespace demo::hexboard {
// check if a button was pressed
// check if a button was pressed
auto
&
input
=
this
->
input
();
auto
&
input
=
this
->
input
();
{
{
fggl
::
math
::
vec2
screenPos
(
const
fggl
::
math
::
vec2
screenPos
(
input
.
mouse
.
axis
(
fggl
::
input
::
MouseAxis
::
X
),
fggl
::
math
::
rescale_ndc
(
input
.
mouse
.
axis
(
fggl
::
input
::
MouseAxis
::
X
),
0
,
1920
),
input
.
mouse
.
axis
(
fggl
::
input
::
MouseAxis
::
Y
)
fggl
::
math
::
rescale_ndc
(
input
.
mouse
.
axis
(
fggl
::
input
::
MouseAxis
::
Y
)
,
0
,
1080
)
);
);
screenPos
.
x
=
fggl
::
math
::
rescale_ndc
(
screenPos
.
x
,
0
,
1920
);
screenPos
.
y
=
fggl
::
math
::
rescale_ndc
(
screenPos
.
y
,
0
,
1080
);
m_selections
->
hover
=
fggl
::
grid
::
round2
(
m_layout
->
toGrid
(
screenPos
)
);
m_selections
->
hover
=
fggl
::
grid
::
round2
(
m_layout
->
toGrid
(
screenPos
)
);
if
(
input
.
mouse
.
pressed
(
fggl
::
input
::
MouseButton
::
LEFT
))
{
if
(
input
.
mouse
.
pressed
(
fggl
::
input
::
MouseButton
::
LEFT
))
{
...
@@ -74,29 +79,13 @@ namespace demo::hexboard {
...
@@ -74,29 +79,13 @@ namespace demo::hexboard {
}
}
void
Scene
::
drawGrid
(
fggl
::
gfx
::
Paint
&
paint
)
{
void
Scene
::
drawGrid
(
fggl
::
gfx
::
Paint
&
paint
)
{
const
float
hexRadius
=
64.0
F
;
const
auto
gridWidth
=
(
int
)(
(
1920
-
hexRadius
)
/
(
hexRadius
*
std
::
sqrt
(
3.0
F
))
);
const
auto
gridHeight
=
(
int
)(
(
1080
-
hexRadius
)
/
(
hexRadius
*
(
3.0
F
/
2.0
F
)
));
auto
tiles
=
m_board
->
getAllTiles
();
auto
tiles
=
m_board
->
getAllTiles
();
for
(
const
auto
&
tile
:
tiles
)
{
fggl
::
grid
::
IntHex
hexPos
{
0
,
0
};
auto
terrain
=
m_board
->
getTerrain
(
tile
);
auto
rowBasis
=
hexPos
;
if
(
terrain
.
has_value
()
)
{
for
(
auto
i
=
0
;
i
<
gridHeight
;
++
i
)
{
const
auto
&
terrainData
=
terrain
.
value
();
for
(
auto
j
=
0
;
j
<
gridWidth
;
++
j
)
{
m_layout
->
paintHex
(
paint
,
tile
,
terrainData
.
colour
);
auto
terrain
=
m_board
->
getTerrain
(
hexPos
);
if
(
terrain
.
has_value
()
)
{
const
auto
&
value
=
terrain
.
value
();
m_layout
->
paintHex
(
paint
,
hexPos
,
value
.
colour
);
}
// next hexagon
hexPos
=
hexPos
.
neighbour
(
fggl
::
grid
::
HexDirPointy
::
RIGHT
);
}
}
rowBasis
=
i
%
2
==
0
?
rowBasis
.
neighbour
(
fggl
::
grid
::
HexDirPointy
::
BOTTOM_RIGHT
)
:
rowBasis
.
neighbour
(
fggl
::
grid
::
HexDirPointy
::
BOTTOM_LEFT
);
hexPos
=
rowBasis
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
include/fggl/grid/layout.hpp
+
15
−
6
View file @
9e4e0b1d
...
@@ -38,14 +38,18 @@
...
@@ -38,14 +38,18 @@
namespace
fggl
::
grid
{
namespace
fggl
::
grid
{
const
math
::
mat2
MAT_HEX_POINTY
{
// factor out the call to sqrt so the matrices can be constexpr
std
::
sqrt
(
3.0
F
),
0.0
F
,
constexpr
float
M_SQRT_3
=
1.73205080757
F
;
std
::
sqrt
(
3.0
F
)
/
2.0
F
,
3.0
F
/
2.0
F
constexpr
float
M_SQRT_3_OVER_2
=
M_SQRT_3
/
2.0
F
;
constexpr
math
::
mat2
MAT_HEX_POINTY
{
M_SQRT_3
,
0.0
F
,
M_SQRT_3_OVER_2
,
3.
F
/
2.
F
};
};
const
math
::
mat2
MAT_HEX_FLAT
{
const
expr
math
::
mat2
MAT_HEX_FLAT
{
3.
F
/
2.
F
,
std
::
sqrt
(
3.
F
)
/
2.
F
,
3.
F
/
2.
F
,
M_SQRT_3_OVER_2
,
0.0
F
,
std
::
sqrt
(
3.
F
)
0.0
F
,
M_SQRT_3
};
};
struct
Orientation
{
struct
Orientation
{
...
@@ -73,6 +77,11 @@ namespace fggl::grid {
...
@@ -73,6 +77,11 @@ namespace fggl::grid {
Layout
(
Orientation
orientation
,
math
::
vec2
size
,
math
::
vec2
origin
)
:
m_orientation
(
orientation
),
m_size
(
size
),
m_origin
(
origin
){}
Layout
(
Orientation
orientation
,
math
::
vec2
size
,
math
::
vec2
origin
)
:
m_orientation
(
orientation
),
m_size
(
size
),
m_origin
(
origin
){}
Layout
(
Orientation
orientation
,
float
size
)
:
m_orientation
(
orientation
),
m_size
(
size
,
size
),
m_origin
()
{}
Layout
(
Orientation
orientation
,
float
size
)
:
m_orientation
(
orientation
),
m_size
(
size
,
size
),
m_origin
()
{}
inline
void
translate
(
float
dx
,
float
dy
){
m_origin
.
x
+=
dx
;
m_origin
.
y
+=
dy
;
}
[[
nodiscard
]]
[[
nodiscard
]]
inline
math
::
vec2
origin
()
const
{
inline
math
::
vec2
origin
()
const
{
return
m_origin
;
return
m_origin
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment