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
4ef4a829
Commit
4ef4a829
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
clean up more types in procedural
parent
c83db64a
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
fggl/data/procedural.cpp
+38
-41
38 additions, 41 deletions
fggl/data/procedural.cpp
include/fggl/data/model.hpp
+1
-1
1 addition, 1 deletion
include/fggl/data/model.hpp
with
39 additions
and
42 deletions
fggl/data/procedural.cpp
+
38
−
41
View file @
4ef4a829
...
@@ -19,7 +19,7 @@ static glm::vec3 calcSurfaceNormal(glm::vec3 vert1, glm::vec3 vert2, glm::vec3 v
...
@@ -19,7 +19,7 @@ static glm::vec3 calcSurfaceNormal(glm::vec3 vert1, glm::vec3 vert2, glm::vec3 v
return
glm
::
normalize
(
glm
::
cross
(
edge1
,
edge2
)
);
return
glm
::
normalize
(
glm
::
cross
(
edge1
,
edge2
)
);
}
}
static
void
computeNormalsDirect
(
fggl
::
data
::
Mesh
&
mesh
,
const
int
*
colIdx
,
int
nPoints
)
{
static
void
computeNormalsDirect
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
data
::
Mesh
::
IndexType
*
colIdx
,
int
nPoints
)
{
// we're assuming all the normals are zero...
// we're assuming all the normals are zero...
for
(
int
i
=
0
;
i
<
nPoints
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nPoints
;
i
++
)
{
...
@@ -41,12 +41,12 @@ static void computeNormalsDirect( fggl::data::Mesh& mesh, const int* colIdx, int
...
@@ -41,12 +41,12 @@ static void computeNormalsDirect( fggl::data::Mesh& mesh, const int* colIdx, int
}
}
static
void
compute_normals
(
fggl
::
data
::
Mesh
&
mesh
,
static
void
compute_normals
(
fggl
::
data
::
Mesh
&
mesh
,
const
std
::
vector
<
int
>&
idxList
,
// source index
const
std
::
vector
<
Mesh
::
IndexType
>&
idxList
,
// source index
const
std
::
vector
<
unsigned
int
>&
idxMapping
// source-to-mesh lookup
const
std
::
vector
<
Mesh
::
IndexType
>&
idxMapping
// source-to-mesh lookup
)
{
)
{
// clear the normals, so the summation below works correctly
// clear the normals, so the summation below works correctly
for
(
unsigned
int
vertexIndex
:
idxMapping
)
{
for
(
auto
vertexIndex
:
idxMapping
)
{
auto
&
vertex
=
mesh
.
vertex
(
vertexIndex
);
auto
&
vertex
=
mesh
.
vertex
(
vertexIndex
);
vertex
.
normal
=
ILLEGAL_NORMAL
;
vertex
.
normal
=
ILLEGAL_NORMAL
;
}
}
...
@@ -76,9 +76,9 @@ static void compute_normals(fggl::data::Mesh& mesh,
...
@@ -76,9 +76,9 @@ static void compute_normals(fggl::data::Mesh& mesh,
}
}
static
void
populateMesh
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
math
::
mat4
transform
,
static
void
populateMesh
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
math
::
mat4
transform
,
const
int
nIdx
,
const
fggl
::
math
::
vec3
*
pos
,
const
int
*
idx
)
{
const
int
nIdx
,
const
fggl
::
math
::
vec3
*
pos
,
const
Mesh
::
IndexType
*
idx
)
{
int
*
colIdx
=
new
int
[
nIdx
];
auto
*
colIdx
=
new
fggl
::
data
::
Mesh
::
IndexType
[
nIdx
];
// generate mesh
// generate mesh
for
(
int
i
=
0
;
i
<
nIdx
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nIdx
;
i
++
)
{
...
@@ -95,7 +95,7 @@ static void populateMesh(fggl::data::Mesh& mesh, const fggl::math::mat4 transfor
...
@@ -95,7 +95,7 @@ static void populateMesh(fggl::data::Mesh& mesh, const fggl::math::mat4 transfor
static
void
populateMesh
(
fggl
::
data
::
Mesh
&
mesh
,
static
void
populateMesh
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
math
::
mat4
transform
,
const
fggl
::
math
::
mat4
transform
,
const
std
::
vector
<
fggl
::
math
::
vec3
>&
posList
,
const
std
::
vector
<
fggl
::
math
::
vec3
>&
posList
,
const
std
::
vector
<
int
>&
idxList
)
{
const
std
::
vector
<
fggl
::
data
::
Mesh
::
IndexType
>&
idxList
)
{
// tmp store the resulting mesh indexes (incase the mesh has multiple primatives)
// tmp store the resulting mesh indexes (incase the mesh has multiple primatives)
std
::
vector
<
unsigned
int
>
colIdx
;
std
::
vector
<
unsigned
int
>
colIdx
;
...
@@ -117,7 +117,7 @@ static void populateMesh(fggl::data::Mesh& mesh,
...
@@ -117,7 +117,7 @@ static void populateMesh(fggl::data::Mesh& mesh,
namespace
fggl
::
data
{
namespace
fggl
::
data
{
static
void
quads2Tris
(
std
::
vector
<
int
>&
indexList
,
int
stacks
,
int
slices
)
{
static
void
quads2Tris
(
std
::
vector
<
Mesh
::
IndexType
>&
indexList
,
int
stacks
,
int
slices
)
{
const
auto
HORZ_SIZE
=
slices
+
1
;
const
auto
HORZ_SIZE
=
slices
+
1
;
for
(
int
vertical
=
0
;
vertical
<
stacks
;
vertical
++
)
{
for
(
int
vertical
=
0
;
vertical
<
stacks
;
vertical
++
)
{
for
(
int
horz
=
0
;
horz
<
slices
;
horz
++
)
{
for
(
int
horz
=
0
;
horz
<
slices
;
horz
++
)
{
...
@@ -159,7 +159,7 @@ namespace fggl::data {
...
@@ -159,7 +159,7 @@ namespace fggl::data {
}
}
// combine the vertices into triangles
// combine the vertices into triangles
std
::
vector
<
int
>
indexList
;
std
::
vector
<
Mesh
::
IndexType
>
indexList
;
quads2Tris
(
indexList
,
stacks
,
slices
);
quads2Tris
(
indexList
,
stacks
,
slices
);
populateMesh
(
mesh
,
offset
,
positions
,
indexList
);
populateMesh
(
mesh
,
offset
,
positions
,
indexList
);
...
@@ -244,36 +244,33 @@ fggl::data::Mesh fggl::data::make_quad_xz() {
...
@@ -244,36 +244,33 @@ fggl::data::Mesh fggl::data::make_quad_xz() {
fggl
::
data
::
Mesh
fggl
::
data
::
make_cube
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
math
::
mat4
&
transform
)
{
fggl
::
data
::
Mesh
fggl
::
data
::
make_cube
(
fggl
::
data
::
Mesh
&
mesh
,
const
fggl
::
math
::
mat4
&
transform
)
{
// done as two loops, top loop is 0,1,2,3, bottom loop is 4,5,6,7
// done as two loops, top loop is 0,1,2,3, bottom loop is 4,5,6,7
constexpr
fggl
::
math
::
vec3
pos
[]
{
constexpr
std
::
array
<
fggl
::
math
::
vec3
,
8
>
pos
{{
{
-
0.5
,
0.5
,
-
0.5
},
// 0 TOP LOOP
{
-
0.5
,
0.5
,
-
0.5
},
// 0 TOP LOOP
{
0.5
,
0.5
,
-
0.5
},
// 1
{
0.5
,
0.5
,
-
0.5
},
// 1
{
0.5
,
0.5
,
0.5
},
// 2
{
0.5
,
0.5
,
0.5
},
// 2
{
-
0.5
,
0.5
,
0.5
},
// 3
{
-
0.5
,
0.5
,
0.5
},
// 3
{
-
0.5
,
-
0.5
,
-
0.5
},
// 4 BOTTOM LOOP
{
-
0.5
,
-
0.5
,
-
0.5
},
// 4 BOTTOM LOOP
{
0.5
,
-
0.5
,
-
0.5
},
// 5
{
0.5
,
-
0.5
,
-
0.5
},
// 5
{
0.5
,
-
0.5
,
0.5
},
// 6
{
0.5
,
-
0.5
,
0.5
},
// 6
{
-
0.5
,
-
0.5
,
0.5
}
// 7
{
-
0.5
,
-
0.5
,
0.5
}
// 7
};
}};
constexpr
int
idx
[]
{
constexpr
std
::
array
<
Mesh
::
IndexType
,
36
>
idx
{{
0
,
3
,
1
,
// top
0
,
3
,
1
,
// top
3
,
2
,
1
,
3
,
2
,
1
,
0
,
1
,
4
,
// side 0 - 1
0
,
1
,
4
,
// side 0 - 1
5
,
4
,
1
,
5
,
4
,
1
,
1
,
2
,
5
,
// side 1 - 2
1
,
2
,
5
,
// side 1 - 2
2
,
6
,
5
,
2
,
6
,
5
,
3
,
7
,
2
,
// side 2 - 3
3
,
7
,
2
,
// side 2 - 3
2
,
7
,
6
,
2
,
7
,
6
,
0
,
4
,
3
,
// side 3 - 0
0
,
4
,
3
,
// side 3 - 0
4
,
7
,
3
,
4
,
7
,
3
,
4
,
5
,
7
,
// bottom
4
,
5
,
7
,
// bottom
7
,
5
,
6
,
7
,
5
,
6
,
};
}};
populateMesh
(
mesh
,
transform
,
idx
.
size
(),
pos
.
data
(),
idx
.
data
());
int
nIdx
=
sizeof
(
idx
)
/
sizeof
(
int
);
populateMesh
(
mesh
,
transform
,
nIdx
,
pos
,
idx
);
return
mesh
;
return
mesh
;
}
}
...
@@ -292,7 +289,7 @@ fggl::data::Mesh fggl::data::make_slope(fggl::data::Mesh& mesh, const fggl::math
...
@@ -292,7 +289,7 @@ fggl::data::Mesh fggl::data::make_slope(fggl::data::Mesh& mesh, const fggl::math
{
-
0.5
,
-
0.5
,
0.5
}
// 7
{
-
0.5
,
-
0.5
,
0.5
}
// 7
};
};
constexpr
int
idx
[]
{
constexpr
Mesh
::
IndexType
idx
[]
{
0
,
7
,
1
,
// ramp
0
,
7
,
1
,
// ramp
7
,
6
,
1
,
7
,
6
,
1
,
0
,
1
,
4
,
// side 0 - 1
0
,
1
,
4
,
// side 0 - 1
...
@@ -324,7 +321,7 @@ fggl::data::Mesh fggl::data::make_ditch(fggl::data::Mesh& mesh, const fggl::math
...
@@ -324,7 +321,7 @@ fggl::data::Mesh fggl::data::make_ditch(fggl::data::Mesh& mesh, const fggl::math
{
-
0.5
,
-
0.5
,
0.5
}
// 7
{
-
0.5
,
-
0.5
,
0.5
}
// 7
};
};
constexpr
int
idx
[]
{
constexpr
Mesh
::
IndexType
idx
[]
{
0
,
3
,
1
,
// top
0
,
3
,
1
,
// top
3
,
6
,
1
,
3
,
6
,
1
,
0
,
1
,
4
,
// side 0 - 1
0
,
1
,
4
,
// side 0 - 1
...
@@ -356,7 +353,7 @@ fggl::data::Mesh fggl::data::make_point(fggl::data::Mesh& mesh, const fggl::math
...
@@ -356,7 +353,7 @@ fggl::data::Mesh fggl::data::make_point(fggl::data::Mesh& mesh, const fggl::math
{
-
0.5
,
-
0.5
,
0.5
}
// 7
{
-
0.5
,
-
0.5
,
0.5
}
// 7
};
};
constexpr
int
idx
[]
{
constexpr
Mesh
::
IndexType
idx
[]
{
0
,
7
,
5
,
// top
0
,
7
,
5
,
// top
7
,
6
,
5
,
7
,
6
,
5
,
0
,
5
,
4
,
// side 0 - 1
0
,
5
,
4
,
// side 0 - 1
...
...
This diff is collapsed.
Click to expand it.
include/fggl/data/model.hpp
+
1
−
1
View file @
4ef4a829
...
@@ -66,10 +66,10 @@ namespace fggl::data {
...
@@ -66,10 +66,10 @@ namespace fggl::data {
}
}
class
Mesh
{
class
Mesh
{
public:
using
IndexType
=
unsigned
int
;
using
IndexType
=
unsigned
int
;
constexpr
static
const
IndexType
INVALID_IDX
=
IndexType
(
UINT_MAX
);
constexpr
static
const
IndexType
INVALID_IDX
=
IndexType
(
UINT_MAX
);
public:
Mesh
();
Mesh
();
~
Mesh
()
=
default
;
~
Mesh
()
=
default
;
...
...
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