Skip to content

Commit 6821b70

Browse files
committed
fix CircleRenderer may shift the whole gui
1 parent 8e6991f commit 6821b70

1 file changed

Lines changed: 63 additions & 65 deletions

File tree

  • src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim

src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/CircleRenderer.java

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -93,71 +93,69 @@ private void drawCircle(PoseStack poseStack, CircleObject circle, float red, flo
9393
}
9494

9595
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());
96-
97-
return;
98-
}
99-
100-
// Pixelated lines
101-
bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
102-
103-
final float pixelSize = borderWidth; // Defines the size of each "pixel" square
104-
105-
// The thickness of the hollow line in terms of pixel units.
106-
// A value of 1.0f means the line will be roughly one pixel thick.
107-
final float lineThicknessPixels = 1f;
108-
109-
// Calculate the effective min/max coordinates in the relative space
110-
float effectiveMinX = -r - pixelSize;
111-
float effectiveMaxX = r + pixelSize;
112-
float effectiveMinY = -r - pixelSize;
113-
float effectiveMaxY = r + pixelSize;
114-
115-
// Start the loop at the first multiple of PIXEL_SIZE that is less than or equal to effectiveMinX/Y
116-
float startX = (float) Math.floor(effectiveMinX / pixelSize) * pixelSize;
117-
float startY = (float) Math.floor(effectiveMinY / pixelSize) * pixelSize;
118-
119-
120-
for (float x = startX; x <= effectiveMaxX; x += pixelSize) {
121-
for (float y = startY; y <= effectiveMaxY; y += pixelSize) {
122-
// Calculate the center of the current pixel cell.
123-
// This is where you determine if the *center* of this block should be drawn.
124-
float pixelCenterX = x + (pixelSize / 2.0F);
125-
float pixelCenterY = y + (pixelSize / 2.0F);
126-
127-
// Distance is calculated from (pixelCenterX, pixelCenterY) to (0,0)
128-
double distanceToCenter = Math.sqrt(
129-
Math.pow(pixelCenterX, 2) + Math.pow(pixelCenterY, 2)
130-
);
131-
132-
boolean shouldDrawPixel;
133-
134-
if (!isFilled) {
135-
float outerRadius = r + (lineThicknessPixels * (pixelSize / 2.0F));
136-
float innerRadius = r - (lineThicknessPixels * (pixelSize / 2.0F));
137-
138-
if (innerRadius < 0) innerRadius = 0;
139-
140-
shouldDrawPixel = (distanceToCenter <= outerRadius) && (distanceToCenter >= innerRadius);
141-
} else {
142-
shouldDrawPixel = distanceToCenter <= r + (pixelSize / 2.0F);
143-
}
144-
145-
if (shouldDrawPixel) {
146-
// Vertices for the QUAD (a PIXEL_SIZE x PIXEL_SIZE square)
147-
// These coordinates are now relative to the current origin (0,0,0)
148-
float pX1 = x;
149-
float pY1 = y;
150-
float pZ = 0f; // z-coordinate is relative to cz, so 0 in this space
151-
152-
float pX2 = x + pixelSize;
153-
float pY2 = y + pixelSize;
154-
155-
// Vertices for the QUAD
156-
// Ensure proper winding order (counter-clockwise for front face)
157-
bufferBuilder.addVertex(matrix, pX1, pY2, pZ).setColor(red, green, blue, alpha); // Bottom-left
158-
bufferBuilder.addVertex(matrix, pX2, pY2, pZ).setColor(red, green, blue, alpha); // Bottom-right
159-
bufferBuilder.addVertex(matrix, pX2, pY1, pZ).setColor(red, green, blue, alpha); // Top-right
160-
bufferBuilder.addVertex(matrix, pX1, pY1, pZ).setColor(red, green, blue, alpha); // Top-left
96+
} else {
97+
// Pixelated lines
98+
bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
99+
100+
final float pixelSize = borderWidth; // Defines the size of each "pixel" square
101+
102+
// The thickness of the hollow line in terms of pixel units.
103+
// A value of 1.0f means the line will be roughly one pixel thick.
104+
final float lineThicknessPixels = 1f;
105+
106+
// Calculate the effective min/max coordinates in the relative space
107+
float effectiveMinX = -r - pixelSize;
108+
float effectiveMaxX = r + pixelSize;
109+
float effectiveMinY = -r - pixelSize;
110+
float effectiveMaxY = r + pixelSize;
111+
112+
// Start the loop at the first multiple of PIXEL_SIZE that is less than or equal to effectiveMinX/Y
113+
float startX = (float) Math.floor(effectiveMinX / pixelSize) * pixelSize;
114+
float startY = (float) Math.floor(effectiveMinY / pixelSize) * pixelSize;
115+
116+
117+
for (float x = startX; x <= effectiveMaxX; x += pixelSize) {
118+
for (float y = startY; y <= effectiveMaxY; y += pixelSize) {
119+
// Calculate the center of the current pixel cell.
120+
// This is where you determine if the *center* of this block should be drawn.
121+
float pixelCenterX = x + (pixelSize / 2.0F);
122+
float pixelCenterY = y + (pixelSize / 2.0F);
123+
124+
// Distance is calculated from (pixelCenterX, pixelCenterY) to (0,0)
125+
double distanceToCenter = Math.sqrt(
126+
Math.pow(pixelCenterX, 2) + Math.pow(pixelCenterY, 2)
127+
);
128+
129+
boolean shouldDrawPixel;
130+
131+
if (!isFilled) {
132+
float outerRadius = r + (lineThicknessPixels * (pixelSize / 2.0F));
133+
float innerRadius = r - (lineThicknessPixels * (pixelSize / 2.0F));
134+
135+
if (innerRadius < 0) innerRadius = 0;
136+
137+
shouldDrawPixel = (distanceToCenter <= outerRadius) && (distanceToCenter >= innerRadius);
138+
} else {
139+
shouldDrawPixel = distanceToCenter <= r + (pixelSize / 2.0F);
140+
}
141+
142+
if (shouldDrawPixel) {
143+
// Vertices for the QUAD (a PIXEL_SIZE x PIXEL_SIZE square)
144+
// These coordinates are now relative to the current origin (0,0,0)
145+
float pX1 = x;
146+
float pY1 = y;
147+
float pZ = 0f; // z-coordinate is relative to cz, so 0 in this space
148+
149+
float pX2 = x + pixelSize;
150+
float pY2 = y + pixelSize;
151+
152+
// Vertices for the QUAD
153+
// Ensure proper winding order (counter-clockwise for front face)
154+
bufferBuilder.addVertex(matrix, pX1, pY2, pZ).setColor(red, green, blue, alpha); // Bottom-left
155+
bufferBuilder.addVertex(matrix, pX2, pY2, pZ).setColor(red, green, blue, alpha); // Bottom-right
156+
bufferBuilder.addVertex(matrix, pX2, pY1, pZ).setColor(red, green, blue, alpha); // Top-right
157+
bufferBuilder.addVertex(matrix, pX1, pY1, pZ).setColor(red, green, blue, alpha); // Top-left
158+
}
161159
}
162160
}
163161
}

0 commit comments

Comments
 (0)