private void updateLod() { reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f); makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1); } }, "plus", "minus", "wireFrame");
/** * Clamps the given float to be between 0 and 1. * * @param input * @return input clamped between 0 and 1. */ public static float saturate(float input) { return clamp(input, 0f, 1f); }
private float computeAnalogValue(long timeDelta) { if (safeMode || frameDelta == 0) { return 1f; } else { return FastMath.clamp((float) timeDelta / (float) frameDelta, 0, 1); } }
private float smoothstep(float edge0, float edge1, float x) { // Scale, bias and saturate x to 0..1 range x = FastMath.clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); // Evaluate polynomial return x * x * (3 - 2 * x); }
/** * This method clamps the pixel values to the given borders. * * @param min * the minimum value * @param max * the maximum value */ public void clamp(float min, float max) { this.red = FastMath.clamp(this.red, min, max); this.green = FastMath.clamp(this.green, min, max); this.blue = FastMath.clamp(this.blue, min, max); this.alpha = FastMath.clamp(this.alpha, min, max); this.intensity = FastMath.clamp(this.intensity, min, max); }
/** * @param time Set the time of the currently playing animation, the time * is clamped from 0 to {@link #getAnimMaxTime()}. */ public void setTime(float time) { this.time = FastMath.clamp(time, 0, getAnimMaxTime()); }
/** * <code>angleBetween</code> returns (in radians) the angle between two vectors. * It is assumed that both this vector and the given vector are unit vectors (iow, normalized). * * @param otherVector * a unit vector to find the angle against * @return the angle in radians. */ public double angleBetween(Vector3d otherVector) { double dot = this.dot(otherVector); // the vectors are normalized, but if they are parallel then the dot product migh get a value like: 1.000000000000000002 // which is caused by floating point operations; in such case, the acos function will return NaN so we need to clamp this value dot = FastMath.clamp((float) dot, -1, 1); return Math.acos(dot); }
/** * move the camera toward or away the target */ protected void zoomCamera(float value) { distance = FastMath.clamp(distance + value, minDistance, maxDistance); camNode.setLocalTranslation(new Vector3f(0, 0, distance)); }
public T getEntryClamp(int index, T store) { index = (int) FastMath.clamp(index, 0, data.getTotalObjectSize() - 1); return data.get(index, store); }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("rup") && isPressed) { roughness = FastMath.clamp(roughness + 0.1f, 0.0f, 1.0f); m.setFloat("Roughness", roughness); } if (name.equals("rdown") && isPressed) { roughness = FastMath.clamp(roughness - 0.1f, 0.0f, 1.0f); m.setFloat("Roughness", roughness); } if (name.equals("light") && isPressed) { dl.setDirection(cam.getDirection().normalize()); } } }, "light", "rup", "rdown");
public void onMouseMotionEvent(MouseMotionEvent evt) { x += evt.getDX(); y += evt.getDY(); // Prevent mouse from leaving screen AppSettings settings = TestSoftwareMouse.this.settings; x = FastMath.clamp(x, 0, settings.getWidth()); y = FastMath.clamp(y, 0, settings.getHeight()); // adjust for hotspot cursor.setPosition(x, y - 64); } public void onMouseButtonEvent(MouseButtonEvent evt) {
@Override public void getPixel(TexturePixel pixel, float x, float y, float z) { int random = FastMath.rand.nextInt(); int val = random & 3; int loop = noisedepth; while (loop-- != 0) { random >>= 2; val *= random & 3; } pixel.intensity = FastMath.clamp(val, 0.0f, 1.0f); if (colorBand != null) { int colorbandIndex = (int) (pixel.intensity * 1000.0f); pixel.red = colorBand[colorbandIndex][0]; pixel.green = colorBand[colorbandIndex][1]; pixel.blue = colorBand[colorbandIndex][2]; this.applyBrightnessAndContrast(bacd, pixel); pixel.alpha = colorBand[colorbandIndex][3]; } else { this.applyBrightnessAndContrast(pixel, bacd.contrast, bacd.brightness); } } }
@Override public void onAnalog(String name, float value, float tpf) { if (name.equals("blendUp")) { blendValue += value; blendValue = FastMath.clamp(blendValue, 1, 4); action.getBlendSpace().setValue(blendValue); action.setSpeed(blendValue); } if (name.equals("blendDown")) { blendValue -= value; blendValue = FastMath.clamp(blendValue, 1, 4); action.getBlendSpace().setValue(blendValue); action.setSpeed(blendValue); } //System.err.println(blendValue); } }, "blendUp", "blendDown");
@Override public void getPixel(TexturePixel pixel, float x, float y, float z) { pixel.intensity = this.musgraveVariableLunacrityNoise(x * 4, y * 4, z * 4, distAmount, noisebasis, noisebasis2); pixel.intensity = FastMath.clamp(pixel.intensity, 0.0f, 1.0f); if (colorBand != null) { int colorbandIndex = (int) (pixel.intensity * 1000.0f); pixel.red = colorBand[colorbandIndex][0]; pixel.green = colorBand[colorbandIndex][1]; pixel.blue = colorBand[colorbandIndex][2]; this.applyBrightnessAndContrast(bacd, pixel); } else { this.applyBrightnessAndContrast(pixel, bacd.contrast, bacd.brightness); } }
@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; }
/** * 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 */ private Vector3f getValueAlongCurve(float alongRatio) { alongRatio = FastMath.clamp(alongRatio, 0, 1); Vector3f result = new Vector3f(); float probeLength = this.getLength() * alongRatio, length = 0; for (BezierLine bezier : beziers) { float edgeLength = bezier.getLength(); if (length + edgeLength >= probeLength) { float ratioAlongEdge = (probeLength - length) / edgeLength; return bezier.getValueAlongCurve(ratioAlongEdge); } length += edgeLength; } return result; }
/** * 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; }
/** * rotate the camera around the target */ protected void rotateCamera() { verticalRotation = FastMath.clamp(verticalRotation, minVerticalRotation, maxVerticalRotation); TempVars vars = TempVars.get(); Quaternion rot = vars.quat1; Quaternion rot2 = vars.quat2; rot.fromAngleNormalAxis(verticalRotation, leftVector); rot2.fromAngleNormalAxis(horizontalRotation, upVector); rot2.multLocal(rot); target.setLocalRotation(rot2); vars.release(); }
/** * This method converts the given point into 3D UV coordinates. * * @param boundingBox * the bounding box of the mesh * @param point * the point to be transformed * @param uvs * the result UV coordinates */ private void toTextureUV(BoundingBox boundingBox, Vector3f point, float[] uvs) { uvs[0] = (point.x - boundingBox.getCenter().x) / (boundingBox.getXExtent() == 0 ? 1 : boundingBox.getXExtent()); uvs[1] = (point.y - boundingBox.getCenter().y) / (boundingBox.getYExtent() == 0 ? 1 : boundingBox.getYExtent()); uvs[2] = (point.z - boundingBox.getCenter().z) / (boundingBox.getZExtent() == 0 ? 1 : boundingBox.getZExtent()); // UVS cannot go outside <0, 1> range, but since we are generating texture for triangle envelope it might happen that // some points of the envelope will exceet the bounding box of the mesh thus generating uvs outside the range for (int i = 0; i < 3; ++i) { uvs[i] = FastMath.clamp(uvs[i], 0, 1); } }