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
0f55c89b
Commit
0f55c89b
authored
3 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
add object placement
parent
784b2324
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demo/main.cpp
+42
-15
42 additions, 15 deletions
demo/main.cpp
with
42 additions
and
15 deletions
demo/main.cpp
+
42
−
15
View file @
0f55c89b
...
...
@@ -78,6 +78,20 @@ void process_camera(fggl::ecs3::World& ecs, const InputManager& input) {
fggl
::
input
::
process_edgescroll
(
ecs
,
*
input
,
cam
);
}
void
placeObject
(
fggl
::
ecs3
::
World
&
world
,
fggl
::
ecs
::
entity_t
parent
,
fggl
::
ecs
::
entity_t
prototype
,
glm
::
vec3
targetPos
)
{
auto
obj
=
world
.
copy
(
prototype
);
auto
result
=
world
.
get
<
fggl
::
math
::
Transform
>
(
obj
);
int
xPos
=
(
int
)
targetPos
.
x
;
int
zPos
=
(
int
)
targetPos
.
z
*
-
1
;
// figure out the floor height
auto
heightMap
=
world
.
get
<
fggl
::
data
::
HeightMap
>
(
parent
);
targetPos
.
y
=
heightMap
->
getValue
(
xPos
,
zPos
);
// TODO should really be the gradient at the required point
result
->
origin
(
targetPos
);
}
class
MenuScene
:
public
fggl
::
scenes
::
Scene
{
public:
...
...
@@ -103,8 +117,8 @@ public:
}
private
:
InputManager
m_inputs
;
private
:
InputManager
m_inputs
;
};
...
...
@@ -159,6 +173,23 @@ public:
m_world
.
set
<
fggl
::
data
::
HeightMap
>
(
terrain
,
&
terrainData
);
}
// create foundation object
fggl
::
ecs3
::
entity_t
foundation
;
{
foundation
=
m_world
.
create
(
true
);
m_world
.
add
(
foundation
,
types
.
find
(
fggl
::
math
::
Transform
::
name
));
// plot rendering
fggl
::
data
::
Mesh
mesh
;
fggl
::
data
::
make_cube
(
mesh
);
mesh
.
removeDups
();
// add mesh as a component
constexpr
char
shader
[]
=
"phong"
;
fggl
::
gfx
::
StaticMesh
staticMesh
{
mesh
,
shader
};
m_world
.
set
<
fggl
::
gfx
::
StaticMesh
>
(
foundation
,
&
staticMesh
);
}
// create building prototype
fggl
::
ecs3
::
entity_t
bunker
;
{
...
...
@@ -192,21 +223,17 @@ public:
m_world
.
set
<
fggl
::
gfx
::
StaticMesh
>
(
bunker
,
&
staticMesh
);
}
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
glm
::
vec3
location
(
i
*
6.5
f
+
1.0
f
,
0.0
f
,
-
7.0
f
);
placeObject
(
m_world
,
terrain
,
foundation
,
location
);
}
int
nCubes
=
3
;
for
(
int
i
=
0
;
i
<
nCubes
;
i
++
)
{
auto
bunkerClone
=
m_world
.
copy
(
bunker
);
auto
result
=
m_world
.
get
<
fggl
::
math
::
Transform
>
(
bunkerClone
);
float
x
=
(
float
)
i
*
6.
f
+
1.0
f
;
int
xPos
=
(
int
)
x
;
float
z
=
(
float
)
-
5.0
f
+
1.0
f
;
int
zPos
=
(
int
)
z
*
-
1
;
// figure out the floor height
auto
heightMap
=
m_world
.
get
<
fggl
::
data
::
HeightMap
>
(
terrain
);
float
y
=
heightMap
->
getValue
(
xPos
,
zPos
);
// TODO should really be the gradient at the required point
result
->
origin
(
glm
::
vec3
(
x
,
y
,
z
)
);
glm
::
vec3
location
;
location
.
x
=
i
*
6.
f
+
1.0
f
;
location
.
z
=
-
5.0
f
+
1.0
f
;
placeObject
(
m_world
,
terrain
,
bunker
,
location
);
}
}
...
...
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