public void setCurrentValue(final int currentValue, final UISlider slider) { if (_currentValue == currentValue) { return; } _currentValue = MathUtils.clamp(currentValue, _minValue, _maxValue); if (slider != null) { slider.fireChangeEvent(); } }
/** * Returns a random int between min and max. * * @return A random int between <tt>min</tt> (inclusive) to <tt>max</tt> (inclusive). */ public static int nextRandomInt(final int min, final int max) { return (int) (nextRandomFloat() * (max - min + 1)) + min; }
/** * * @param fovY * @param aspect * @param zNear * @param zFar * @param store */ public static void matrixPerspective(final double fovY, final double aspect, final double zNear, final double zFar, final Matrix4 store) { final double height = zNear * tan(fovY * 0.5 * MathUtils.DEG_TO_RAD); final double width = height * aspect; matrixFrustum(-width, width, -height, height, zNear, zFar, store); }
private float getWeightedHeight(final float viewX, final float viewY, final float h, final float w, final float scaledClipSideSize) { final float maxDistance = Math.max(viewX, viewY) / scaledClipSideSize; final float blend = MathUtils.clamp((maxDistance - 0.51f) * 2.2f, 0.0f, 1.0f); return MathUtils.lerp(blend, h, w); }
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] }
/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
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; }
public double distanceFromInitial() { final double dx = initialX - currX; final double dy = initialY - currY; return MathUtils.sqrt(dx * dx + dy * dy); }
public LwjglPbufferTextureRenderer(final DisplaySettings settings, final Renderer parentRenderer, final ContextCapabilities caps) { super(settings, parentRenderer, caps); int pTarget = RenderTexture.RENDER_TEXTURE_2D; if (!MathUtils.isPowerOfTwo(_width) || !MathUtils.isPowerOfTwo(_height)) { pTarget = RenderTexture.RENDER_TEXTURE_RECTANGLE; } // signature: boolean useRGB, boolean useRGBA, boolean useDepth, boolean isRectangle, int target, int mipmaps _texture = new RenderTexture(false, true, true, pTarget == RenderTexture.RENDER_TEXTURE_RECTANGLE, pTarget, 0); setMultipleTargets(false); }
@Override public void setCurrentSample(final int sampleIndex, final double progressPercent, final Object applyTo) { final double[] store = (double[]) applyTo; // set key store[0] = MathUtils.lerp(progressPercent, _values[sampleIndex], _values[sampleIndex + 1]); }
private static double createGridValue(final double baseValue, final double variationAmount) { double gridValue = baseValue; if (variationAmount > 0.0) { final double variation = (MathUtils.nextRandomDouble() * (variationAmount * 2.0)) - variationAmount; gridValue += variation; } return gridValue; } }
if (!MathUtils.isPowerOfTwo(size)) { throw new Ardor3dException("size must be power of two!"); final int mips = (int) (MathUtils.log(size, 2)) + 1;
final int section = MathUtils.nextRandomInt(0, getSectionCount() - 1); final int primitiveIndex = MathUtils.nextRandomInt(0, getPrimitiveCount(section) - 1); double b = MathUtils.nextRandomDouble(); double c = MathUtils.nextRandomDouble(); BufferUtils.populateFromBuffer(result, getVertexBuffer(), pntA); BufferUtils.populateFromBuffer(work, getVertexBuffer(), pntB); Vector3.lerp(result, work, MathUtils.nextRandomDouble(), result); Vector3.releaseTempInstance(work); break;
/** * Returns cos of a value. * * @param dValue * The value to cosine, in radians. * @return The cosine of dValue. * @see java.lang.Math#cos(double) */ public static double cos(final double dValue) { return sin(dValue + MathUtils.HALF_PI); }
@Override public ResultSample doInverseTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4d m1 = new Matrix4d(); final double near = 1.0, far = 1000.0, fovy = 90.0, aspect = 0.5; final double height = near * MathUtils.tan(fovy * 0.5 * MathUtils.DEG_TO_RAD); final double width = height * aspect; final double x = near / width; final double y = near / height; final double a = 0; final double b = 0; final double c = -(far + near) / (far - near); final double d = -(2.0 * far * near) / (far - near); m1.set(new double[] { x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, a, b, c, -1.0, 0.0, 0.0, d, 0.0 }); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.invert(); } } return populateResult(System.currentTimeMillis() - start, loopCount, toArray(m1)); }
/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
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; }