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()
{
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()
}

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.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
@ -58,76 +58,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(
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 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 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)
val modelTexture = { modelTextureUsage: Int, textureFilename: String -> ModelTexture().apply {
usage = modelTextureUsage
fileName = textureFilename
}}
return Model(model, TextureProvider.FileTextureProvider(
Texture.TextureFilter.Nearest,
Texture.TextureFilter.Nearest,
Texture.TextureWrap.Repeat,
Texture.TextureWrap.Repeat,
false))
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)
})
})
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()

View File

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

View File

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

Binary file not shown.