diff --git a/modules/freeworld.client/src/main/java/freeworld/client/render/GameRenderer.java b/modules/freeworld.client/src/main/java/freeworld/client/render/GameRenderer.java index d494cf1..ad158a4 100644 --- a/modules/freeworld.client/src/main/java/freeworld/client/render/GameRenderer.java +++ b/modules/freeworld.client/src/main/java/freeworld/client/render/GameRenderer.java @@ -207,7 +207,11 @@ private void renderWorldEntities(GLStateMgr gl, double partialTick) { entity.interpolatePosition(partialTick); var factory = EntityRenderers.registry().getById(Registries.ENTITY_TYPE.getId(entity.entityType())); if (factory != null) { - factory.create(client).render(gl, partialTick, Matrix4f.translation(entity.interpolatedPosition().toVector3f()), entity); + factory.create(client).render(gl, + partialTick, + Matrix4f.translation(entity.interpolatedPosition().toVector3f()) + .rotateY((float) Math.toRadians(entity.rotation().y())), + entity); } } } diff --git a/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/CubeEntityRenderer.java b/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/CubeEntityRenderer.java index b105c13..6793c42 100644 --- a/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/CubeEntityRenderer.java +++ b/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/CubeEntityRenderer.java @@ -32,13 +32,54 @@ public void render(GLStateMgr gl, double partialTick, Matrix4f positionMatrix, C RenderSystem.useProgram(client.gameRenderer().positionColorProgram()); Tessellator t = Tessellator.getInstance(); t.begin(GLDrawMode.TRIANGLES); + float x0 = -0.5f; + float y0 = 0.0f; + float z0 = -0.5f; + float x1 = 0.5f; + float y1 = 1.0f; + float z1 = 0.5f; + + // -x + t.indices(0, 1, 2, 2, 3, 0); + t.position(positionMatrix, x0, y1, z0).color(0, 255, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y0, z0).color(0, 255, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y0, z1).color(0, 255, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y1, z1).color(0, 255, 255).texCoord(0, 0).emit(); + + // +x + t.indices(0, 1, 2, 2, 3, 0); + t.position(positionMatrix, x1, y1, z1).color(255, 0, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z1).color(255, 0, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z0).color(255, 0, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y1, z0).color(255, 0, 0).texCoord(0, 0).emit(); + + // -y + t.indices(0, 1, 2, 2, 3, 0); + t.position(positionMatrix, x0, y0, z1).color(255, 0, 220).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y0, z0).color(255, 0, 220).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z0).color(255, 0, 220).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z1).color(255, 0, 220).texCoord(0, 0).emit(); + + // +y + t.indices(0, 1, 2, 2, 3, 0); + t.position(positionMatrix, x0, y1, z0).color(0, 255, 33).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y1, z1).color(0, 255, 33).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y1, z1).color(0, 255, 33).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y1, z0).color(0, 255, 33).texCoord(0, 0).emit(); + + // -z + t.indices(0, 1, 2, 2, 3, 0); + t.position(positionMatrix, x1, y1, z0).color(255, 216, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z0).color(255, 216, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y0, z0).color(255, 216, 0).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y1, z0).color(255, 216, 0).texCoord(0, 0).emit(); // +z t.indices(0, 1, 2, 2, 3, 0); - t.position(positionMatrix, 0.0f, 1.0f, 1.0f).color(0, 148, 255).texCoord(0, 0).emit(); - t.position(positionMatrix, 0.0f, 0.0f, 1.0f).color(0, 148, 255).texCoord(0, 0).emit(); - t.position(positionMatrix, 1.0f, 0.0f, 1.0f).color(0, 148, 255).texCoord(0, 0).emit(); - t.position(positionMatrix, 1.0f, 1.0f, 1.0f).color(0, 148, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y1, z1).color(0, 148, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x0, y0, z1).color(0, 148, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y0, z1).color(0, 148, 255).texCoord(0, 0).emit(); + t.position(positionMatrix, x1, y1, z1).color(0, 148, 255).texCoord(0, 0).emit(); t.end(gl); } diff --git a/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/EntityRenderers.java b/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/EntityRenderers.java index 368eb79..88f0529 100644 --- a/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/EntityRenderers.java +++ b/modules/freeworld.client/src/main/java/freeworld/client/render/world/entity/EntityRenderers.java @@ -32,6 +32,7 @@ public static void bootstrap() { register(EntityTypes.CUBE, CubeEntityRenderer::new); } + @SuppressWarnings("unchecked") public static void register(EntityType entityType, EntityRenderer.Factory renderer) { Registry.register(REGISTRY, Registries.ENTITY_TYPE.getId(entityType), (EntityRenderer.Factory) renderer); } diff --git a/modules/freeworld.core/src/main/java/freeworld/world/World.java b/modules/freeworld.core/src/main/java/freeworld/world/World.java index 59b5fa9..8b52938 100644 --- a/modules/freeworld.core/src/main/java/freeworld/world/World.java +++ b/modules/freeworld.core/src/main/java/freeworld/world/World.java @@ -10,13 +10,16 @@ package freeworld.world; +import freeworld.math.Vector2d; import freeworld.math.Vector3d; import freeworld.math.Vector3i; import freeworld.util.Int3Consumer; import freeworld.util.math.ChunkPos; +import freeworld.util.math.MathUtil; import freeworld.world.block.BlockType; import freeworld.world.block.BlockTypes; import freeworld.world.chunk.Chunk; +import freeworld.world.entity.CubeEntity; import freeworld.world.entity.Entity; import freeworld.world.entity.EntityType; import freeworld.world.entity.PlayerEntity; @@ -69,6 +72,17 @@ public void addListener(WorldListener listener) { public void tick() { motionSystem.process(this, players); motionSystem.process(this, entities); + // TODO: test + for (Entity entity : entities) { + if (entity instanceof CubeEntity cubeEntity) { + cubeEntity.rotation = new Vector2d(0.0, cubeEntity.rotation().y() + Math.random() * 2 - 1); + cubeEntity.acceleration = MathUtil.moveRelative( + 0.0, cubeEntity.onGround() && Math.random() > 0.5 ? 0.5 : 0.0, 1.0, + cubeEntity.rotation().y(), + cubeEntity.onGround() ? 0.1 : 0.02 + ); + } + } } public T createEntity(EntityType type, Vector3d position) { diff --git a/modules/freeworld.math/src/main/java/freeworld/math/Matrix4f.java b/modules/freeworld.math/src/main/java/freeworld/math/Matrix4f.java index bbb9cce..abb388a 100644 --- a/modules/freeworld.math/src/main/java/freeworld/math/Matrix4f.java +++ b/modules/freeworld.math/src/main/java/freeworld/math/Matrix4f.java @@ -285,6 +285,10 @@ public Matrix4f translate(float x, float y, float z) { return translateGeneric(x, y, z); } + public Matrix4f translate(Vector3f v) { + return translate(v.x(), v.y(), v.z()); + } + private Matrix4f translateGeneric(float x, float y, float z) { return new Matrix4f( properties & ~(PROPERTY_PERSPECTIVE | PROPERTY_IDENTITY),