Compare commits

...

4 Commits

Author SHA1 Message Date
9cde1d98e2 cache ur rocks 2023-08-19 06:58:55 +10:00
745476a7a0 rock 2023-08-19 06:33:56 +10:00
a6d6277070 party refactors in the house tonight 2023-08-19 05:46:29 +10:00
81064b497f wrinkly woman 2023-08-19 02:16:02 +10:00
10 changed files with 110 additions and 76 deletions

View File

@@ -40,10 +40,7 @@ class Colin
private fun updateCamera() private fun updateCamera()
{ {
cam.position.set(Vector3(pos.x, 1.0f, pos.y)) cam.position.set(Vector3(pos.x, 1.0f, pos.y))
val forward = Vector3(0.0f, 0.0f, -1.0f) cam.direction.set(Util.forward.rotateRad(Util.right, offsAngle.y).rotateRad(Util.up, offsAngle.x + angle))
val up = Vector3(0.0f, 1.0f, 0.0f)
val right = Vector3(1.0f, 0.0f, 0.0f)
cam.direction.set(forward.rotateRad(right, offsAngle.y).rotateRad(up, offsAngle.x + angle))
cam.update() cam.update()
} }

View File

@@ -13,11 +13,12 @@ import com.badlogic.gdx.graphics.g3d.model.data.*
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider import com.badlogic.gdx.graphics.g3d.utils.TextureProvider.AssetTextureProvider
import com.badlogic.gdx.math.* 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
class Game: ApplicationAdapter() class Game: ApplicationAdapter()
{ {
@@ -37,6 +38,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 rockBatch: ModelCache
private fun makeCube(texture: Texture): Model private fun makeCube(texture: Texture): Model
{ {
@@ -58,76 +60,61 @@ class Game: ApplicationAdapter()
private fun makeFloor(): Model private fun makeFloor(): Model
{ {
val model = ModelData()
val mesh = ModelMesh()
mesh.id = "floormodel"
mesh.attributes = arrayOf(
VertexAttribute.Position(),
VertexAttribute.Normal(),
VertexAttribute.Tangent(),
VertexAttribute.Binormal(),
VertexAttribute.TexCoords(0))
val normal = Vector3(0.0f, 1.0f, 0.0f)
val tangent = Vector3(1.0f, 0.0f, 0.0f)
val bitangent = Vector3(0.0f, 0.0f, -1.0f)
val vertex = { pos: Vector3, tex: Vector2, norm: Vector3, tan: Vector3, bitan: Vector3 -> floatArrayOf(
pos.x, pos.y, pos.z,
norm.x, norm.y, norm.z,
tan.x, tan.y, tan.z,
bitan.x, bitan.y, bitan.z,
tex.x, tex.y
)}
val size = 16.0f val size = 16.0f
val texs = 4.0f val texs = 4.0f
mesh.vertices =
vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs), normal, tangent, bitangent) +
vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs), normal, tangent, bitangent) +
vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f), normal, tangent, bitangent) +
vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f), normal, tangent, bitangent)
val part = ModelMeshPart()
part.id = "floormesh"
part.primitiveType = GL20.GL_TRIANGLES
part.indices = shortArrayOf(
0, 1, 2,
3, 2, 1)
mesh.parts = arrayOf(part)
model.addMesh(mesh)
val material = ModelMaterial() val vertex = { pos: Vector3, tex: Vector2 ->
material.id = "floormat" val normal = Util.up
material.diffuse = XnaColor.White val tangent = Util.right
material.specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f) val bitangent = Util.forward
material.shininess = 65.0f floatArrayOf(
val diffuse = ModelTexture() pos.x, pos.y, pos.z,
diffuse.usage = ModelTexture.USAGE_DIFFUSE normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, bitangent.x, bitangent.y, bitangent.z,
diffuse.fileName = "cobblestone.png" tex.x, tex.y)
val normalMap = ModelTexture() }
normalMap.usage = ModelTexture.USAGE_NORMAL
normalMap.fileName = "cobblestone_normal.png"
val specular = ModelTexture()
specular.usage = ModelTexture.USAGE_SPECULAR
specular.fileName = "cobblestone_specular.png"
material.textures = Array()
material.textures.add(diffuse, normalMap, specular)
model.materials.add(material)
val node = ModelNode() val modelTexture = { modelTextureUsage: Int, textureFilename: String -> ModelTexture().apply {
node.id = "floornode" usage = modelTextureUsage
node.scale = Vector3(1.0f, 1.0f, 1.0f) fileName = textureFilename
node.rotation = Quaternion() }}
val nodePart = ModelNodePart()
nodePart.meshPartId = "floormesh"
nodePart.materialId = "floormat"
node.parts = arrayOf(nodePart)
model.nodes.add(node)
return Model(model, TextureProvider.FileTextureProvider( return Model(ModelData().apply {
Texture.TextureFilter.Nearest, addMesh(ModelMesh().apply {
Texture.TextureFilter.Nearest, id = "floormodel"
Texture.TextureWrap.Repeat, attributes = arrayOf(VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.Tangent(), VertexAttribute.Binormal(), VertexAttribute.TexCoords(0))
Texture.TextureWrap.Repeat, vertices =
false)) vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs)) +
vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs)) +
vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f)) +
vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f))
parts = arrayOf(ModelMeshPart().apply {
id = "floormesh"
primitiveType = GL20.GL_TRIANGLES
indices = shortArrayOf(
0, 1, 2,
3, 2, 1)
})
})
materials.add(ModelMaterial().apply {
id = "floormat"
diffuse = XnaColor.White
specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f)
shininess = 65.0f
textures = Array()
textures.add(
modelTexture(ModelTexture.USAGE_DIFFUSE, "cobblestone.png"),
modelTexture(ModelTexture.USAGE_NORMAL, "cobblestone_normal.png"),
modelTexture(ModelTexture.USAGE_SPECULAR, "cobblestone_specular.png"))
})
nodes.add(ModelNode().apply {
id = "floornode"
scale = Util.one
parts = arrayOf(ModelNodePart().apply {
meshPartId = "floormesh"
materialId = "floormat"
})
})
}, AssetTextureProvider(assetManager))
} }
override fun create() override fun create()
@@ -137,11 +124,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)
// Override ridiculous shininess because i cbf to fix the model
for (i in suzanne.materials)
i.set(FloatAttribute.createShininess(30.0f))
cube = makeCube(texJolk) cube = makeCube(texJolk)
floor = makeFloor() floor = makeFloor()
@@ -187,7 +169,36 @@ 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)
}
val 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)))
}
rockBatch = ModelCache().apply {
begin()
add(rocks.asIterable())
end()
}
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f) suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
} }
@@ -246,6 +257,7 @@ class Game: ApplicationAdapter()
modelBatch.begin(colin.camera) modelBatch.begin(colin.camera)
modelBatch.render(floorInstance, env) modelBatch.render(floorInstance, env)
modelBatch.render(rockBatch, env)
modelBatch.render(cubeInstance, env) modelBatch.render(cubeInstance, env)
modelBatch.render(suzanneInstance, env) modelBatch.render(suzanneInstance, env)
modelBatch.end() modelBatch.end()
@@ -261,6 +273,7 @@ class Game: ApplicationAdapter()
override fun dispose() override fun dispose()
{ {
rockBatch.dispose()
floor.dispose() floor.dispose()
cube.dispose() cube.dispose()
modelBatch.dispose() modelBatch.dispose()

View File

@@ -1,6 +1,7 @@
package gay.pizza.CavesOfJolk package gay.pizza.CavesOfJolk
import com.badlogic.gdx.assets.AssetManager import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.assets.loaders.TextureLoader
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver
import com.badlogic.gdx.audio.Sound import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
@@ -30,6 +31,14 @@ class Resources private constructor()
assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver)) assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver))
} }
val linearMipped = TextureLoader.TextureParameter().apply {
minFilter = Texture.TextureFilter.MipMapLinearLinear
magFilter = Texture.TextureFilter.Linear
wrapU = Texture.TextureWrap.Repeat
wrapV = Texture.TextureWrap.Repeat
genMipMaps = true
}
fun loadAssets() fun loadAssets()
{ {
assetManager.load("colin.png", Texture::class.java) assetManager.load("colin.png", Texture::class.java)
@@ -37,6 +46,10 @@ class Resources private constructor()
assetManager.loadFont("Comic Sans MS.ttf", 20) assetManager.loadFont("Comic Sans MS.ttf", 20)
assetManager.load("suzanne.g3db", Model::class.java) assetManager.load("suzanne.g3db", Model::class.java)
assetManager.load("nut.wav", Sound::class.java) assetManager.load("nut.wav", Sound::class.java)
assetManager.load("cobblestone.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("rock.g3db", Model::class.java)
} }
} }

View File

@@ -5,10 +5,13 @@ import com.badlogic.gdx.graphics.g3d.Attribute
import com.badlogic.gdx.graphics.g3d.Attributes import com.badlogic.gdx.graphics.g3d.Attributes
import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3
import ktx.math.div import ktx.math.div
import ktx.math.times import ktx.math.times
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
{ {
@@ -43,6 +46,12 @@ class Util
((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f, ((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f,
((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f, ((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f,
((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f) ((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f)
val zero get() = Vector3.Zero
val one get() = Vector3(1.0f, 1.0f, 1.0f)
val forward get() = -Vector3.Z
val right get() = Vector3.X
val up get() = Vector3.Y
} }
} }
@@ -64,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)

Binary file not shown.

BIN
src/main/resources/rock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1019 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 KiB