Skip to content

Commit 7ac2a12

Browse files
committed
2 parents 4b488c8 + 1d0c65e commit 7ac2a12

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/main/java/mesh/creator/assets/ArchCreator.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,47 @@ public ArchCreator() {
3737
@Override
3838
public Mesh3D create() {
3939
initializeMesh();
40-
createLeftVertices();
41-
createRightVertices();
42-
createLeftFace();
43-
createRightFace();
40+
createVertices();
41+
createFaces();
4442
createArc();
4543
solidify();
4644
snapToGround();
4745
return mesh;
4846
}
4947

48+
private void createVertices() {
49+
createLeftVertices();
50+
createRightVertices();
51+
}
52+
53+
private void createFaces() {
54+
createLeftFace();
55+
createRightFace();
56+
}
57+
5058
private void createArc() {
5159
float extendStep = calculateWidth() / segments;
5260
float offsetLeft = -radius - extendLeft;
53-
float angle = Mathf.PI;
54-
float angleStep = Mathf.PI / segments;
5561

5662
for (int i = 0; i <= segments; i++) {
5763
float x = offsetLeft + (i * extendStep);
58-
float y = -radius - extendTop;
59-
Vector3f v1 = new Vector3f(x, y, 0);
60-
Vector3f v0 = pointOnCircle(angle);
64+
Vector3f v1 = new Vector3f(x, -radius - extendTop, 0);
65+
Vector3f v0 = createPointOnCircleAt(i);
66+
6167
if (i > 0 && i < segments)
6268
v1.setX(v0.getX());
6369

64-
if (i < segments)
65-
addFaceAt(i);
66-
70+
addFaceAt(i);
6771
mesh.add(v0);
6872
mesh.add(v1);
69-
angle += angleStep;
7073
}
7174
}
7275

76+
private Vector3f createPointOnCircleAt(int i) {
77+
float angle = Mathf.PI + (i * (Mathf.PI / segments));
78+
return pointOnCircle(angle);
79+
}
80+
7381
private Vector3f pointOnCircle(float angrad) {
7482
float x = radius * Mathf.cos(angrad);
7583
float y = radius * Mathf.sin(angrad);
@@ -98,21 +106,27 @@ private void createLeftFace() {
98106
}
99107

100108
private void createRightFace() {
101-
int a = 2 * ((segments + 1)) + 4;
102-
mesh.addFace(3, 2, a - 2, a - 1);
109+
int a = 2 * (segments + 1) + 4;
110+
addFace(3, 2, a - 2, a - 1);
111+
}
112+
113+
private void addFace(int... indices) {
114+
mesh.addFace(indices);
103115
}
104116

105117
private void createLeftVertices() {
106-
mesh.addVertex(-radius, extendBottom, 0);
107-
mesh.addVertex(-radius - extendLeft, extendBottom, 0);
118+
addVertex(-radius, extendBottom, 0);
119+
addVertex(-radius - extendLeft, extendBottom, 0);
108120
}
109121

110122
private void createRightVertices() {
111-
mesh.addVertex(radius, extendBottom, 0);
112-
mesh.addVertex(radius + extendRight, extendBottom, 0);
123+
addVertex(radius, extendBottom, 0);
124+
addVertex(radius + extendRight, extendBottom, 0);
113125
}
114126

115127
private void addFaceAt(int i) {
128+
if (i >= segments)
129+
return;
116130
int index = (i * 2) + 4;
117131
int index0 = index;
118132
int index1 = index + 1;
@@ -121,6 +135,10 @@ private void addFaceAt(int i) {
121135
mesh.addFace(index0, index1, index2, index3);
122136
}
123137

138+
private void addVertex(float x, float y, float z) {
139+
mesh.addVertex(x, y, z);
140+
}
141+
124142
public int getSegments() {
125143
return segments;
126144
}

0 commit comments

Comments
 (0)