Last active
December 2, 2017 14:07
-
-
Save Dawars/e95cd6f62b7213d223523a900d4760b5 to your computer and use it in GitHub Desktop.
MediumBlob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static float[][][] fieldStrength(List blobs) { | |
float result[][][] = new float[16][16][16]; | |
for (int x = 0; x < 16; x++) { | |
for (int y = 0; y < 16; y++) { | |
for (int z = 0; z < 16; z++) { | |
for (int i = 0; i < blobs.size(); i++) { | |
float xDist = blobs.get(i).x - x; | |
float yDist = blobs.get(i).y - y; | |
float zDist = blobs.get(i).z - z; | |
float r = xDist * xDist + yDist * yDist + zDist * zDist; //distance square | |
result[x][y][z] += metaball(r); | |
} | |
} | |
} | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tessellator tess = Tessellator.getInstance(); | |
VertexBuffer buffer = tess.getBuffer(); | |
buffer.setTranslation(x, y, z); | |
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); | |
final float THRESHOLD = 1; | |
float[][][] field = Blobs.fieldStrength(te.getBlobs()); | |
for (int i = 0; i < 16; i++) | |
for (int j = 0; j < 16; j++) | |
for (int k = 0; k < 16; k++) | |
if (field[i][j][k] >= THRESHOLD) { // Cell is in the blob | |
if (j == 15 || field[i][j + 1][k] < THRESHOLD) { // neighbour is outside (or at space bound) | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
} | |
if (j == 0 || (int) field[i][j - 1][k] < THRESHOLD) { | |
buffer.pos((i) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
} | |
if (k == 15 || (int) field[i][j][k + 1] < THRESHOLD) { | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
} | |
if (k == 0 || (int) field[i][j][k - 1] < THRESHOLD) { | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
} | |
if (i == 15 || (int) field[i + 1][j][k] < THRESHOLD) { | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i + 1) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
} | |
if (i == 0 || (int) field[i - 1][j][k] < THRESHOLD) { | |
buffer.pos((i) / 16F, (j) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k + 1) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j + 1) / 16F, (k) / 16F).endVertex(); | |
buffer.pos((i) / 16F, (j) / 16F, (k) / 16F).endVertex(); | |
} | |
} | |
tess.draw(); | |
buffer.setTranslation(0, 0, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void update(float speed) { | |
if (this.x > maxX || this.x < minX) this.velX *= -1F; | |
if (this.y > maxY || this.y < minY) this.velY *= -1F; | |
if (this.z > maxZ || this.z < minZ) this.velZ *= -1F; | |
this.x += speed * this.velX; | |
this.y += speed * this.velY; | |
this.z += speed * this.velZ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment