private void updateLod() { reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f); makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1); } }, "plus", "minus", "wireFrame");
protected byte[] generateTag() { int width = ((int) FastMath.log(aliasCount, 256) + 1); int count = aliasCount; aliasCount++; byte[] bytes = new byte[width]; for (int x = width - 1; x >= 0; x--) { int pow = (int) FastMath.pow(256, x); int factor = count / pow; bytes[width - x - 1] = (byte) factor; count %= pow; } return bytes; }
public RawHeightMap(float heightData[]) { this.heightData = heightData; this.size = (int) FastMath.sqrt(heightData.length); this.format = FORMAT_8BIT; }
@Override protected void postQueue(RenderQueue queue) { getClipCoordinates(lightPosition, screenLightPos, viewPort.getCamera()); viewPort.getCamera().getViewMatrix().mult(lightPosition, viewLightPos); if (adaptative) { float densityX = 1f - FastMath.clamp(FastMath.abs(screenLightPos.x - 0.5f), 0, 1); float densityY = 1f - FastMath.clamp(FastMath.abs(screenLightPos.y - 0.5f), 0, 1); innerLightDensity = lightDensity * densityX * densityY; } else { innerLightDensity = lightDensity; } display = innerLightDensity != 0.0 && viewLightPos.z < 0; }
targetRotation = FastMath.TWO_PI - FastMath.acos(a.dot(b)); } else { targetRotation = FastMath.acos(a.dot(b)); if (targetRotation != previousTargetRotation && FastMath.abs(targetRotation - previousTargetRotation) > FastMath.PI / 8) { trailingLerpFactor = 0; rotation = FastMath.interpolateLinear(trailingLerpFactor, rotation, targetRotation); distance = temp.set(targetLocation).subtractLocal(cam.getLocation()).length(); distanceLerpFactor = Math.min(distanceLerpFactor + (tpf * tpf * chasingSensitivity * 0.05f), 1); distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance); if (targetDistance + 0.01f >= distance && targetDistance - 0.01f <= distance) { distanceLerpFactor = 0; distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance); if (targetDistance + 0.1f >= distance && targetDistance - 0.1f <= distance) { zooming = false; rotation = FastMath.interpolateLinear(rotationLerpFactor, rotation, targetRotation); if (targetRotation + 0.01f >= rotation && targetRotation - 0.01f <= rotation) { rotating = false; vRotation = FastMath.interpolateLinear(vRotationLerpFactor, vRotation, targetVRotation); if (targetVRotation + 0.01f >= vRotation && targetVRotation - 0.01f <= vRotation) { vRotating = false;
public void interpolateWeights(float t, int currentIndex, float[] weights, int nbMorphTargets, float[] store) { int start = currentIndex * nbMorphTargets; for (int i = 0; i < nbMorphTargets; i++) { int current = start + i; int next = current + nbMorphTargets; if (next >= weights.length) { next = current; } float val = FastMath.interpolateLinear(t, weights[current], weights[next]); store[i] = val; } }
/** * The method computes the value of a point at the certain relational distance from its beginning. * @param alongRatio * the relative distance along the curve; should be a value between 0 and 1 inclusive; * if the value exceeds the boundaries it is truncated to them * @return computed value along the curve */ public Vector3f getValueAlongCurve(float alongRatio) { alongRatio = FastMath.clamp(alongRatio, 0, 1); Vector3f result = new Vector3f(); float probeLength = this.getLength() * alongRatio; float length = 0; for (int i = 1; i < vertices.length; ++i) { float edgeLength = vertices[i].distance(vertices[i - 1]); if (length + edgeLength > probeLength) { float ratioAlongEdge = (probeLength - length) / edgeLength; return FastMath.interpolateLinear(ratioAlongEdge, vertices[i - 1], vertices[i]); } else if (length + edgeLength == probeLength) { return vertices[i]; } length += edgeLength; } return result; }
protected void addLineFault(float[][] tempBuffer, Random random, float faultHeight, float range) { int x1 = random.nextInt(size); int x2 = random.nextInt(size); int y1 = random.nextInt(size); int y2 = random.nextInt(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist = ((x2 - x1) * (j - y1) - (y2 - y1) * (i - x1)) / (FastMath.sqrt(FastMath.sqr(x2 - x1) + FastMath.sqr(y2 - y1))); tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
int higherMipLevel = (int) FastMath.ceil(mipLevel); float ratio = mipLevel - lowerMipLevel; mipMapRaster.getPixel((int) uvs.x, (int) uvs.y, tmpColor); store.r = FastMath.interpolateLinear(ratio, store.r, tmpColor.r); store.g = FastMath.interpolateLinear(ratio, store.g, tmpColor.g); store.b = FastMath.interpolateLinear(ratio, store.b, tmpColor.b); store.a = FastMath.interpolateLinear(ratio, store.a, tmpColor.a);
/** * Zoom the camera by the specified amount. * * @param value zoom amount */ protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); float newFovY = fovY + value * 0.1f * zoomSpeed; if (newFovY > 0f) { // Don't let the FOV go zero or negative. fovY = newFovY; } h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
/** * Interpolate a position on the spline * @param value a value from 0 to 1 that represent the position between the current control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
/** * <code>setFrustumPerspective</code> defines the frustum for the camera. This * frustum is defined by a viewing angle, aspect ratio, and near/far planes * * @param fovY Frame of view angle along the Y in degrees. * @param aspect Width:Height ratio * @param near Near view plane distance * @param far Far view plane distance */ public void setFrustumPerspective(float fovY, float aspect, float near, float far) { if (Float.isNaN(aspect) || Float.isInfinite(aspect)) { // ignore. logger.log(Level.WARNING, "Invalid aspect given to setFrustumPerspective: {0}", aspect); return; } float h = FastMath.tan(fovY * FastMath.DEG_TO_RAD * .5f) * near; float w = h * aspect; frustumLeft = -w; frustumRight = w; frustumBottom = -h; frustumTop = h; frustumNear = near; frustumFar = far; // Camera is no longer parallel projection even if it was before parallelProjection = false; onFrustumChange(); }
private BufferedImage getFontImage(Bf4File fontFile) { // Try to create a nice square (power of two is really waste of space...) int area = fontFile.getMaxHeight() * fontFile.getAvgWidth() * fontFile.getGlyphCount(); // This is how many square pixels we need, approximate int side = (int) FastMath.ceil(FastMath.sqrt(area)) + 10; // The plus is just a bit padding to make sure everything fits // Divisible by two if (side % 2 != 0) { side++; } // Create the image return new BufferedImage(side, side, BufferedImage.TYPE_BYTE_BINARY, Bf4File.getCm()); }
/** * The maximum lod supported by this terrain patch. * If the patch size is 32 then the returned value would be log2(32)-2 = 3 * You can then use that value, 3, to see how many times you can divide 32 by 2 * before the terrain gets too un-detailed (can't stitch it any further). * @return the maximum LOD */ public int getMaxLod() { if (maxLod < 0) maxLod = Math.max(1, (int) (FastMath.log(size-1)/FastMath.log(2)) -1); // -1 forces our minimum of 4 triangles wide return maxLod; }
public static Image resizeToPowerOf2(Image original){ int potWidth = FastMath.nearestPowerOfTwo(original.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(original.getHeight()); return scaleImage(original, potWidth, potHeight); }
@Test public void testNearestPowerOfTwo() { for (int i = -100; i < 1; i++) { assert FastMath.nearestPowerOfTwo(i) == 1; } for (int i = 1; i < 10000; i++) { int nextPowerOf2 = FastMath.nearestPowerOfTwo(i); assert i <= nextPowerOf2; assert FastMath.isPowerOfTwo(nextPowerOf2); assert nextPowerOf2 == nearestPowerOfTwoSlow(i); } }