This commit is contained in:
2023-08-19 06:33:56 +10:00
parent a6d6277070
commit 745476a7a0
6 changed files with 33 additions and 2 deletions

View File

@ -18,6 +18,9 @@ import com.badlogic.gdx.math.*
import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.utils.ScreenUtils
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
import ktx.math.times
import org.lwjgl.system.MathUtil
import kotlin.random.Random
class Game: ApplicationAdapter()
{
@ -37,6 +40,7 @@ class Game: ApplicationAdapter()
private lateinit var cubeInstance: ModelInstance
private lateinit var floorInstance: ModelInstance
private lateinit var suzanneInstance: ModelInstance
private lateinit var rocks: kotlin.Array<ModelInstance>
private fun makeCube(texture: Texture): Model
{
@ -122,7 +126,6 @@ class Game: ApplicationAdapter()
texJolk = assetManager.get("jolkmeup.jpg")
fntComic = assetManager.get("Comic Sans MS.ttf")
val suzanne = assetManager.get("suzanne.g3db", Model::class.java)
cube = makeCube(texJolk)
floor = makeFloor()
@ -168,7 +171,30 @@ class Game: ApplicationAdapter()
cubeInstance = ModelInstance(cube)
floorInstance = ModelInstance(floor)
suzanneInstance = ModelInstance(suzanne)
suzanneInstance = ModelInstance(assetManager.get("suzanne.g3db", Model::class.java))
val rock = assetManager.get("rock.g3db", Model::class.java)
val rand = RandomXS128(69 + 420 + 1919 + 916 + 42 + 911)
val randQuaternion = { rand: RandomXS128 ->
var x: Float
var y: Float
var z: Float
do { x = rand.nextFloat(-1.0f, 1.0f); y = rand.nextFloat(-1.0f, 1.0f); z = x * x + y * y } while (z > 1.0f)
var u: Float
var v: Float
var w: Float
do { u = rand.nextFloat(-1.0f, 1.0f); v = rand.nextFloat(-1.0f, 1.0f); w = u * u + v * v } while (w > 1.0f)
val s = kotlin.math.sqrt((1.0f - z) / w)
Quaternion(x, y, s * u, s * v)
}
rocks = Array(50) { i->
ModelInstance(rock, Matrix4(
Vector3(
rand.nextFloat(16.0f),
rand.nextFloat(-0.75f, 0.125f),
-rand.nextFloat(16.0f)),
randQuaternion(rand),
Util.one * rand.nextFloat(0.6f, 1.2f)))
}
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
}
@ -227,6 +253,7 @@ class Game: ApplicationAdapter()
modelBatch.begin(colin.camera)
modelBatch.render(floorInstance, env)
modelBatch.render(rocks.asIterable(), env)
modelBatch.render(cubeInstance, env)
modelBatch.render(suzanneInstance, env)
modelBatch.end()