diff --git a/src/main/kotlin/Game.kt b/src/main/kotlin/Game.kt index 51a2bfa..3e6159c 100644 --- a/src/main/kotlin/Game.kt +++ b/src/main/kotlin/Game.kt @@ -34,11 +34,13 @@ class Game: ApplicationAdapter() private lateinit var colin: Colin private var jolkRot = 0.0f private var lightTheta = 0.0f + private val rand = RandomXS128(69 + 420 + 1919 + 916 + 42 + 1) private lateinit var cubeInstance: ModelInstance private lateinit var floorInstance: ModelInstance private lateinit var suzanneInstance: ModelInstance private lateinit var rockBatch: ModelCache + private lateinit var knux: ModelInstance private fun makeCube(texture: Texture): Model { @@ -171,26 +173,13 @@ class Game: ApplicationAdapter() floorInstance = ModelInstance(floor) 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 + 1) - 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) - } val rocks = Array(75) { i-> ModelInstance(rock, Matrix4( Vector3( rand.nextFloat(joeMany), rand.nextFloat(-0.75f, 10.125f), -rand.nextFloat(joeMany)), - randQuaternion(rand), + rand.nextQuaternion(), Util.one * rand.nextFloat(0.6f, 6.2f))) } rockBatch = ModelCache().apply { @@ -200,6 +189,7 @@ class Game: ApplicationAdapter() } suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f) + knux = ModelInstance(assetManager.get("knux.g3db", Model::class.java)) } override fun resize(width: Int, height: Int) @@ -254,12 +244,14 @@ class Game: ApplicationAdapter() .rotate(0.0f, 1.0f, 0.0f, jolkRot) .scale(0.25f, 0.25f, 0.25f) cubeInstance.transform = world + knux.transform.rotate(rand.nextQuaternion().slerp(Quaternion(), 0.9f)) modelBatch.begin(colin.camera) modelBatch.render(floorInstance, env) modelBatch.render(rockBatch, env) modelBatch.render(cubeInstance, env) modelBatch.render(suzanneInstance, env) + modelBatch.render(knux, env) modelBatch.end() spriteBatch.begin() diff --git a/src/main/kotlin/Resources.kt b/src/main/kotlin/Resources.kt index e015459..d881670 100644 --- a/src/main/kotlin/Resources.kt +++ b/src/main/kotlin/Resources.kt @@ -50,6 +50,7 @@ class Resources private constructor() assetManager.load("cobblestone_normal.png", Texture::class.java, linearMipped) assetManager.load("cobblestone_specular.png", Texture::class.java, linearMipped) assetManager.load("rock.g3db", Model::class.java) + assetManager.load("knux.g3db", Model::class.java) } } diff --git a/src/main/kotlin/Util.kt b/src/main/kotlin/Util.kt index 7e15b83..379ab5f 100644 --- a/src/main/kotlin/Util.kt +++ b/src/main/kotlin/Util.kt @@ -3,9 +3,7 @@ package gay.pizza.CavesOfJolk import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g3d.Attribute import com.badlogic.gdx.graphics.g3d.Attributes -import com.badlogic.gdx.math.MathUtils -import com.badlogic.gdx.math.Vector2 -import com.badlogic.gdx.math.Vector3 +import com.badlogic.gdx.math.* import ktx.math.div import ktx.math.times import ktx.math.unaryMinus @@ -75,3 +73,17 @@ fun Color.mix(rhs: Color, x: Float) = Color( fun Attributes.get(type: Long) = get(type) as? T fun Random.nextFloat(min: Float, max: Float) = min + nextFloat() * (max - min) + +fun RandomXS128.nextQuaternion(): Quaternion +{ + var x: Float + var y: Float + var z: Float + do { x = nextFloat(-1.0f, 1.0f); y = 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 = nextFloat(-1.0f, 1.0f); v = nextFloat(-1.0f, 1.0f); w = u * u + v * v } while (w > 1.0f) + val s = kotlin.math.sqrt((1.0f - z) / w) + return Quaternion(x, y, s * u, s * v) +} diff --git a/src/main/resources/knux.g3db b/src/main/resources/knux.g3db new file mode 100644 index 0000000..722c2d5 Binary files /dev/null and b/src/main/resources/knux.g3db differ