party refactors in the house tonight

This commit is contained in:
2023-08-19 05:46:29 +10:00
parent 81064b497f
commit a6d6277070
5 changed files with 72 additions and 70 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,7 +13,7 @@ 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
@ -58,76 +58,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) + val vertex = { pos: Vector3, tex: Vector2 ->
vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs), normal, tangent, bitangent) + val normal = Util.up
vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f), normal, tangent, bitangent) + val tangent = Util.right
vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f), normal, tangent, bitangent) val bitangent = Util.forward
val part = ModelMeshPart() floatArrayOf(
part.id = "floormesh" pos.x, pos.y, pos.z,
part.primitiveType = GL20.GL_TRIANGLES normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, bitangent.x, bitangent.y, bitangent.z,
part.indices = shortArrayOf( 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, 0, 1, 2,
3, 2, 1) 3, 2, 1)
mesh.parts = arrayOf(part) })
model.addMesh(mesh) })
materials.add(ModelMaterial().apply {
val material = ModelMaterial() id = "floormat"
material.id = "floormat" diffuse = XnaColor.White
material.diffuse = XnaColor.White specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f)
material.specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f) shininess = 65.0f
material.shininess = 65.0f textures = Array()
val diffuse = ModelTexture() textures.add(
diffuse.usage = ModelTexture.USAGE_DIFFUSE modelTexture(ModelTexture.USAGE_DIFFUSE, "cobblestone.png"),
diffuse.fileName = "cobblestone.png" modelTexture(ModelTexture.USAGE_NORMAL, "cobblestone_normal.png"),
val normalMap = ModelTexture() modelTexture(ModelTexture.USAGE_SPECULAR, "cobblestone_specular.png"))
normalMap.usage = ModelTexture.USAGE_NORMAL })
normalMap.fileName = "cobblestone_normal.png" nodes.add(ModelNode().apply {
val specular = ModelTexture() id = "floornode"
specular.usage = ModelTexture.USAGE_SPECULAR scale = Util.one
specular.fileName = "cobblestone_specular.png" parts = arrayOf(ModelNodePart().apply {
material.textures = Array() meshPartId = "floormesh"
material.textures.add(diffuse, normalMap, specular) materialId = "floormat"
model.materials.add(material) })
})
val node = ModelNode() }, AssetTextureProvider(assetManager))
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))
} }
override fun create() override fun create()

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,9 @@ 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)
} }
} }

View File

@ -5,8 +5,10 @@ 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
@ -43,6 +45,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
} }
} }

Binary file not shown.