mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 13:34:06 +09:00
working procedural lightning demo, except for branches
Former-commit-id: cfb11fb0cc3758c996998de40ad81d0e1a21bf81 Former-commit-id: 956263058b8ba2a662c26f46b9dc9f9766d6e7ce
This commit is contained in:
@@ -36,7 +36,7 @@ class TileableValueNoise(
|
|||||||
octaveLoop@ for (octcnt in 0..octaves - 1) { // 1, 2, 3, 4, ...
|
octaveLoop@ for (octcnt in 0..octaves - 1) { // 1, 2, 3, 4, ...
|
||||||
val i = octavesIntStream[octcnt] // 1, 2, 4, 8, ...
|
val i = octavesIntStream[octcnt] // 1, 2, 4, 8, ...
|
||||||
// octave 1 samples four points
|
// octave 1 samples four points
|
||||||
val samples = 4 * i
|
val samples = 8 * i
|
||||||
val amp = FastMath.pow(persistency, octcnt.toFloat()) // 1/1, 1/2, 1/3, 1/4, ...
|
val amp = FastMath.pow(persistency, octcnt.toFloat()) // 1/1, 1/2, 1/3, 1/4, ...
|
||||||
var pointThis = 0f
|
var pointThis = 0f
|
||||||
var pointNext = rng.nextBipolarFloat()
|
var pointNext = rng.nextBipolarFloat()
|
||||||
@@ -69,7 +69,7 @@ class TileableValueNoise(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e: ArithmeticException) {
|
catch (e: ArithmeticException) {
|
||||||
println("[TileableValueNoise] division by zero error occured, aborting further octave iteration.")
|
//println("[TileableValueNoise] division by zero error occured, aborting further octave iteration.")
|
||||||
break@octaveLoop
|
break@octaveLoop
|
||||||
} // division by zero; which means octave value was too high
|
} // division by zero; which means octave value was too high
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum
|
|||||||
|
|
||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.colourutil.ColourTemp
|
||||||
import net.torvald.point.Point2d
|
import net.torvald.point.Point2d
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.random.TileableValueNoise
|
import net.torvald.random.TileableValueNoise
|
||||||
@@ -29,56 +30,74 @@ import javax.sound.sampled.AudioSystem
|
|||||||
*/
|
*/
|
||||||
class StateTestingSandbox : BasicGameState() {
|
class StateTestingSandbox : BasicGameState() {
|
||||||
|
|
||||||
val lightning_start = Point2d(50.0, 200.0)
|
val lightning_start = Point2d(50.0, 100.0)
|
||||||
val lightning_end = Point2d(750.0, 200.0)
|
val lightning_end = Point2d(750.0, 300.0)
|
||||||
|
|
||||||
val bolt = LightingBolt(lightning_start, lightning_end, 50)
|
val bolt = LightingBolt(lightning_start, lightning_end, 50)
|
||||||
|
|
||||||
val noiseGen = TileableValueNoise(6, 0.4f, 128)
|
|
||||||
|
|
||||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||||
noiseGen.generate(seed)
|
reseed(genOnly = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
||||||
|
/*timer += delta
|
||||||
|
if (timer > regenTime) {
|
||||||
|
timer -= regenTime
|
||||||
|
reseed()
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getID() = Terrarum.STATE_ID_TEST_SHIT
|
override fun getID() = Terrarum.STATE_ID_TEST_SHIT
|
||||||
|
|
||||||
|
|
||||||
|
private var timer = 0
|
||||||
private var regenTime = 17
|
private var regenTime = 17
|
||||||
|
|
||||||
private var seed = 1L
|
private var seed = 1L
|
||||||
|
|
||||||
|
val samples = 256
|
||||||
|
|
||||||
|
val lightningXgen = TileableValueNoise(8, 0.67f, samples)
|
||||||
|
val lightningYgen = TileableValueNoise(8, 0.36f, samples)
|
||||||
|
|
||||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||||
g.color = Color.white
|
g.color = ColourTemp(7500)
|
||||||
g.lineWidth = 3f
|
g.lineWidth = 3f
|
||||||
|
|
||||||
//g.drawLine(lightning_start, lightning_end)
|
//g.drawLine(lightning_start, lightning_end)
|
||||||
//bolt.draw(g)
|
//bolt.draw(g)
|
||||||
|
|
||||||
|
|
||||||
val amp = 60f
|
val ampY = 40f
|
||||||
|
val ampX = 3
|
||||||
val xoff = 10f
|
val xoff = 10f
|
||||||
val yoff = 300f
|
val yoff = 300f
|
||||||
|
|
||||||
for (x in 0..noiseGen.width - 1) {
|
for (x in 0..lightningYgen.width - 1) {
|
||||||
val pStart = noiseGen[x] * amp + yoff
|
val pXstart = (x + lightningXgen[x ]) * ampX + xoff
|
||||||
val pEnd = noiseGen[x + 1] * amp + yoff
|
val pXend = (x + 1 + lightningXgen[x + 1]) * ampX + xoff
|
||||||
val step = 6
|
val pYstart = lightningYgen[x ] * ampY + yoff
|
||||||
|
val pYend = lightningYgen[x + 1] * ampY + yoff
|
||||||
|
|
||||||
g.drawLine(x * step + xoff, pStart,
|
g.drawLine(pXstart, pYstart, pXend, pYend)
|
||||||
(x+1) * step + xoff, pEnd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.color = Color.red
|
g.color = Color.red
|
||||||
g.lineWidth = 1f
|
g.lineWidth = 1f
|
||||||
|
|
||||||
g.drawLine(xoff, yoff, xoff + noiseGen.width * 6, yoff)
|
g.drawLine(xoff, yoff, xoff + lightningYgen.width * ampX, yoff)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun keyPressed(key: Int, c: Char) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
if (c == ' ') noiseGen.generate(++seed)
|
if (c == ' ') reseed()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reseed(genOnly: Boolean = false) {
|
||||||
|
if (!genOnly) seed = System.nanoTime()
|
||||||
|
lightningXgen.generate(0x51621DL xor seed)
|
||||||
|
lightningYgen.generate(seed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user