Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Autumn2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sindre Eiklid
Autumn2020
Commits
2db9b15d
Commit
2db9b15d
authored
4 years ago
by
Sindre Eiklid
Browse files
Options
Downloads
Patches
Plain Diff
Randomize tree placement
parent
c0d89d4c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
class/header/entity.h
+1
-1
1 addition, 1 deletion
class/header/entity.h
class/header/vegetation.h
+4
-1
4 additions, 1 deletion
class/header/vegetation.h
class/shader/modelShader.h
+1
-1
1 addition, 1 deletion
class/shader/modelShader.h
class/vegetation.cpp
+4
-4
4 additions, 4 deletions
class/vegetation.cpp
with
10 additions
and
7 deletions
class/header/entity.h
+
1
−
1
View file @
2db9b15d
...
...
@@ -15,7 +15,7 @@ class Entity {
GLuint
aerialShaderProgram
=
0
,
groundShaderProgram
=
0
;
GLuint
aerialVAO
=
0
,
groundVAO
=
0
;
int
aerialMeshAmount
=
0
,
groundMeshAmount
=
0
;
glm
::
vec3
aerialInstancePos
[
42
],
groundInstancePos
[
1
8
];
glm
::
vec3
aerialInstancePos
[
1000
],
groundInstancePos
[
1
000
];
int
aerialInstanceIndex
=
0
,
groundInstanceIndex
=
0
;
std
::
vector
<
int
>
aerialLastDirection
,
groundLastDirection
;
std
::
vector
<
std
::
vector
<
int
>>
aerialGridPosition
,
groundGridPosition
;
...
...
This diff is collapsed.
Click to expand it.
class/header/vegetation.h
+
4
−
1
View file @
2db9b15d
...
...
@@ -3,6 +3,7 @@
/* library */
#include
<GL/glew.h>
#include
<GLFW/glfw3.h>
#include
<glm/glm.hpp>
#include
<vector>
/**
* @brief Vegetation class.
...
...
@@ -13,7 +14,9 @@ class Vegetation {
/* private data */
GLuint
shaderProgram
=
0
;
GLuint
VAO
=
0
;
int
meshAmount
=
0
,
instanceIndex
=
0
;
int
meshAmount
=
0
;
glm
::
vec3
instancePos
[
1000
];
int
instanceIndex
=
0
;
public:
/* public functionality */
~
Vegetation
();
...
...
This diff is collapsed.
Click to expand it.
class/shader/modelShader.h
+
1
−
1
View file @
2db9b15d
...
...
@@ -15,7 +15,7 @@ static const std::string modelVertexShader = R"(
uniform mat4 u_modelMatrix = mat4(1);
uniform mat4 u_viewMatrix = mat4(1);
uniform mat4 u_projectionMatrix = mat4(1);
uniform vec3 offsets[
6
00];
uniform vec3 offsets[
10
00];
/**
* Main vertex shader program.
*/
...
...
This diff is collapsed.
Click to expand it.
class/vegetation.cpp
+
4
−
4
View file @
2db9b15d
...
...
@@ -5,7 +5,6 @@
#include
"camera.h"
#include
"mapData.h"
#include
"functionality.h"
#include
<glm/glm.hpp>
#include
<glm/gtx/matrix_transform_2d.hpp>
#include
<glm/gtc/type_ptr.hpp>
#include
<iostream>
...
...
@@ -39,7 +38,6 @@ Vegetation::Vegetation() {
modelMatrix
=
glm
::
scale
(
glm
::
mat4
(
1.f
),
glm
::
vec3
(
0.01f
));
glUniformMatrix4fv
(
glGetUniformLocation
(
shaderProgram
,
"u_modelMatrix"
),
1
,
GL_FALSE
,
glm
::
value_ptr
(
modelMatrix
));
//generate coordinates for each instance
glm
::
vec3
gridInstancePos
[
600
];
for
(
int
i
=
0
;
i
<
g_mapData
->
gridHeight
;
i
+=
5
)
{
for
(
int
j
=
0
;
j
<
g_mapData
->
gridWidth
;
j
+=
5
)
{
//branch if depth is between 42 and 79 (in green area)
...
...
@@ -49,18 +47,20 @@ Vegetation::Vegetation() {
translation
.
x
=
g_mapData
->
gridElement
[
std
::
make_pair
(
i
,
j
)][
0
][
X
]
*
(
100.f
*
2.f
);
translation
.
z
=
-
g_mapData
->
gridElement
[
std
::
make_pair
(
i
,
j
)][
0
][
Y
]
*
(
100.f
*
2.f
);
translation
.
y
=
g_mapData
->
gridElement
[
std
::
make_pair
(
i
,
j
)][
0
][
Z
]
*
(
100.f
*
2.f
);
gridI
nstancePos
[
instanceIndex
]
=
translation
;
i
nstancePos
[
instanceIndex
]
=
translation
;
instanceIndex
++
;
if
(
j
+
10
<
g_mapData
->
gridWidth
)
j
+=
randomIndex
(
2
,
5
);
//remember initial position to compute coalition when moving entities
g_mapData
->
obstaclesInGridElement
[
i
][
j
]
=
false
;
}
}
}
std
::
cout
<<
instanceIndex
<<
std
::
endl
;
//send initial position to uniform
for
(
unsigned
int
i
=
0
;
i
<
instanceIndex
;
i
++
)
{
std
::
string
buffer
=
"offsets["
+
std
::
to_string
(
i
)
+
"]"
;
const
char
*
uniformLoc
=
buffer
.
c_str
();
glUniform3fv
(
glGetUniformLocation
(
shaderProgram
,
uniformLoc
),
1
,
glm
::
value_ptr
(
gridI
nstancePos
[
i
]));
glUniform3fv
(
glGetUniformLocation
(
shaderProgram
,
uniformLoc
),
1
,
glm
::
value_ptr
(
i
nstancePos
[
i
]));
}
glUseProgram
(
0
);
}
...
...
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