rock
This commit is contained in:
@ -18,6 +18,9 @@ import com.badlogic.gdx.math.*
|
|||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.badlogic.gdx.utils.ScreenUtils
|
import com.badlogic.gdx.utils.ScreenUtils
|
||||||
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
|
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
|
||||||
|
import ktx.math.times
|
||||||
|
import org.lwjgl.system.MathUtil
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class Game: ApplicationAdapter()
|
class Game: ApplicationAdapter()
|
||||||
{
|
{
|
||||||
@ -37,6 +40,7 @@ class Game: ApplicationAdapter()
|
|||||||
private lateinit var cubeInstance: ModelInstance
|
private lateinit var cubeInstance: ModelInstance
|
||||||
private lateinit var floorInstance: ModelInstance
|
private lateinit var floorInstance: ModelInstance
|
||||||
private lateinit var suzanneInstance: ModelInstance
|
private lateinit var suzanneInstance: ModelInstance
|
||||||
|
private lateinit var rocks: kotlin.Array<ModelInstance>
|
||||||
|
|
||||||
private fun makeCube(texture: Texture): Model
|
private fun makeCube(texture: Texture): Model
|
||||||
{
|
{
|
||||||
@ -122,7 +126,6 @@ class Game: ApplicationAdapter()
|
|||||||
|
|
||||||
texJolk = assetManager.get("jolkmeup.jpg")
|
texJolk = assetManager.get("jolkmeup.jpg")
|
||||||
fntComic = assetManager.get("Comic Sans MS.ttf")
|
fntComic = assetManager.get("Comic Sans MS.ttf")
|
||||||
val suzanne = assetManager.get("suzanne.g3db", Model::class.java)
|
|
||||||
|
|
||||||
cube = makeCube(texJolk)
|
cube = makeCube(texJolk)
|
||||||
floor = makeFloor()
|
floor = makeFloor()
|
||||||
@ -168,7 +171,30 @@ class Game: ApplicationAdapter()
|
|||||||
|
|
||||||
cubeInstance = ModelInstance(cube)
|
cubeInstance = ModelInstance(cube)
|
||||||
floorInstance = ModelInstance(floor)
|
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)
|
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +253,7 @@ class Game: ApplicationAdapter()
|
|||||||
|
|
||||||
modelBatch.begin(colin.camera)
|
modelBatch.begin(colin.camera)
|
||||||
modelBatch.render(floorInstance, env)
|
modelBatch.render(floorInstance, env)
|
||||||
|
modelBatch.render(rocks.asIterable(), env)
|
||||||
modelBatch.render(cubeInstance, env)
|
modelBatch.render(cubeInstance, env)
|
||||||
modelBatch.render(suzanneInstance, env)
|
modelBatch.render(suzanneInstance, env)
|
||||||
modelBatch.end()
|
modelBatch.end()
|
||||||
|
@ -49,6 +49,7 @@ class Resources private constructor()
|
|||||||
assetManager.load("cobblestone.png", Texture::class.java, linearMipped)
|
assetManager.load("cobblestone.png", Texture::class.java, linearMipped)
|
||||||
assetManager.load("cobblestone_normal.png", Texture::class.java, linearMipped)
|
assetManager.load("cobblestone_normal.png", Texture::class.java, linearMipped)
|
||||||
assetManager.load("cobblestone_specular.png", Texture::class.java, linearMipped)
|
assetManager.load("cobblestone_specular.png", Texture::class.java, linearMipped)
|
||||||
|
assetManager.load("rock.g3db", Model::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import ktx.math.times
|
|||||||
import ktx.math.unaryMinus
|
import ktx.math.unaryMinus
|
||||||
import org.hsluv.HUSLColorConverter
|
import org.hsluv.HUSLColorConverter
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
fun Float.axisDeadzone(min: Float, max: Float): Float
|
fun Float.axisDeadzone(min: Float, max: Float): Float
|
||||||
{
|
{
|
||||||
@ -72,3 +73,5 @@ fun Color.mix(rhs: Color, x: Float) = Color(
|
|||||||
//FIXME: find some way to get rid of these warnings
|
//FIXME: find some way to get rid of these warnings
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "UNCHECKED_CAST")
|
@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "UNCHECKED_CAST")
|
||||||
fun <T: Attribute> Attributes.get(type: Long) = get(type) as? T
|
fun <T: Attribute> Attributes.get(type: Long) = get(type) as? T
|
||||||
|
|
||||||
|
fun Random.nextFloat(min: Float, max: Float) = min + nextFloat() * (max - min)
|
||||||
|
BIN
src/main/resources/rock.g3db
Normal file
BIN
src/main/resources/rock.g3db
Normal file
Binary file not shown.
BIN
src/main/resources/rock.png
Normal file
BIN
src/main/resources/rock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1019 KiB |
BIN
src/main/resources/rocknorm.png
Normal file
BIN
src/main/resources/rocknorm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 KiB |
Reference in New Issue
Block a user