Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDT4240 Tank Wars
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Snorre Skjellestad Kristiansen
TDT4240 Tank Wars
Commits
43583e8e
Commit
43583e8e
authored
2 years ago
by
Jan Einar Thorvaldsen
Committed by
Sverre Wiedswang
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Create a simple terrain"
parent
eb8693e2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Resolve "Create a simple terrain"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/core/src/com/game/tankwars/model/TerrainGenerator.java
+56
-0
56 additions, 0 deletions
...nd/core/src/com/game/tankwars/model/TerrainGenerator.java
with
56 additions
and
0 deletions
frontend/core/src/com/game/tankwars/model/TerrainGenerator.java
0 → 100644
+
56
−
0
View file @
43583e8e
package
com.game.tankwars.model
;
import
com.badlogic.gdx.math.BSpline
;
import
com.badlogic.gdx.math.MathUtils
;
import
com.badlogic.gdx.math.Vector2
;
public
class
TerrainGenerator
{
float
xStart
;
float
xEnd
;
float
yMax
;
float
yMin
;
int
points
;
Vector2
[]
controlPoints
;
public
TerrainGenerator
(
float
xStart
,
float
xEnd
,
float
yMin
,
float
yMax
,
int
points
){
this
.
xStart
=
xStart
;
this
.
xEnd
=
xEnd
;
this
.
yMax
=
yMax
;
this
.
yMin
=
yMin
;
this
.
points
=
points
;
controlPoints
=
new
Vector2
[
points
];
controlPoints
[
points
-
1
]
=
new
Vector2
(
xEnd
+
2
,
MathUtils
.
random
(
yMin
,
yMax
));
controlPoints
[
0
]
=
new
Vector2
(
xStart
,
MathUtils
.
random
(
yMin
,
yMax
));
controlPoints
[
points
-
1
]
=
new
Vector2
(
xEnd
+
2
,
MathUtils
.
random
(
yMin
,
yMax
));
for
(
int
i
=
1
;
i
<
points
-
1
;
i
++){
controlPoints
[
i
]
=
new
Vector2
(
xEnd
*((
float
)
i
/((
float
)
points
-
2
)),
MathUtils
.
random
(
yMin
,
yMax
));
}
}
public
Vector2
[]
generateVertices
(
int
vertNumber
)
{
Vector2
[]
vertices
=
new
Vector2
[
vertNumber
];
Vector2
outStart
=
new
Vector2
();
Vector2
outEnd
=
new
Vector2
();
Vector2
tmp
=
new
Vector2
();
BSpline
.
cubic
(
outStart
,
0
,
controlPoints
,
false
,
tmp
);
vertices
[
0
]
=
outStart
;
BSpline
.
cubic
(
outEnd
,
1
,
controlPoints
,
false
,
tmp
);
vertices
[
vertNumber
-
1
]
=
outEnd
;
for
(
int
i
=
1
;
i
<
vertNumber
-
1
;
i
++){
Vector2
out
=
new
Vector2
();
float
t
=
(
float
)
i
/((
float
)
vertNumber
-
1
);
BSpline
.
cubic
(
out
,
t
,
controlPoints
,
false
,
tmp
);
vertices
[
i
]
=
out
;
}
return
vertices
;
}
}
\ 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