Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nt1100 analyser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
nt1100 analyser
Commits
3006fcbf
Commit
3006fcbf
authored
2 years ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Finished constructor, implemented other methods
parent
a0efe750
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
src/heightmap.cpp
+51
-12
51 additions, 12 deletions
src/heightmap.cpp
with
51 additions
and
12 deletions
src/heightmap.cpp
+
51
−
12
View file @
3006fcbf
...
...
@@ -7,6 +7,7 @@
#include
<sstream>
#include
<utility>
#include
<algorithm>
#include
<resource_manager.h>
Heightmap
::
Heightmap
(
std
::
string
filename
)
:
_filename
(
filename
)
{
std
::
string
file_string
=
""
;
...
...
@@ -20,6 +21,7 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
}
catch
(
const
std
::
exception
e
){
std
::
cerr
<<
"An error occurred loading file "
<<
filename
<<
": "
<<
e
.
what
()
<<
std
::
endl
;
file_string
=
""
;
}
if
(
file_string
!=
""
)
{
...
...
@@ -62,9 +64,14 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
/*TODO: Renormalize model coordinates sensible here*/
//For now, I just renormalize the z range to [0,1]
double
zRangeInverse
=
1.
/
(
_maxZ
-
_minZ
);
for
(
auto
it
=
_data
.
begin
()
+
2
;
it
<
_data
.
end
();
it
+=
3
)
{
*
it
-=
_minZ
;
*
it
*=
zRangeInverse
;
for
(
size_t
i
=
2
;
i
<
_data
.
size
();
i
+=
3
)
{
if
(
_data
[
i
]
>=
_minZ
)
{
_data
[
i
]
-=
_minZ
;
_data
[
i
]
*=
zRangeInverse
;
}
else
{
_data
[
i
]
=
0.
;
}
}
/*Initialize Renderer Infrastructure*/
...
...
@@ -72,6 +79,14 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
glGenBuffers
(
1
,
&
_ebo
);
glGenVertexArrays
(
1
,
&
_vao
);
/*Upload VBO data*/
//Temporarily cast to float
std
::
vector
<
float
>
data_float
;
data_float
.
reserve
(
_data
.
size
());
data_float
.
insert
(
data_float
.
begin
(),
_data
.
begin
(),
_data
.
end
());
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vbo
);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
float
)
*
data_float
.
size
(),
data_float
.
data
(),
GL_STATIC_DRAW
);
/*Calculate EBO indexing array*/
std
::
vector
<
unsigned
>
ebo_array
;
ebo_array
.
reserve
(
2
*
_data
.
size
());
//rough upper bound
...
...
@@ -97,29 +112,53 @@ Heightmap::Heightmap(std::string filename): _filename(filename) {
ebo_array
.
insert
(
ebo_array
.
end
(),
index_array
.
begin
(),
index_array
.
end
());
}
}
_numElements
=
ebo_array
.
size
();
/*Upload EBO data*/
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
_ebo
);
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
)
*
ebo_array
.
size
(),
ebo_array
.
data
(),
GL_STATIC_DRAW
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
0
);
/*Upload VBO data*/
//Temporarily cast to float
std
::
vector
<
float
>
data_float
;
data_float
.
reserve
(
_data
.
size
());
data_float
.
insert
(
data_float
.
begin
(),
_data
.
begin
(),
_data
.
end
());
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vbo
);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
float
)
*
data_float
.
size
(),
data_float
.
data
(),
GL_STATIC_DRAW
);
/*Setup VAO*/
glBindVertexArray
(
_vao
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vbo
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
_ebo
);
glVertexAttribPointer
(
0
,
3
,
GL_FLOAT
,
GL_FALSE
,
3
*
sizeof
(
float
),
(
void
*
)
0
);
glEnableVertexAttribArray
(
0
);
glBindVertexArray
(
0
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
/*TODO: Generate shader, I may want to use a Factory here*/
/*TODO: This should be made prettier*/
std
::
string
vertFile
=
std
::
string
(
SHADER_LOC
)
+
std
::
string
(
"heightmap0.vert"
);
std
::
string
fragFile
=
std
::
string
(
SHADER_LOC
)
+
std
::
string
(
"heightmap0.frag"
);
_shader_ptr
=
ResourceManager
::
fetch_shader
(
vertFile
,
fragFile
);
}
else
{
throw
Nt1100_exception
(
"Heightmap::Heightmap(std::string): File "
+
filename
+
" contents are empty."
);
}
}
void
Heightmap
::
draw
(
glm
::
mat4
projection
,
glm
::
mat4
view
,
glm
::
mat4
model
){
_shader_ptr
->
use
();
_shader_ptr
->
setMat4
(
"projection"
,
projection
);
_shader_ptr
->
setMat4
(
"view"
,
view
);
_shader_ptr
->
setMat4
(
"model"
,
model
);
glBindVertexArray
(
_vao
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vbo
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
_ebo
);
glDrawElements
(
GL_TRIANGLES
,
_numElements
,
GL_UNSIGNED_INT
,
0
);
glBindVertexArray
(
0
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
_shader_ptr
->
unuse
();
}
void
Heightmap
::
upload
()
{
return
;
}
void
Heightmap
::
unload
()
{
return
;
}
bool
Heightmap
::
is
(
const
std
::
string
filename
)
const
{
return
_filename
==
filename
;
}
\ No newline at end of file
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