aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2020-01-01 16:31:53 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2020-01-01 16:31:53 +0000
commit7f13eed4ec19cf01e049af752c87f7e010e301b6 (patch)
tree5e088a0f24d2b4e4ebc3449ea1fe4b606b57ea07 /src
parent89e6b7e1fa7f27dcc6cd1b8e3b11fc445b73606a (diff)
downloadterrain-7f13eed4ec19cf01e049af752c87f7e010e301b6.tar.xz
terrain-7f13eed4ec19cf01e049af752c87f7e010e301b6.zip
Add additional fine noise. Code cleanup.
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/Terrain.kt30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/main/kotlin/Terrain.kt b/src/main/kotlin/Terrain.kt
index 2568202..73f0321 100644
--- a/src/main/kotlin/Terrain.kt
+++ b/src/main/kotlin/Terrain.kt
@@ -50,7 +50,8 @@ class Terrain {
2.9,
4,
16,
- false)
+ false
+ )
init {
@@ -75,6 +76,7 @@ class Terrain {
}
controls = OrbitControls(camera, renderer.domElement)
+ controls.autoRotate = true
seedNoise()
@@ -113,18 +115,19 @@ class Terrain {
scene.remove(terrainMesh)
}
- terrainGeometry = PlaneGeometry(100,100, size-1, size-1)
+ terrainGeometry = PlaneGeometry(100, 100, size - 1, size - 1)
for (x in 0 until size) {
for (y in 0 until size) {
- if (x == 0 || x == size-1 || y == 0 || y == size-1) {
- terrainGeometry.vertices[x + (y*size)].setZ(0)
+ if (x == 0 || x == size - 1 || y == 0 || y == size - 1) {
+ terrainGeometry.vertices[x + (y * size)].setZ(0)
} else {
var noise = simplexNoise.noise2D(x / options.zoomFactor.toDouble(), y / options.zoomFactor.toDouble())
// add some fine noise
- noise += (0.03 * simplexNoise.noise2D(x/15.toDouble(), y/15.toDouble()))
+ noise += (0.03 * simplexNoise.noise2D(x / 15.toDouble(), y / 15.toDouble()))
+ noise += (0.01 * simplexNoise.noise2D(x / 5.toDouble(), y / 5.toDouble()))
noise += 2
noise = noise.pow(options.scalingFactor)
@@ -179,14 +182,15 @@ class Terrain {
scene.remove(waterMesh)
}
- waterGeometry = BoxGeometry(99,99, options.waterHeight)
+ waterGeometry = BoxGeometry(99, 99, options.waterHeight)
waterTexture = TextureLoader().load("waternormals.jpg", {
it.wrapS = THREE.RepeatWrapping
it.wrapT = THREE.RepeatWrapping
})
- waterMesh = Water(waterGeometry,
+ waterMesh = Water(
+ waterGeometry,
WaterParams(
waterNormals = waterTexture,
alpha = 1.0,
@@ -194,12 +198,13 @@ class Terrain {
sunColor = Color(0xffffff),
waterColor = Color(0x001e0f),
distortionScale = 5.0
- ))
+ )
+ )
.apply {
receiveShadows = true
translateZ(options.waterHeight)
rotation.x = -PI / 2
- position.set(0, options.waterHeight / 2 , 0)
+ position.set(0, options.waterHeight / 2, 0)
}
.also(scene::add)
@@ -268,10 +273,8 @@ class Terrain {
it.add(this.options, "showWireframe").onChange { regenerateTerrain() }
it.add(controls, "autoRotate")
}
-
}
}
-
}
fun animate() {
@@ -288,9 +291,8 @@ class Terrain {
animate()
}
- }, 1000/30)
+ }, 1000 / 30)
renderer.render(scene, camera)
}
-
-}
+} \ No newline at end of file