Skip to content

Commit

Permalink
feat(cloth capes): progress on rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperLola committed May 22, 2023
1 parent 1a21a39 commit 829215e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void renderSmoothCape(AbstractClientPlayer player, float delta, float[] a
RenderUtil.bindCapeTexture(player, playerRenderer);

GlStateManager.pushMatrix();
GlStateManager.translate(0.0F, 0.0F, 0.125F);
// GlStateManager.translate(0.0F, 0.0F, 0.125F);
// double lvt_9_1_ = player.prevChasingPosX + (player.chasingPosX - player.prevChasingPosX) * (double) delta - (player.prevPosX + (player.posX - player.prevPosX) * (double) delta);
// double lvt_11_1_ = player.prevChasingPosY + (player.chasingPosY - player.prevChasingPosY) * (double) delta - (player.prevPosY + (player.posY - player.prevPosY) * (double) delta);
// double lvt_13_1_ = player.prevChasingPosZ + (player.chasingPosZ - player.prevChasingPosZ) * (double) delta - (player.prevPosZ + (player.posZ - player.prevPosZ) * (double) delta);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void renderSmoothCape(AbstractClientPlayer player, float delta, float[] a

for (int i = 0; i < simulation.getPoints().size(); i++) {
VerletSimulation.Point point = simulation.getPoints().get(i);
System.out.println("POINT " + i + " - Z: " + point.position.x + " | Y: " + point.position.y);
// System.out.println("POINT " + i + " - Z: " + point.position.x + " | Y: " + point.position.y);
}

final int HEIGHT_SEGMENTS = 16;
Expand All @@ -135,22 +135,20 @@ public void renderSmoothCape(AbstractClientPlayer player, float delta, float[] a

float y = simulation.getPoints().get(0).getLerpY(delta) - i - simulation.getPoints().get(i).getLerpY(delta);

System.out.println("Z: " + z + " | Y: " + y);

PositionTextureVertex backTopLeft = new PositionTextureVertex(-5, y, -1 - z, 0.0F, 0.0F);
PositionTextureVertex frontTopLeft = new PositionTextureVertex(-5, y, 0 - z, 8.0F, 0.0F);
PositionTextureVertex backTopLeft = new PositionTextureVertex(-5, -y, -1 + z, 0.0F, 0.0F);
PositionTextureVertex frontTopLeft = new PositionTextureVertex(-5, -y, 0 + z, 8.0F, 0.0F);
// TODO y for next 2 shouldn't be y, should be angled
PositionTextureVertex frontBottomLeft = new PositionTextureVertex(-5, y, 0 - z, 8.0F, 8.0F);
PositionTextureVertex backBottomLeft = new PositionTextureVertex(-5, y, -1 - z, 0.0F, 8.0F);
PositionTextureVertex frontBottomLeft = new PositionTextureVertex(-5, -y - SEGMENT_HEIGHT, 0 + z, 8.0F, 8.0F);
PositionTextureVertex backBottomLeft = new PositionTextureVertex(-5, -y - SEGMENT_HEIGHT, -1 + z, 0.0F, 8.0F);

quadList.add(
new TexturedQuad(new PositionTextureVertex[]{backTopLeft, frontTopLeft, frontBottomLeft, backBottomLeft}, 0, 1, 1, 1 + height, textureWidth, textureHeight)
);

PositionTextureVertex frontTopRight = new PositionTextureVertex(5, y, 0 - z, 0.0F, 0.0F);
PositionTextureVertex backTopRight = new PositionTextureVertex(5, y, -1 - z, 8.0F, 0.0F);
PositionTextureVertex backBottomRight = new PositionTextureVertex(5, y, -1 - z, 8.0F, 8.0F);
PositionTextureVertex frontBottomRight = new PositionTextureVertex(5, y, 0 - z, 0.0F, 8.0F);
PositionTextureVertex frontTopRight = new PositionTextureVertex(5, -y, 0 + z, 0.0F, 0.0F);
PositionTextureVertex backTopRight = new PositionTextureVertex(5, -y, -1 + z, 8.0F, 0.0F);
PositionTextureVertex backBottomRight = new PositionTextureVertex(5, -y - SEGMENT_HEIGHT, -1 + z, 8.0F, 8.0F);
PositionTextureVertex frontBottomRight = new PositionTextureVertex(5, -y - SEGMENT_HEIGHT, 0 + z, 0.0F, 8.0F);

quadList.add(
new TexturedQuad(new PositionTextureVertex[]{frontTopRight, backTopRight, backBottomRight, frontBottomRight}, 1 + width, 1, 1 + width + 1, 1 + height, textureWidth, textureHeight)
Expand All @@ -165,10 +163,10 @@ public void renderSmoothCape(AbstractClientPlayer player, float delta, float[] a

float y = simulation.getPoints().get(0).getLerpY(delta) - i - simulation.getPoints().get(i).getLerpY(delta);

PositionTextureVertex topLeft = new PositionTextureVertex(-5, y, side - z, 0.0F, 0.0F);
PositionTextureVertex topRight = new PositionTextureVertex(5, y, side - z, 8.0F, 0.0F);
PositionTextureVertex bottomLeft = new PositionTextureVertex(-5, y, side - z, 0.0F, 8.0F);
PositionTextureVertex bottomRight = new PositionTextureVertex(5, y, side - z, 8.0F, 8.0F);
PositionTextureVertex topLeft = new PositionTextureVertex(-5, -y, side - z, 0.0F, 0.0F);
PositionTextureVertex topRight = new PositionTextureVertex(5, -y, side - z, 8.0F, 0.0F);
PositionTextureVertex bottomLeft = new PositionTextureVertex(-5, -y - SEGMENT_HEIGHT, side - z, 0.0F, 8.0F);
PositionTextureVertex bottomRight = new PositionTextureVertex(5, -y - SEGMENT_HEIGHT, side - z, 8.0F, 8.0F);
quadList.add(
new TexturedQuad(new PositionTextureVertex[]{topLeft, topRight, bottomRight, bottomLeft}, 1 + leftOffset, 1 + i * SEGMENT_HEIGHT, 1 + width + leftOffset, 1 + (i + 1) * SEGMENT_HEIGHT, textureWidth, textureHeight)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.palight.playerinfo.rendering.cosmetics;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;

public interface CapeHolder {
public VerletSimulation getSimulation();
Expand All @@ -18,16 +19,20 @@ public default void simulate(EntityPlayer player) {
VerletSimulation simulation = getSimulation();
if (simulation.getPoints().isEmpty()) return;

simulation.getPoints().get(0).prevPosition.copy(simulation.getPoints().get(0).position);
double d = player.chasingPosX - player.posX;
double m = player.chasingPosZ - player.posZ;
double n = player.renderYawOffset;

double o = Math.sin(n * 0.017453292F);
double p = -Math.cos(n * 0.017453292F);

simulation.getPoints().get(0).position.x += (d * o + m * p);
simulation.getPoints().get(0).position.y = (float) (player.posY + (player.isSneaking() ? -4 : 0));
final int heightMul = 6;
simulation.getPoints().get(0).prevPosition.copy(simulation.getPoints().get(0).position);
simulation.getPoints().get(0).position.x += (d * o + m * p) + MathHelper.clamp_double((simulation.getPoints().get(0).position.y - (player.posY * heightMul)), 0d, 1d);
simulation.getPoints().get(0).position.y = (float) (player.posY * heightMul + (player.isSneaking() ? -4 : 0));
int numPoints = simulation.getPoints().size();
System.out.println("X1: " + simulation.getPoints().get(0).position.x + " | Y1: " + simulation.getPoints().get(0).position.y + " | Z1: " + simulation.getPoints().get(0).position.z);
System.out.println("X2: " + simulation.getPoints().get(numPoints - 1).position.x + " | Y2: " + simulation.getPoints().get(numPoints - 1).position.y + " | Z2: " + simulation.getPoints().get(numPoints - 1).position.z);
simulation.simulate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public boolean init(int partCount) {
for (int i = 0; i < partCount; i++) {
Point point = new Point();
point.position.y = -i;
point.position.x = -i;
point.locked = i == 0;
points.add(point);
if (i > 0) {
Expand All @@ -44,16 +43,27 @@ public void simulate() {
}

for (int i = 0; i < numIterations; i++) {
for (Stick stick : sticks) {
for (int j = sticks.size() - 1; j >= 0; j--) {
Stick stick = sticks.get(j);
Vector3d stickCenter = (stick.pointA.position.add(stick.pointB.position)).div(2);
Vector3d stickDir = (stick.pointA.position.sub(stick.pointB.position)).normalized();

// System.out.println("POINT LOCKED: " + stick.pointA.locked + " | X: " + stick.pointA.position.x + " | Y: " + stick.pointA.position.y + " | Z: " + stick.pointA.position.z);

if (!stick.pointA.locked)
stick.pointA.position = stickCenter.add(stickDir.mul(stick.length / 2));
if (!stick.pointB.locked)
stick.pointB.position = stickCenter.sub(stickDir.mul(stick.length / 2));
}
}

for (int i = 0; i < sticks.size(); i++) {
Stick stick = sticks.get(i);
Vector3d stickDir = stick.pointA.position.sub(stick.pointB.position).normalized();

if (!stick.pointB.locked)
stick.pointB.position = stick.pointA.position.sub(stickDir.mul(stick.length));
}
}

public List<Point> getPoints() {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/palight/playerinfo/util/math/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public Vector3d div(double scalar) {
}

public Vector3d normalized() {
double norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
this.x *= norm;
this.y *= norm;
this.z *= norm;
return this;
double l = Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
if (l < 1.0E-4D) {
return new Vector3d(0, 0, 0);
} else {
return new Vector3d(this.x / l, this.y / l, this.z / l);
}
}

public void copy(Vector3d other) {
Expand Down

0 comments on commit 829215e

Please sign in to comment.