private boolean fill (int bufferID) { tempBuffer.clear(); int length = read(tempBytes); if (length <= 0) { if (isLooping) { loop(); length = read(tempBytes); if (length <= 0) return false; if (renderedSecondsQueue.size > 0) { renderedSecondsQueue.set(0, 0); } } else return false; } float previousLoadedSeconds = renderedSecondsQueue.size > 0 ? renderedSecondsQueue.first() : 0; float currentBufferSeconds = maxSecondsPerBuffer * (float)length / (float)bufferSize; renderedSecondsQueue.insert(0, previousLoadedSeconds + currentBufferSeconds); tempBuffer.put(tempBytes, 0, length).flip(); alBufferData(bufferID, format, tempBuffer, sampleRate); return true; }
/** Returns a new array containing the remaining values. */ public FloatArray toArray () { FloatArray array = new FloatArray(true, map.size); while (hasNext) array.add(next()); return array; } }
/** Returns > 0 if the points are a counterclockwise turn, < 0 if clockwise, and 0 if colinear. */ private float ccw (float p3x, float p3y) { FloatArray hull = this.hull; int size = hull.size; float p1x = hull.get(size - 4); float p1y = hull.get(size - 3); float p2x = hull.get(size - 2); float p2y = hull.peek(); return (p2x - p1x) * (p3y - p1y) - (p2y - p1y) * (p3x - p1x); }
/** Removes from this array all of elements contained in the specified array. * @return true if this array was modified. */ public boolean removeAll (FloatArray array) { int size = this.size; int startSize = size; float[] items = this.items; for (int i = 0, n = array.size; i < n; i++) { float item = array.get(i); for (int ii = 0; ii < size; ii++) { if (item == items[ii]) { removeIndex(ii); size--; break; } } } return size != startSize; }
prefWidth = 0; if (rowSizes == null) rowSizes = new FloatArray(); else rowSizes.clear(); FloatArray rowSizes = this.rowSizes; float space = this.space, wrapSpace = this.wrapSpace; rowSizes.add(x); rowSizes.add(rowHeight); prefWidth = Math.max(prefWidth, x + pad); if (y > 0) y += wrapSpace; rowHeight = Math.max(rowHeight, height); rowSizes.add(x); rowSizes.add(rowHeight); prefWidth = Math.max(prefWidth, x + pad); if (y > 0) y += wrapSpace;
first.width += xAdvances2.get(widthIndex++); first.width -= xAdvances2.get(--widthIndex); xAdvances1.addAll(xAdvances2, 0, firstEnd + 1); xAdvances2.removeRange(1, secondStart); // Leave first entry to be overwritten by next line. xAdvances2.set(0, -glyphs2.first().xoffset * fontData.scaleX - fontData.padLeft); first.xAdvances = xAdvances1; second.xAdvances = xAdvances2; xAdvances2.truncate(firstEnd + 1);
alSourceUnqueueBuffers(sourceID, buffers); while (renderedSecondsQueue.size > 0) { renderedSeconds = renderedSecondsQueue.pop(); renderedSeconds += maxSecondsPerBuffer; renderedSecondsQueue.add(renderedSeconds); boolean filled = false; for (int i = 0; i < bufferCount; i++) { alSourceQueueBuffers(sourceID, bufferID); renderedSecondsQueue.pop(); if (!filled) { stop();
public static void splitPolygon(PolygonFixtureDefModel object) { object.vertices.clear(); final FloatArray vertices = new FloatArray(); for (Vector2 v : object.polygon) { vertices.add(v.x); vertices.add(v.y); } ShortArray temp = earClippingTriangulator.computeTriangles(vertices); for (int i = 0; i < temp.size; i += 3) { Vector2[] vv = new Vector2[3]; vv[0] = new Vector2(vertices.get(2 * temp.get(i)), vertices.get(2 * temp.get(i) + 1)); vv[1] = new Vector2(vertices.get(2 * temp.get(i + 1)), vertices.get(2 * temp.get(i + 1) + 1)); vv[2] = new Vector2(vertices.get(2 * temp.get(i + 2)), vertices.get(2 * temp.get(i + 2) + 1)); if (Mathutils.isClockwise(vv[0], vv[1], vv[2])) { Vector2 vt = vv[0]; vv[0] = vv[2]; vv[2] = vt; } object.vertices.add(vv); } }
public void reset () { glyphs.clear(); xAdvances.clear(); width = 0; }
void triangulate () { // seed = 4139368480425561099l; // seed = 6559652580366669361l; MathUtils.random.setSeed(seed); int pointCount = 100; points.clear(); for (int i = 0; i < pointCount; i++) { float value; do { value = MathUtils.random(10, 400); } while (points.contains(value)); points.add(value); do { value = MathUtils.random(10, 400); } while (points.contains(value)); points.add(value); } points.add(Gdx.input.getX()); points.add(Gdx.graphics.getHeight() - Gdx.input.getY()); triangles = trianglulator.computeTriangles(points, false); }
@Override public void load() { // load height data from terra file final FloatArray floatArray = new FloatArray(); DataInputStream is; try { is = new DataInputStream(file.read()); while (is.available() > 0) { floatArray.add(is.readFloat()); } is.close(); } catch (EOFException e) { // e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); return; } data = floatArray.toArray(); terrain = new Terrain(meta.getTerrain().getSize(), data); terrain.init(); terrain.update(); }
xAdvances.ensureCapacity(end - start + 1); xAdvances.add(glyph.fixedWidth ? 0 : -glyph.xoffset * scaleX - padLeft); else xAdvances.add((lastGlyph.xadvance + lastGlyph.getKerning(ch)) * scaleX); lastGlyph = glyph; float lastGlyphWidth = lastGlyph.fixedWidth ? lastGlyph.xadvance * scaleX : (lastGlyph.width + lastGlyph.xoffset) * scaleX - padRight; xAdvances.add(lastGlyphWidth);
@Override public void addMesh (Mesh mesh, int indexOffset, int numIndices) { if (!attributes.equals(mesh.getVertexAttributes())) throw new GdxRuntimeException("Vertex attributes do not match"); if (numIndices <= 0) return; // silently ignore an empty mesh part // FIXME don't triple copy, instead move the copy to jni int numFloats = mesh.getNumVertices() * stride; tmpVertices.clear(); tmpVertices.ensureCapacity(numFloats); tmpVertices.size = numFloats; mesh.getVertices(tmpVertices.items); tmpIndices.clear(); tmpIndices.ensureCapacity(numIndices); tmpIndices.size = numIndices; mesh.getIndices(indexOffset, numIndices, tmpIndices.items, 0); addMesh(tmpVertices.items, tmpIndices.items, 0, numIndices); }
/** Adjusts the xadvance of the last glyph to use its width instead of xadvance. */ private void adjustLastGlyph (BitmapFontData fontData, GlyphRun run) { Glyph last = run.glyphs.peek(); if (last.fixedWidth) return; float width = (last.width + last.xoffset) * fontData.scaleX - fontData.padRight; run.width += width - run.xAdvances.peek(); // Can cause the run width to be > targetWidth, but the problem is minimal. run.xAdvances.set(run.xAdvances.size - 1, width); }
/** * @param handleBarIndex index of handle bar starting from zero, max index is number of widgets - 1 * @param split new value of split, must be greater than 0 and lesser than 1 and must be smaller and bigger than * previous and next split value. Invalid values will be clamped to closest valid one. */ public void setSplit (int handleBarIndex, float split) { if (handleBarIndex < 0) throw new IllegalStateException("handleBarIndex can't be < 0"); if (handleBarIndex >= splits.size) throw new IllegalStateException("handleBarIndex can't be >= splits size"); float minSplit = handleBarIndex == 0 ? 0 : splits.get(handleBarIndex - 1); float maxSplit = handleBarIndex == splits.size - 1 ? 1 : splits.get(handleBarIndex + 1); split = MathUtils.clamp(split, minSplit, maxSplit); splits.set(handleBarIndex, split); }