Немного прибираемся
This commit is contained in:
parent
a0705472f8
commit
d8c1d9dab8
@ -1,12 +1,9 @@
|
|||||||
package ru.dbotthepony.kstarbound.client.render
|
package ru.dbotthepony.kstarbound.client.render.entity
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL46.*
|
|
||||||
import ru.dbotthepony.kstarbound.PIXELS_IN_STARBOUND_UNITf
|
|
||||||
import ru.dbotthepony.kstarbound.client.ClientChunk
|
import ru.dbotthepony.kstarbound.client.ClientChunk
|
||||||
import ru.dbotthepony.kstarbound.client.gl.GLStateTracker
|
import ru.dbotthepony.kstarbound.client.gl.GLStateTracker
|
||||||
import ru.dbotthepony.kstarbound.client.gl.vertex.QuadTransformers
|
|
||||||
import ru.dbotthepony.kstarbound.client.gl.vertex.quadRotatedZ
|
|
||||||
import ru.dbotthepony.kstarbound.client.render.entity.ItemRenderer
|
import ru.dbotthepony.kstarbound.client.render.entity.ItemRenderer
|
||||||
|
import ru.dbotthepony.kstarbound.client.render.entity.ProjectileRenderer
|
||||||
import ru.dbotthepony.kstarbound.world.entities.Entity
|
import ru.dbotthepony.kstarbound.world.entities.Entity
|
||||||
import ru.dbotthepony.kstarbound.world.entities.ItemEntity
|
import ru.dbotthepony.kstarbound.world.entities.ItemEntity
|
||||||
import ru.dbotthepony.kstarbound.world.entities.projectile.Projectile
|
import ru.dbotthepony.kstarbound.world.entities.projectile.Projectile
|
||||||
@ -55,33 +52,3 @@ open class EntityRenderer(val state: GLStateTracker, val entity: Entity, open va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class ProjectileRenderer(state: GLStateTracker, entity: Projectile, chunk: ClientChunk?) : EntityRenderer(state, entity, chunk) {
|
|
||||||
private val def = entity.def
|
|
||||||
private val texture = state.loadNamedTextureSafe(def.image.texture)
|
|
||||||
private val animator = FrameSetAnimator(def.image, def.animationCycle, entity.def.animationLoops)
|
|
||||||
|
|
||||||
override fun render(stack: Matrix4fStack) {
|
|
||||||
state.shaderVertexTexture.use()
|
|
||||||
state.shaderVertexTexture.transform.set(stack.last)
|
|
||||||
state.activeTexture = 0
|
|
||||||
state.shaderVertexTexture["_texture"] = 0
|
|
||||||
texture.bind()
|
|
||||||
|
|
||||||
animator.advance()
|
|
||||||
|
|
||||||
val builder = state.flat2DTexturedQuads.small
|
|
||||||
|
|
||||||
builder.begin()
|
|
||||||
|
|
||||||
val (u0, v0) = texture.pixelToUV(animator.frameObj.texturePosition)
|
|
||||||
val (u1, v1) = texture.pixelToUV(animator.frameObj.textureEndPosition)
|
|
||||||
|
|
||||||
val width = (animator.frameObj.width / PIXELS_IN_STARBOUND_UNITf) / 2f
|
|
||||||
val height = (animator.frameObj.height / PIXELS_IN_STARBOUND_UNITf) / 2f
|
|
||||||
|
|
||||||
builder.quadRotatedZ(-width, -height, width, height, 5f, 0f, 0f, entity.movement.angle, QuadTransformers.uv(u0, v0, u1, v1))
|
|
||||||
|
|
||||||
builder.upload()
|
|
||||||
builder.draw()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,44 @@
|
|||||||
|
package ru.dbotthepony.kstarbound.client.render.entity
|
||||||
|
|
||||||
|
import ru.dbotthepony.kstarbound.PIXELS_IN_STARBOUND_UNITf
|
||||||
|
import ru.dbotthepony.kstarbound.client.ClientChunk
|
||||||
|
import ru.dbotthepony.kstarbound.client.gl.GLStateTracker
|
||||||
|
import ru.dbotthepony.kstarbound.client.gl.vertex.QuadTransformers
|
||||||
|
import ru.dbotthepony.kstarbound.client.gl.vertex.quadRotatedZ
|
||||||
|
import ru.dbotthepony.kstarbound.client.render.EntityRenderer
|
||||||
|
import ru.dbotthepony.kstarbound.client.render.FrameSetAnimator
|
||||||
|
import ru.dbotthepony.kstarbound.world.entities.projectile.Projectile
|
||||||
|
import ru.dbotthepony.kvector.matrix.Matrix4fStack
|
||||||
|
|
||||||
|
open class ProjectileRenderer(state: GLStateTracker, entity: Projectile, chunk: ClientChunk?) : EntityRenderer(state, entity, chunk) {
|
||||||
|
private val def = entity.def
|
||||||
|
private val texture = state.loadNamedTextureSafe(def.image.texture)
|
||||||
|
private val animator = FrameSetAnimator(def.image, def.animationCycle, entity.def.animationLoops)
|
||||||
|
|
||||||
|
override fun render(stack: Matrix4fStack) {
|
||||||
|
state.shaderVertexTexture.use()
|
||||||
|
state.shaderVertexTexture.transform.set(stack.last)
|
||||||
|
state.activeTexture = 0
|
||||||
|
state.shaderVertexTexture["_texture"] = 0
|
||||||
|
texture.bind()
|
||||||
|
|
||||||
|
animator.advance()
|
||||||
|
|
||||||
|
val builder = state.flat2DTexturedQuads.small
|
||||||
|
|
||||||
|
builder.begin()
|
||||||
|
|
||||||
|
val (u0, v0) = texture.pixelToUV(animator.frameObj.texturePosition)
|
||||||
|
val (u1, v1) = texture.pixelToUV(animator.frameObj.textureEndPosition)
|
||||||
|
|
||||||
|
val width = (animator.frameObj.width / PIXELS_IN_STARBOUND_UNITf) / 2f
|
||||||
|
val height = (animator.frameObj.height / PIXELS_IN_STARBOUND_UNITf) / 2f
|
||||||
|
|
||||||
|
builder.quadRotatedZ(-width, -height, width, height, 5f, 0f, 0f, entity.movement.angle,
|
||||||
|
QuadTransformers.uv(u0, v0, u1, v1)
|
||||||
|
)
|
||||||
|
|
||||||
|
builder.upload()
|
||||||
|
builder.draw()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user