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; } }
/** * Linear interpolation from startValue to endValue by the given percent. * Basically: ((1 - percent) * startValue) + (percent * endValue) * * @param scale * scale value to use. if 1, use endValue, if 0, use startValue. * @param startValue * Beginning value. 0% of f * @param endValue * ending value. 100% of f * @return The interpolated value between startValue and endValue. */ public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue) { return interpolateLinear(scale, startValue, endValue, null); }
float lerpAmount = (float)prevToCurrentDelta / prevToNextDelta; return FastMath.interpolateLinear(lerpAmount, keyValue1, keyValue2);
/** * Linear interpolation from startValue to endValue by the given percent. * Basically: ((1 - percent) * startValue) + (percent * endValue) * * @param scale * scale value to use. if 1, use endValue, if 0, use startValue. * @param startValue * Beginning value. 0% of f * @param endValue * ending value. 100% of f * @param store a vector3f to store the result * @return The interpolated value between startValue and endValue. */ public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateLinear(scale, startValue.x, endValue.x); store.y = interpolateLinear(scale, startValue.y, endValue.y); store.z = interpolateLinear(scale, startValue.z, endValue.z); return store; }
private void interpolate(Type type, float ratio, KeyFrame lastKeyFrame, KeyFrame nextKeyFrame, int currentIndex) { //TODO here we should interpolate differently according to the interpolation given in the gltf file. switch (type) { case Translation: translations[currentIndex] = FastMath.interpolateLinear(ratio, lastKeyFrame.translation, nextKeyFrame.translation); break; case Rotation: Quaternion rot = new Quaternion().set(lastKeyFrame.rotation); rot.nlerp(nextKeyFrame.rotation, ratio); rotations[currentIndex] = rot; break; case Scale: scales[currentIndex] = FastMath.interpolateLinear(ratio, lastKeyFrame.scale, nextKeyFrame.scale); break; } }
/** * 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; }
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);
/** * 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; }
translations[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]); break; case Rotation: break; case Scale: scales[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]); break;
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;
protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){ // applying gravity p.velocity.x -= gravity.x * tpf; p.velocity.y -= gravity.y * tpf; p.velocity.z -= gravity.z * tpf; temp.set(p.velocity).multLocal(tpf); p.position.addLocal(temp); // affecting color, size and angle float b = (p.startlife - p.life) / p.startlife; p.color.interpolateLocal(startColor, endColor, b); p.size = FastMath.interpolateLinear(b, startSize, endSize); p.angle += p.rotateSpeed * tpf; // Computing bounding volume temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); if (!selectRandomImage) { p.imageIndex = (int) (b * imagesX * imagesY); } }
/** * Linear interpolation from startValue to endValue by the given percent. * Basically: ((1 - percent) * startValue) + (percent * endValue) * * @param scale * scale value to use. if 1, use endValue, if 0, use startValue. * @param startValue * Beginning value. 0% of f * @param endValue * ending value. 100% of f * @return The interpolated value between startValue and endValue. */ public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue) { return interpolateLinear(scale, startValue, endValue, null); }
/** * Linear interpolation from startValue to endValue by the given percent. * Basically: ((1 - percent) * startValue) + (percent * endValue) * * @param scale * scale value to use. if 1, use endValue, if 0, use startValue. * @param startValue * Begining value. 0% of f * @param endValue * ending value. 100% of f * @return The interpolated value between startValue and endValue. */ public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue) { return interpolateLinear(scale, startValue, endValue, null); }
@Override protected void doInterpolate( double t ) { float value = FastMath.interpolateLinear((float)t, from, to); target.setAlpha(value); } }
private void interpolate(Type type, float ratio, KeyFrame lastKeyFrame, KeyFrame nextKeyFrame, int currentIndex) { //TODO here we should interpolate differently according to the interpolation given in the gltf file. switch (type) { case Translation: translations[currentIndex] = FastMath.interpolateLinear(ratio, lastKeyFrame.translation, nextKeyFrame.translation); break; case Rotation: Quaternion rot = new Quaternion().set(lastKeyFrame.rotation); rot.nlerp(nextKeyFrame.rotation, ratio); rotations[currentIndex] = rot; break; case Scale: scales[currentIndex] = FastMath.interpolateLinear(ratio, lastKeyFrame.scale, nextKeyFrame.scale); break; } }
@Override public void updateControl(float tpf) { if (parent == null || camera == null) { return; } if (tick > 1) { parent.removeControl(this); return; } Vector3f look = FastMath.interpolateLinear(tick, from, to); camera.setLookAt(look); tick += tpf * SPEED; }
private void moveCamera() { Vector3f location = FastMath.interpolateLinear(tick, pFrom, pTo); camera.setLocation(location); Quaternion rotation = new Quaternion(qFrom, qTo, tick); camera.setRotation(rotation); }
@Override public void update(float tpf) { super.update(tpf); if (getPlayState() == PlayState.Playing) { // Rotate float progress = getCurrentValue(); int startIndex = getCurrentWayPoint(); // Get the rotation at previous (or current) waypoint CameraSweepDataEntry entry = cameraSweepData.getEntries().get(startIndex); Quaternion q1 = new Quaternion(entry.getRotation()); // If we are not on the last waypoint, interpolate the rotation between waypoints CameraSweepDataEntry entryNext = cameraSweepData.getEntries().get(startIndex + 1); Quaternion q2 = entryNext.getRotation(); q1.slerp(q2, progress); // Set the rotation setRotation(q1); // Set the near & FOV //float near = FastMath.interpolateLinear(progress, entry.getNear(), entryNext.getNear()) / 4096; float fov = FastMath.interpolateLinear(progress, entry.getFov(), entryNext.getFov()); cam.setFrustumPerspective(fov, (float) cam.getWidth() / cam.getHeight(), 0.1f, 100f); } }
protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){ // applying gravity p.velocity.x -= gravity.x * tpf; p.velocity.y -= gravity.y * tpf; p.velocity.z -= gravity.z * tpf; temp.set(p.velocity).multLocal(tpf); p.position.addLocal(temp); // affecting color, size and angle float b = (p.startlife - p.life) / p.startlife; p.color.interpolateLocal(startColor, endColor, b); p.size = FastMath.interpolateLinear(b, startSize, endSize); p.angle += p.rotateSpeed * tpf; // Computing bounding volume temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); if (!selectRandomImage) { p.imageIndex = (int) (b * imagesX * imagesY); } }
private void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){ // applying gravity p.velocity.x -= gravity.x * tpf; p.velocity.y -= gravity.y * tpf; p.velocity.z -= gravity.z * tpf; temp.set(p.velocity).multLocal(tpf); p.position.addLocal(temp); // affecting color, size and angle float b = (p.startlife - p.life) / p.startlife; p.color.interpolate(startColor, endColor, b); p.size = FastMath.interpolateLinear(b, startSize, endSize); p.angle += p.rotateSpeed * tpf; // Computing bounding volume temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); if (!selectRandomImage) { p.imageIndex = (int) (b * imagesX * imagesY); } }