Compare commits
4 Commits
344080e14d
...
9cde1d98e2
| Author | SHA1 | Date | |
|---|---|---|---|
| 9cde1d98e2 | |||
| 745476a7a0 | |||
| a6d6277070 | |||
| 81064b497f |
@@ -40,10 +40,7 @@ class Colin
|
||||
private fun updateCamera()
|
||||
{
|
||||
cam.position.set(Vector3(pos.x, 1.0f, pos.y))
|
||||
val forward = Vector3(0.0f, 0.0f, -1.0f)
|
||||
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.direction.set(Util.forward.rotateRad(Util.right, offsAngle.y).rotateRad(Util.up, offsAngle.x + angle))
|
||||
cam.update()
|
||||
}
|
||||
|
||||
|
||||
@@ -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.utils.ModelBuilder
|
||||
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.utils.Array
|
||||
import com.badlogic.gdx.utils.ScreenUtils
|
||||
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
|
||||
import ktx.math.times
|
||||
|
||||
class Game: ApplicationAdapter()
|
||||
{
|
||||
@@ -37,6 +38,7 @@ class Game: ApplicationAdapter()
|
||||
private lateinit var cubeInstance: ModelInstance
|
||||
private lateinit var floorInstance: ModelInstance
|
||||
private lateinit var suzanneInstance: ModelInstance
|
||||
private lateinit var rockBatch: ModelCache
|
||||
|
||||
private fun makeCube(texture: Texture): Model
|
||||
{
|
||||
@@ -58,76 +60,61 @@ class Game: ApplicationAdapter()
|
||||
|
||||
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 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(
|
||||
|
||||
val vertex = { pos: Vector3, tex: Vector2 ->
|
||||
val normal = Util.up
|
||||
val tangent = Util.right
|
||||
val bitangent = Util.forward
|
||||
floatArrayOf(
|
||||
pos.x, pos.y, pos.z,
|
||||
normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, bitangent.x, bitangent.y, bitangent.z,
|
||||
tex.x, tex.y)
|
||||
}
|
||||
|
||||
val modelTexture = { modelTextureUsage: Int, textureFilename: String -> ModelTexture().apply {
|
||||
usage = modelTextureUsage
|
||||
fileName = textureFilename
|
||||
}}
|
||||
|
||||
return Model(ModelData().apply {
|
||||
addMesh(ModelMesh().apply {
|
||||
id = "floormodel"
|
||||
attributes = arrayOf(VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.Tangent(), VertexAttribute.Binormal(), VertexAttribute.TexCoords(0))
|
||||
vertices =
|
||||
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)
|
||||
mesh.parts = arrayOf(part)
|
||||
model.addMesh(mesh)
|
||||
|
||||
val material = ModelMaterial()
|
||||
material.id = "floormat"
|
||||
material.diffuse = XnaColor.White
|
||||
material.specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f)
|
||||
material.shininess = 65.0f
|
||||
val diffuse = ModelTexture()
|
||||
diffuse.usage = ModelTexture.USAGE_DIFFUSE
|
||||
diffuse.fileName = "cobblestone.png"
|
||||
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()
|
||||
node.id = "floornode"
|
||||
node.scale = Vector3(1.0f, 1.0f, 1.0f)
|
||||
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(
|
||||
Texture.TextureFilter.Nearest,
|
||||
Texture.TextureFilter.Nearest,
|
||||
Texture.TextureWrap.Repeat,
|
||||
Texture.TextureWrap.Repeat,
|
||||
false))
|
||||
})
|
||||
})
|
||||
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()
|
||||
@@ -137,11 +124,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)
|
||||
|
||||
// Override ridiculous shininess because i cbf to fix the model
|
||||
for (i in suzanne.materials)
|
||||
i.set(FloatAttribute.createShininess(30.0f))
|
||||
|
||||
cube = makeCube(texJolk)
|
||||
floor = makeFloor()
|
||||
@@ -187,7 +169,36 @@ 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -246,6 +257,7 @@ class Game: ApplicationAdapter()
|
||||
|
||||
modelBatch.begin(colin.camera)
|
||||
modelBatch.render(floorInstance, env)
|
||||
modelBatch.render(rockBatch, env)
|
||||
modelBatch.render(cubeInstance, env)
|
||||
modelBatch.render(suzanneInstance, env)
|
||||
modelBatch.end()
|
||||
@@ -261,6 +273,7 @@ class Game: ApplicationAdapter()
|
||||
|
||||
override fun dispose()
|
||||
{
|
||||
rockBatch.dispose()
|
||||
floor.dispose()
|
||||
cube.dispose()
|
||||
modelBatch.dispose()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gay.pizza.CavesOfJolk
|
||||
|
||||
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.audio.Sound
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
@@ -30,6 +31,14 @@ class Resources private constructor()
|
||||
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()
|
||||
{
|
||||
assetManager.load("colin.png", Texture::class.java)
|
||||
@@ -37,6 +46,10 @@ class Resources private constructor()
|
||||
assetManager.loadFont("Comic Sans MS.ttf", 20)
|
||||
assetManager.load("suzanne.g3db", Model::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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,13 @@ 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 ktx.math.div
|
||||
import ktx.math.times
|
||||
import ktx.math.unaryMinus
|
||||
import org.hsluv.HUSLColorConverter
|
||||
import kotlin.math.pow
|
||||
import kotlin.random.Random
|
||||
|
||||
fun Float.axisDeadzone(min: Float, max: Float): Float
|
||||
{
|
||||
@@ -43,6 +46,12 @@ class Util
|
||||
((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f,
|
||||
((abgr8888 and 0xFF0000u) shr 16).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
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "UNCHECKED_CAST")
|
||||
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 |
Binary file not shown.
BIN
src/main/resources/suzanne_diffuse.png
Normal file
BIN
src/main/resources/suzanne_diffuse.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 656 KiB |
BIN
src/main/resources/suzanne_normal.png
Normal file
BIN
src/main/resources/suzanne_normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 881 KiB |
Reference in New Issue
Block a user