@Override public Quaternion interpolate(float t, int currentIndex, TrackDataReader<Quaternion> data, TrackTimeReader times, Quaternion store) { data.getEntryClamp(currentIndex, store); data.getEntryClamp(currentIndex + 1, next); store.nlerp(next, t); return store; } };
/** * Sets this transform to the interpolation between the first transform and the second by delta amount. * @param t1 The beginning transform. * @param t2 The ending transform. * @param delta An amount between 0 and 1 representing how far to interpolate from t1 to t2. */ public void interpolateTransforms(Transform t1, Transform t2, float delta) { t1.rot.nlerp(t2.rot, delta); this.rot.set(t1.rot); this.translation.interpolateLocal(t1.translation,t2.translation,delta); this.scale.interpolateLocal(t1.scale,t2.scale,delta); }
public static Quaternion slerpNoInvert(Quaternion q1, Quaternion q2, float t, Quaternion store) { float dot = q1.dot(q2); if (dot > -0.95f && dot < 0.95f) { float angle = FastMath.acos(dot); float sin1 = FastMath.sin(angle * (1 - t)); float sin2 = FastMath.sin(angle * t); float sin3 = FastMath.sin(angle); store.x = (q1.x * sin1 + q2.x * sin2) / sin3; store.y = (q1.y * sin1 + q2.y * sin2) / sin3; store.z = (q1.z * sin1 + q2.z * sin2) / sin3; store.w = (q1.w * sin1 + q2.w * sin2) / sin3; System.err.println("real slerp"); } else { // if the angle is small, use linear interpolation store.set(q1).nlerp(q2, t); System.err.println("nlerp"); } 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; } }
/** * Rotate the GUI to the given direction. * @param dir the direction to rotate to. * @param tpf the time per frame. */ private void rotateScreenTo(Quaternion dir, float tpf) { dir.getRotationColumn(2, look).negateLocal(); dir.getRotationColumn(0, left).negateLocal(); orient.fromAxes(left, dir.getRotationColumn(1, up), look); Quaternion rot = tempq.fromRotationMatrix(orient); if( posMode == VRGUIPositioningMode.AUTO_CAM_ALL_SKIP_PITCH ){ VRUtil.stripToYaw(rot); } if( guiPositioningElastic > 0f && posMode != VRGUIPositioningMode.MANUAL ) { // mix pos & dir with current pos & dir EoldDir.nlerp(rot, tpf * guiPositioningElastic); guiQuadNode.setLocalRotation(EoldDir); } else { guiQuadNode.setLocalRotation(rot); } }
tmpRot2.set(tmpRot1).nlerp(link.bone.getModelSpaceRotation(), blendStart / blendTime); position2.set(position).interpolateLocal(link.bone.getModelSpacePosition(), blendStart / blendTime); tmpRot1.set(tmpRot2);
tmpRot2.set(tmpRot1).nlerp(link.bone.getModelSpaceRotation(), blendStart / blendTime); position2.set(position).interpolateLocal(link.bone.getModelSpacePosition(), blendStart / blendTime); tmpRot1.set(tmpRot2);
scales.get(endFrame, tempS2); tempQ.nlerp(tempQ2, blend); tempV.interpolateLocal(tempV2, blend); tempS.interpolateLocal(tempS2, blend);
} else { float invWeightSum = 1f - currentWeightSum; localRot.nlerp(bindRot, invWeightSum); localPos.interpolateLocal(bindPos, invWeightSum); localScale.interpolateLocal(bindScale, invWeightSum);
localRot.nlerp(tmpQ, weight);
scales.get(endFrame, tempS2); tempQ.nlerp(tempQ2, blend); tempV.interpolateLocal(tempV2, blend); tempS.interpolateLocal(tempS2, blend);
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; } }
tmpRot2.set(tmpRot1).nlerp(link.bone.getModelSpaceRotation(), blendStart / blendTime); position2.set(position).interpolateLocal(link.bone.getModelSpacePosition(), blendStart / blendTime); tmpRot1.set(tmpRot2);
tmpRot2.set(tmpRot1).nlerp(link.bone.getModelSpaceRotation(), blendStart / blendTime); position2.set(position).interpolateLocal(link.bone.getModelSpacePosition(), blendStart / blendTime); tmpRot1.set(tmpRot2);
scales.get(endFrame, tempS2); tempQ.nlerp(tempQ2, blend); tempV.interpolateLocal(tempV2, blend); tempS.interpolateLocal(tempS2, blend);
} else { float invWeightSum = 1f - currentWeightSum; localRot.nlerp(bindRot, invWeightSum); localPos.interpolateLocal(bindPos, invWeightSum); localScale.interpolateLocal(bindScale, invWeightSum);
} else { float invWeightSum = 1f - currentWeightSum; localRot.nlerp(initialRot, invWeightSum); localPos.interpolate(initialPos, invWeightSum); localScale.interpolate(initialScale, invWeightSum);
localRot.nlerp(tmpQ, weight);
localRot.nlerp(tmpQ, weight);
scales.get(endFrame, tempS2); tempQ.nlerp(tempQ2, blend); tempV.interpolate(tempV2, blend); tempS.interpolate(tempS2, blend);