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
Onuralp SEZER
Game Library
Commits
be357a1a
Commit
be357a1a
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
clean up heighmap APIs
parent
aa716b19
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/demo/GameScene.cpp
+17
-18
17 additions, 18 deletions
demo/demo/GameScene.cpp
include/fggl/data/heightmap.h
+5
-3
5 additions, 3 deletions
include/fggl/data/heightmap.h
with
22 additions
and
21 deletions
demo/demo/GameScene.cpp
+
17
−
18
View file @
be357a1a
...
...
@@ -65,18 +65,18 @@ static void process_camera(fggl::ecs3::World& ecs, const fggl::input::Input& inp
fggl
::
input
::
process_edgescroll
(
ecs
,
input
,
cam
);
}
static
void
setupCamera
(
fggl
::
ecs3
::
World
&
world
,
fggl
::
ecs3
::
TypeRegistry
&
types
)
{
static
void
setupCamera
(
fggl
::
ecs3
::
World
&
world
)
{
auto
prototype
=
world
.
create
(
false
);
world
.
add
(
prototype
,
types
.
find
(
fggl
::
math
::
Transform
::
name
));
world
.
add
(
prototype
,
types
.
find
(
fggl
::
gfx
::
Camera
::
name
));
world
.
add
(
prototype
,
types
.
find
(
fggl
::
input
::
FreeCamKeys
::
name
));
auto
camTf
=
world
.
get
<
fggl
::
math
::
Transform
>
(
prototype
);
if
(
camTf
!=
nullptr
)
{
camTf
->
origin
(
glm
::
vec3
(
10.0
f
,
3.0
f
,
10.0
f
));
// setup camera position/transform
auto
*
transform
=
world
.
add
<
fggl
::
math
::
Transform
>
(
prototype
);
if
(
transform
!=
nullptr
)
{
transform
->
origin
(
glm
::
vec3
(
10.0
f
,
3.0
f
,
10.0
f
));
}
auto
cameraKeys
=
world
.
get
<
fggl
::
input
::
FreeCamKeys
>
(
prototype
);
// setup camera components
world
.
add
<
fggl
::
gfx
::
Camera
>
(
prototype
);
auto
*
cameraKeys
=
world
.
add
<
fggl
::
input
::
FreeCamKeys
>
(
prototype
);
if
(
cameraKeys
!=
nullptr
)
{
cameraKeys
->
forward
=
glfwGetKeyScancode
(
GLFW_KEY_W
);
cameraKeys
->
backward
=
glfwGetKeyScancode
(
GLFW_KEY_S
);
...
...
@@ -87,26 +87,25 @@ static void setupCamera(fggl::ecs3::World& world, fggl::ecs3::TypeRegistry& type
}
}
static
fggl
::
ecs3
::
entity_t
setupTerrain
(
fggl
::
ecs3
::
World
&
world
,
fggl
::
ecs3
::
TypeRegistry
&
types
)
{
static
fggl
::
ecs3
::
entity_t
setupTerrain
(
fggl
::
ecs3
::
World
&
world
)
{
fggl
::
ecs3
::
entity_t
terrain
;
{
terrain
=
world
.
create
(
false
);
world
.
add
(
terrain
,
types
.
find
(
fggl
::
math
::
Transform
::
name
));
auto
camTf
=
world
.
get
<
fggl
::
math
::
Transform
>
(
terrain
);
auto
*
camTf
=
world
.
add
<
fggl
::
math
::
Transform
>
(
terrain
);
camTf
->
origin
(
glm
::
vec3
(
-
128.0
f
,
0.0
f
,
128.0
f
)
);
//auto terrainData = m_world.get<fggl::data::HeightMap>(terrain);
fggl
::
data
::
HeightMap
terrainData
{};
terrainData
.
clear
();
const
siv
::
PerlinNoise
::
seed_type
seed
=
123456
u
;
const
siv
::
PerlinNoise
::
seed_type
seed
=
123456
U
;
const
siv
::
PerlinNoise
perlin
{
seed
};
for
(
int
y
=
0
;
y
<
255
;
++
y
)
{
for
(
int
x
=
0
;
x
<
255
;
++
x
)
{
const
double
noise
=
perlin
.
octave2D_11
(
(
x
*
0.01
),
(
y
*
0.01
)
,
4
)
*
10.
f
;
terrainData
.
heigh
tValue
s
[
x
*
255
+
y
]
=
(
float
)
noise
;
for
(
int
z
=
0
;
z
<
fggl
::
data
::
heightMaxZ
;
++
z
)
{
for
(
int
x
=
0
;
x
<
fggl
::
data
::
heightMaxX
;
++
x
)
{
const
double
noise
=
perlin
.
octave2D_11
(
(
x
*
0.01
),
(
z
*
0.01
)
,
4
)
*
10.
f
;
terrainData
.
se
tValue
(
x
,
z
,
(
float
)
noise
)
;
}
}
world
.
set
<
fggl
::
data
::
HeightMap
>
(
terrain
,
&
terrainData
);
...
...
@@ -116,8 +115,8 @@ static fggl::ecs3::entity_t setupTerrain(fggl::ecs3::World& world, fggl::ecs3::T
static
fggl
::
ecs3
::
entity_t
setupEnvironment
(
fggl
::
ecs3
::
World
&
world
)
{
auto
&
types
=
world
.
types
();
setupCamera
(
world
,
types
);
return
setupTerrain
(
world
,
types
);
setupCamera
(
world
);
return
setupTerrain
(
world
);
}
static
fggl
::
ecs3
::
entity_t
setupBunkerPrototype
(
fggl
::
ecs3
::
World
&
world
)
{
...
...
This diff is collapsed.
Click to expand it.
include/fggl/data/heightmap.h
+
5
−
3
View file @
be357a1a
...
...
@@ -6,6 +6,8 @@
#define FGGL_HEIGHTMAP_H
#include
<cstdint>
#include
<array>
#include
"fggl/data/model.hpp"
namespace
fggl
::
data
{
...
...
@@ -16,7 +18,7 @@ namespace fggl::data {
struct
HeightMap
{
constexpr
static
const
char
name
[]
=
"Heightmap"
;
float
heightValues
[
heightMaxX
*
heightMaxZ
];
std
::
array
<
float
,
heightMaxX
*
heightMaxZ
>
heightValues
;
void
clear
()
{
for
(
float
&
heightValue
:
heightValues
)
{
...
...
@@ -26,11 +28,11 @@ namespace fggl::data {
[[
nodiscard
]]
inline
float
getValue
(
std
::
size_t
x
,
std
::
size_t
z
)
const
{
return
heightValues
[
x
*
heightMaxZ
+
z
]
;
return
heightValues
.
at
(
x
*
heightMaxZ
+
z
)
;
}
inline
void
setValue
(
std
::
size_t
x
,
std
::
size_t
z
,
float
value
)
{
heightValues
[
x
*
heightMaxZ
+
z
]
=
value
;
heightValues
.
at
(
x
*
heightMaxZ
+
z
)
=
value
;
}
};
...
...
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