use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class Voronoi method processCell.
private void processCell(int cellX, int cellY, Vector2f at, VoronoiResult[] results) {
long seed = (702395077 * cellX + 915488749 * cellY);
// Number of features
int count = poissonCount[(int) (seed >> 24)];
seed = incrementSeed(seed);
for (int point = 0; point < count; point++) {
long id = seed;
seed = incrementSeed(seed);
float x = (seed + 0.5f) / 4294967296.0f;
seed = incrementSeed(seed);
float y = (seed + 0.5f) / 4294967296.0f;
seed = incrementSeed(seed);
Vector2f innerPos = new Vector2f(x, y);
Vector2f delta = new Vector2f(cellX + innerPos.x - at.x, cellY + innerPos.y - at.y);
float dist = standardDistanceFunction(delta);
if (dist < results[results.length - 1].distance) {
int index = results.length - 1;
while (index > 0 && dist < results[index - 1].distance) {
index--;
}
for (int i = results.length - 1; i > index; i--) {
results[i] = results[i - 1];
}
results[index].distance = dist;
results[index].delta = new Vector2f(delta);
results[index].id = (int) id;
}
}
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BlockBuilder method createAppearance.
private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
for (BlockPart part : BlockPart.values()) {
// TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient
Vector2f atlasPos;
if (tiles.get(part) == null) {
atlasPos = new Vector2f();
} else {
atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null);
}
BlockPart targetPart = part.rotate(rot);
textureAtlasPositions.put(targetPart, atlasPos);
if (shape.getMeshPart(part) != null) {
meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize()));
}
}
return new BlockAppearance(meshParts, textureAtlasPositions);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BlockMeshPart method appendTo.
public void appendTo(ChunkMesh chunk, int offsetX, int offsetY, int offsetZ, Vector4f colorOffset, ChunkMesh.RenderType renderType, ChunkVertexFlag flags) {
ChunkMesh.VertexElements elements = chunk.getVertexElements(renderType);
for (Vector2f texCoord : texCoords) {
elements.tex.add(texCoord.x);
elements.tex.add(texCoord.y);
}
int nextIndex = elements.vertexCount;
for (int vIdx = 0; vIdx < vertices.length; ++vIdx) {
elements.color.add(colorOffset.x);
elements.color.add(colorOffset.y);
elements.color.add(colorOffset.z);
elements.color.add(colorOffset.w);
elements.vertices.add(vertices[vIdx].x + offsetX);
elements.vertices.add(vertices[vIdx].y + offsetY);
elements.vertices.add(vertices[vIdx].z + offsetZ);
elements.normals.add(normals[vIdx].x);
elements.normals.add(normals[vIdx].y);
elements.normals.add(normals[vIdx].z);
elements.flags.add(flags.getValue());
}
elements.vertexCount += vertices.length;
for (int index : indices) {
elements.indices.add(index + nextIndex);
}
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Port from, Port to, Color color) {
Vector2f start = new Vector2f(from.node.getPosition());
start.add(from.mid());
Vector2f end = new Vector2f(to.node.getPosition());
end.add(to.mid());
drawConnection(canvas, start, end, color);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Port from, Vector2f to, Color color) {
Vector2f start = new Vector2f(from.node.getPosition());
start.add(from.mid());
drawConnection(canvas, start, to, color);
}
Aggregations