public static long round(final double val) { return floor(val + 0.5d); }
public static long round(final double val) { return floor(val + 0.5d); }
public static int round(final float val) { return floor(val + 0.5f); }
public static int round(final float val) { return floor(val + 0.5f); }
public double eval(final double x, final double y, final double z) { final double dx = x * _frequency; final double dz = z * _frequency; // get the radius to our point -- see the equation of a circle double radius = MathUtils.sqrt(dx * dx + dz * dz); // get fractional part radius = radius - MathUtils.floor(radius); // now get the distance to the closest integer, radius is now [0, .5] radius = Math.min(radius, 1 - radius); // return a value between -1 and 1, where 1 means the radius length was on an integer value and -1 means it was // halfway between two integers. return 1.0 - radius * 4; // [-1, 1] }
public double eval(final double x, final double y, final double z) { final double dx = x * _frequency; final double dz = z * _frequency; // get the radius to our point -- see the equation of a circle double radius = MathUtils.sqrt(dx * dx + dz * dz); // get fractional part radius = radius - MathUtils.floor(radius); // now get the distance to the closest integer, radius is now [0, .5] radius = Math.min(radius, 1 - radius); // return a value between -1 and 1, where 1 means the radius length was on an integer value and -1 means it was // halfway between two integers. return 1.0 - radius * 4; // [-1, 1] }
public void regenerate(final Renderer renderer) { for (int unit = validLevels - 1; unit >= 0; unit--) { float x = eyePosition.getXf(); float y = eyePosition.getZf(); final int exp2 = (int) Math.pow(2, unit); x /= exp2; y /= exp2; final int offX = MathUtils.floor(x); final int offY = MathUtils.floor(y); final LevelData levelData = levelDataList.get(unit); final int sX = offX - textureSize / 2; final int sY = offY - textureSize / 2; updateQuick(renderer, levelData, textureSize + 1, textureSize + 1, sX, sY, levelData.offsetX, levelData.offsetY, textureSize, textureSize); } }
public void regenerate(final Renderer renderer) { for (int unit = validLevels - 1; unit >= 0; unit--) { float x = eyePosition.getXf(); float y = eyePosition.getZf(); final int exp2 = (int) Math.pow(2, unit); x /= exp2; y /= exp2; final int offX = MathUtils.floor(x); final int offY = MathUtils.floor(y); final LevelData levelData = levelDataList.get(unit); final int sX = offX - textureSize / 2; final int sY = offY - textureSize / 2; updateQuick(renderer, levelData, textureSize + 1, textureSize + 1, sX, sY, levelData.offsetX, levelData.offsetY, textureSize, textureSize); } }
private int findClipIndex(final ReadOnlyVector3 pointInEyeSpace) { final Vector2 gridPoint = _tracers.get(_minLevel).get2DPoint(pointInEyeSpace, null); final int maxDist = Math.max(Math.abs((int) gridPoint.getX()), Math.abs((int) gridPoint.getY())) / (_clipmapLevels.get(_minLevel).getClipSideSize() + 1 >> 1); int index = (int) MathUtils.floor(Math.log(maxDist) / Math.log(2)) + 1; index = MathUtils.clamp(index, _minLevel, _maxLevel); return index; }
private int findClipIndex(final ReadOnlyVector3 pointInEyeSpace) { final Vector2 gridPoint = _tracers.get(_minLevel).get2DPoint(pointInEyeSpace, null); final int maxDist = Math.max(Math.abs((int) gridPoint.getX()), Math.abs((int) gridPoint.getY())) / (_clipmapLevels.get(_minLevel).getClipSideSize() + 1 >> 1); int index = (int) MathUtils.floor(Math.log(maxDist) / Math.log(2)) + 1; index = MathUtils.clamp(index, _minLevel, _maxLevel); return index; }
protected void addTiles(final ReadOnlyVector4 bounds) { for (int i = 0; i < availableClipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getZ() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getW() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); _updatedTiles[i].add(tile); } } } } }
protected void addTiles(final ReadOnlyVector4 bounds) { for (int i = 0; i < availableClipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getZ() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getW() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); _updatedTiles[i].add(tile); } } } } }
protected void addTiles(final Rectangle2 bounds, final Set<Tile> store) { for (int i = 0; i <= clipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getWidth() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getHeight() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); synchronized (store) { store.add(tile); } } } } }
protected void addTiles(final Rectangle2 bounds, final Set<Tile> store) { for (int i = 0; i <= clipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getWidth() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getHeight() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); synchronized (store) { store.add(tile); } } } } }
@Override public int getSubColor(final float x, final float z) { int tileX = MathUtils.floor(x / tileSize); int tileY = MathUtils.floor(z / tileSize); tileX = MathUtils.moduloPositive(tileX, cacheSize); tileY = MathUtils.moduloPositive(tileY, cacheSize); final CacheData tileData = cache[tileX][tileY]; if (!tileData.isValid) { if (parentCache != null) { return parentCache.getSubColor(x / 2f, z / 2f); } else { return 0; } } else { final int col = MathUtils.floor(x); final int row = MathUtils.floor(z); final double intOnX = x - col; final double intOnZ = z - row; final int topLeft = getColor(col, row); final int topRight = getColor(col + 1, row); final int top = IntColorUtils.lerp(intOnX, topLeft, topRight); final int bottomLeft = getColor(col, row + 1); final int bottomRight = getColor(col + 1, row + 1); final int bottom = IntColorUtils.lerp(intOnX, bottomLeft, bottomRight); return IntColorUtils.lerp(intOnZ, top, bottom); } }
public static double noise(double x, double y, double z) { final int X = (int) MathUtils.floor(x) & 255, // FIND UNIT CUBE THAT Y = (int) MathUtils.floor(y) & 255, // CONTAINS POINT. Z = (int) MathUtils.floor(z) & 255; x -= MathUtils.floor(x); // FIND RELATIVE X,Y,Z y -= MathUtils.floor(y); // OF POINT IN CUBE. z -= MathUtils.floor(z); final double u = fade(x), // COMPUTE FADE CURVES v = fade(y), // FOR EACH OF X,Y,Z. w = fade(z); final int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z, // HASH COORDINATES OF B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z; // THE 8 CUBE CORNERS, return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), // AND ADD grad(p[BA], x - 1, y, z)), // BLENDED lerp(u, grad(p[AB], x, y - 1, z), // RESULTS grad(p[BB], x - 1, y - 1, z))),// FROM 8 lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), // CORNERS grad(p[BA + 1], x - 1, y, z - 1)), // OF CUBE lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)))); }
public static double noise(double x, double y, double z) { final int X = (int) MathUtils.floor(x) & 255, // FIND UNIT CUBE THAT Y = (int) MathUtils.floor(y) & 255, // CONTAINS POINT. Z = (int) MathUtils.floor(z) & 255; x -= MathUtils.floor(x); // FIND RELATIVE X,Y,Z y -= MathUtils.floor(y); // OF POINT IN CUBE. z -= MathUtils.floor(z); final double u = fade(x), // COMPUTE FADE CURVES v = fade(y), // FOR EACH OF X,Y,Z. w = fade(z); final int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z, // HASH COORDINATES OF B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z; // THE 8 CUBE CORNERS, return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), // AND ADD grad(p[BA], x - 1, y, z)), // BLENDED lerp(u, grad(p[AB], x, y - 1, z), // RESULTS grad(p[BB], x - 1, y - 1, z))),// FROM 8 lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), // CORNERS grad(p[BA + 1], x - 1, y, z - 1)), // OF CUBE lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)))); }
@Override public void invoke(final long window, final double xoffset, final double yoffset) { wheelAccum += yoffset; final int dw = (int) MathUtils.floor(wheelAccum); if (dw == 0) { return; } wheelAccum -= dw; // Add our new state final int x = _lastState != null ? _lastState.getX() : 0; final int y = _lastState != null ? _lastState.getY() : 0; final MouseState event = new MouseState(x, y, 0, 0, dw, Maps.newEnumMap(_lastButtonState), null); addNextState(event); } });