diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/EntityRenderer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/EntityRenderer.kt similarity index 56% rename from src/main/kotlin/ru/dbotthepony/kstarbound/client/render/EntityRenderer.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/EntityRenderer.kt index eb751da1..29dd7156 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/EntityRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/EntityRenderer.kt @@ -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.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.ProjectileRenderer import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kstarbound.world.entities.ItemEntity 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() - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/ProjectileRenderer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/ProjectileRenderer.kt new file mode 100644 index 00000000..cad3ac06 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/entity/ProjectileRenderer.kt @@ -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() + } +} \ No newline at end of file