use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class TessellatorHelper method addBlockMesh.
public static void addBlockMesh(Tessellator tessellator, Vector4f color, float size, float light1, float light2, float posX, float posY, float posZ) {
Vector2f defaultSize = new Vector2f(1.0f, 1.0f);
Vector2f defaultOffset = new Vector2f(0.0f, 0.0f);
addBlockMesh(tessellator, color, defaultOffset, defaultSize, size, light1, light2, posX, posY, posZ);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayout method screenToWorld.
public Vector2f screenToWorld(Vector2i screenPos) {
Vector2f world = new Vector2f(screenPos.x / pixelSize.x, screenPos.y / pixelSize.y);
world.add(windowPosition);
return world;
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayout method zoom.
public void zoom(float zoomX, float zoomY, Vector2i mousePos) {
Vector2f mouseBefore = screenToWorld(mousePos);
windowSize.x *= zoomX;
windowSize.y *= zoomY;
calculateSizes();
Vector2f mouseAfter = screenToWorld(mousePos);
windowPosition.x -= mouseAfter.x - mouseBefore.x;
windowPosition.y -= mouseAfter.y - mouseBefore.y;
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class Voronoi method getClosestPoints.
/**
* @param at
* @param numPoints Should be ≤ 5. The number of points to return
* @return
*/
public VoronoiResult[] getClosestPoints(Vector2f at, int numPoints) {
VoronoiResult[] results = new VoronoiResult[numPoints];
for (VoronoiResult result : results) {
result.distance = Float.MAX_VALUE;
}
at.scale(DENSITY_ADJUSTMENT);
at.add(offset);
int cellX = TeraMath.floorToInt(at.x);
int cellY = TeraMath.floorToInt(at.y);
processCell(cellX, cellY, at, results);
Vector2f cellPos = new Vector2f(at);
cellPos.x -= cellX;
cellPos.y -= cellY;
Vector2f distMax = new Vector2f(standardDistanceFunction(new Vector2f(1 - cellPos.x, 0)), standardDistanceFunction(new Vector2f(0, 1 - cellPos.y)));
Vector2f distMin = new Vector2f(standardDistanceFunction(new Vector2f(cellPos.x, 0)), standardDistanceFunction(new Vector2f(0, cellPos.y)));
// Test near cells
if (distMin.x < results[results.length - 1].distance) {
processCell(cellX - 1, cellY, at, results);
}
if (distMin.y < results[results.length - 1].distance) {
processCell(cellX, cellY - 1, at, results);
}
if (distMax.x < results[results.length - 1].distance) {
processCell(cellX + 1, cellY, at, results);
}
if (distMax.y < results[results.length - 1].distance) {
processCell(cellX, cellY + 1, at, results);
}
// Test further cells
if (distMin.x + distMin.y < results[results.length - 1].distance) {
processCell(cellX - 1, cellY - 1, at, results);
}
if (distMax.x + distMax.y < results[results.length - 1].distance) {
processCell(cellX + 1, cellY + 1, at, results);
}
if (distMin.x + distMax.y < results[results.length - 1].distance) {
processCell(cellX - 1, cellY + 1, at, results);
}
if (distMax.x + distMin.y < results[results.length - 1].distance) {
processCell(cellX + 1, cellY - 1, at, results);
}
for (VoronoiResult result : results) {
result.delta.scale(INVERSE_DENSITY_ADJUSTMENT);
result.distance *= INVERSE_DENSITY_ADJUSTMENT * INVERSE_DENSITY_ADJUSTMENT;
}
return results;
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BlockMeshPart method mapTexCoords.
public BlockMeshPart mapTexCoords(Vector2f offset, float width) {
float normalisedBorder = BORDER * width;
Vector2f[] newTexCoords = new Vector2f[texCoords.length];
for (int i = 0; i < newTexCoords.length; ++i) {
newTexCoords[i] = new Vector2f(offset.x + normalisedBorder + texCoords[i].x * (width - 2 * normalisedBorder), offset.y + normalisedBorder + texCoords[i].y * (width - 2 * normalisedBorder));
}
return new BlockMeshPart(vertices, normals, newTexCoords, indices);
}
Aggregations