@Test public void testSmoothEyeOneFrame() { ArrayList<KeyFrame> keyFrames = new ArrayList<KeyFrame>(); keyFrames.add(createEyeKeyFrame(0, 0.0, 0.0, 0.0)); setCameraKeyFrames(keyFrames); classToBeTested.smoothEyeSpeed(); List<KeyFrame> newKeyFrames = animation.getKeyFrames(); assertNotNull(newKeyFrames); assertEquals(1, newKeyFrames.size()); assertEyeKeyFrameEquals(0, 0.0, 0.0, 0.0, newKeyFrames.get(0)); }
@Override public void smoothEyeSpeed() { List<KeyFrame> eyeKeyFrames = eyeLat.getKeyFramesWithThisParameter(); int numberOfKeys = eyeKeyFrames.size(); if (numberOfKeys <= 1) { return; } double[] cumulativeDistance = new double[numberOfKeys - 1]; for (int i = 0; i < numberOfKeys - 1; i++) { int firstFrame = eyeKeyFrames.get(i).getFrame(); int lastFrame = eyeKeyFrames.get(i + 1).getFrame(); cumulativeDistance[i] = i == 0 ? 0 : cumulativeDistance[i - 1]; Vector3 vStart = null; for (int frame = firstFrame; frame <= lastFrame; frame++) { double x = eyeLat.getValueAtFrame(frame).getValue(); double y = eyeLon.getValueAtFrame(frame).getValue(); double z = eyeElevation.getValueAtFrame(frame).getValue(); Vector3 vEnd = new Vector3(x, y, z); if (vStart != null) { cumulativeDistance[i] += vStart.subtract(vEnd).distance(); } vStart = vEnd; } } int[] newFrames = new int[numberOfKeys]; int firstFrame = eyeKeyFrames.get(0).getFrame(); int lastFrame = eyeKeyFrames.get(numberOfKeys - 1).getFrame(); newFrames[0] = firstFrame; newFrames[numberOfKeys - 1] = lastFrame; for (int i = 1; i < numberOfKeys - 1; i++) { newFrames[i] = (int) Math.round(Math.abs((firstFrame - lastFrame + 1) * cumulativeDistance[i - 1] / cumulativeDistance[numberOfKeys - 2])); } for (int i = 0; i < newFrames.length - 1; i++) { if (newFrames[i] >= newFrames[i + 1]) { newFrames[i + 1] = newFrames[i] + 1; } } if (newFrames[numberOfKeys - 1] != lastFrame) { newFrames[numberOfKeys - 1] = lastFrame; for (int i = newFrames.length - 1; i > 0; i--) { if (newFrames[i] <= newFrames[i - 1]) { newFrames[i - 1] = newFrames[i] - 1; } } } if (newFrames[0] != firstFrame) { throw new IllegalStateException("Expected new first frame to be '" + firstFrame + "' but is '" + newFrames[0] + "'"); } for (int i = 0; i < eyeKeyFrames.size(); i++) { KeyFrame oldKeyFrame = eyeKeyFrames.get(i); Collection<ParameterValue> eyeValues = oldKeyFrame.getValuesForParameters(getParameters()); KeyFrame newKeyFrame = new KeyFrameImpl(newFrames[i], eyeValues); oldKeyFrame.removeValuesForParameters(getParameters()); animation.insertKeyFrame(newKeyFrame); } animation.removeEmptyKeyFrames(); }
CameraImpl extends AnimatableBase implements Camera { @Override public void smoothEyeSpeed() { List<KeyFrame> eyeKeyFrames = eyeLat.getKeyFramesWithThisParameter(); int numberOfKeys = eyeKeyFrames.size(); if (numberOfKeys <= 1) { return; } double[] cumulativeDistance = new double[numberOfKeys - 1]; for (int i = 0; i < numberOfKeys - 1; i++) { int firstFrame = eyeKeyFrames.get(i).getFrame(); int lastFrame = eyeKeyFrames.get(i + 1).getFrame(); cumulativeDistance[i] = i == 0 ? 0 : cumulativeDistance[i - 1]; Vector3 vStart = null; for (int frame = firstFrame; frame <= lastFrame; frame++) { double x = eyeLat.getValueAtFrame(frame).getValue(); double y = eyeLon.getValueAtFrame(frame).getValue(); double z = eyeElevation.getValueAtFrame(frame).getValue(); Vector3 vEnd = new Vector3(x, y, z); if (vStart != null) { cumulativeDistance[i] += vStart.subtract(vEnd).distance(); } vStart = vEnd; } } int[] newFrames = new int[numberOfKeys]; int firstFrame = eyeKeyFrames.get(0).getFrame(); int lastFrame = eyeKeyFrames.get(numberOfKeys - 1).getFrame(); newFrames[0] = firstFrame; newFrames[numberOfKeys - 1] = lastFrame; for (int i = 1; i < numberOfKeys - 1; i++) { newFrames[i] = (int) Math.round(Math.abs((firstFrame - lastFrame + 1) * cumulativeDistance[i - 1] / cumulativeDistance[numberOfKeys - 2])); } for (int i = 0; i < newFrames.length - 1; i++) { if (newFrames[i] >= newFrames[i + 1]) { newFrames[i + 1] = newFrames[i] + 1; } } if (newFrames[numberOfKeys - 1] != lastFrame) { newFrames[numberOfKeys - 1] = lastFrame; for (int i = newFrames.length - 1; i > 0; i--) { if (newFrames[i] <= newFrames[i - 1]) { newFrames[i - 1] = newFrames[i] - 1; } } } if (newFrames[0] != firstFrame) { throw new IllegalStateException("Expected new first frame to be '" + firstFrame + "' but is '" + newFrames[0] + "'"); } for (int i = 0; i < eyeKeyFrames.size(); i++) { KeyFrame oldKeyFrame = eyeKeyFrames.get(i); Collection<ParameterValue> eyeValues = oldKeyFrame.getValuesForParameters(getParameters()); KeyFrame newKeyFrame = new KeyFrameImpl(newFrames[i], eyeValues); oldKeyFrame.removeValuesForParameters(getParameters()); animation.insertKeyFrame(newKeyFrame); } animation.removeEmptyKeyFrames(); } }
CameraImpl extends AnimatableBase implements Camera { @Override public void smoothEyeSpeed() { List<KeyFrame> eyeKeyFrames = eyeLat.getKeyFramesWithThisParameter(); int numberOfKeys = eyeKeyFrames.size(); if (numberOfKeys <= 1) { return; } double[] cumulativeDistance = new double[numberOfKeys - 1]; for (int i = 0; i < numberOfKeys - 1; i++) { int firstFrame = eyeKeyFrames.get(i).getFrame(); int lastFrame = eyeKeyFrames.get(i + 1).getFrame(); cumulativeDistance[i] = i == 0 ? 0 : cumulativeDistance[i - 1]; Vector3 vStart = null; for (int frame = firstFrame; frame <= lastFrame; frame++) { double x = eyeLat.getValueAtFrame(frame).getValue(); double y = eyeLon.getValueAtFrame(frame).getValue(); double z = eyeElevation.getValueAtFrame(frame).getValue(); Vector3 vEnd = new Vector3(x, y, z); if (vStart != null) { cumulativeDistance[i] += vStart.subtract(vEnd).distance(); } vStart = vEnd; } } int[] newFrames = new int[numberOfKeys]; int firstFrame = eyeKeyFrames.get(0).getFrame(); int lastFrame = eyeKeyFrames.get(numberOfKeys - 1).getFrame(); newFrames[0] = firstFrame; newFrames[numberOfKeys - 1] = lastFrame; for (int i = 1; i < numberOfKeys - 1; i++) { newFrames[i] = (int) Math.round(Math.abs((firstFrame - lastFrame + 1) * cumulativeDistance[i - 1] / cumulativeDistance[numberOfKeys - 2])); } for (int i = 0; i < newFrames.length - 1; i++) { if (newFrames[i] >= newFrames[i + 1]) { newFrames[i + 1] = newFrames[i] + 1; } } if (newFrames[numberOfKeys - 1] != lastFrame) { newFrames[numberOfKeys - 1] = lastFrame; for (int i = newFrames.length - 1; i > 0; i--) { if (newFrames[i] <= newFrames[i - 1]) { newFrames[i - 1] = newFrames[i] - 1; } } } if (newFrames[0] != firstFrame) { throw new IllegalStateException("Expected new first frame to be '" + firstFrame + "' but is '" + newFrames[0] + "'"); } for (int i = 0; i < eyeKeyFrames.size(); i++) { KeyFrame oldKeyFrame = eyeKeyFrames.get(i); Collection<ParameterValue> eyeValues = oldKeyFrame.getValuesForParameters(getParameters()); KeyFrame newKeyFrame = new KeyFrameImpl(newFrames[i], eyeValues); oldKeyFrame.removeValuesForParameters(getParameters()); animation.insertKeyFrame(newKeyFrame); } animation.removeEmptyKeyFrames(); } CameraImpl(Animation animation); protected  CameraImpl(String name, Animation animation); protected  CameraImpl(); }
CameraImpl extends AnimatableBase implements Camera { @Override public void smoothEyeSpeed() { List<KeyFrame> eyeKeyFrames = eyeLat.getKeyFramesWithThisParameter(); int numberOfKeys = eyeKeyFrames.size(); if (numberOfKeys <= 1) { return; } double[] cumulativeDistance = new double[numberOfKeys - 1]; for (int i = 0; i < numberOfKeys - 1; i++) { int firstFrame = eyeKeyFrames.get(i).getFrame(); int lastFrame = eyeKeyFrames.get(i + 1).getFrame(); cumulativeDistance[i] = i == 0 ? 0 : cumulativeDistance[i - 1]; Vector3 vStart = null; for (int frame = firstFrame; frame <= lastFrame; frame++) { double x = eyeLat.getValueAtFrame(frame).getValue(); double y = eyeLon.getValueAtFrame(frame).getValue(); double z = eyeElevation.getValueAtFrame(frame).getValue(); Vector3 vEnd = new Vector3(x, y, z); if (vStart != null) { cumulativeDistance[i] += vStart.subtract(vEnd).distance(); } vStart = vEnd; } } int[] newFrames = new int[numberOfKeys]; int firstFrame = eyeKeyFrames.get(0).getFrame(); int lastFrame = eyeKeyFrames.get(numberOfKeys - 1).getFrame(); newFrames[0] = firstFrame; newFrames[numberOfKeys - 1] = lastFrame; for (int i = 1; i < numberOfKeys - 1; i++) { newFrames[i] = (int) Math.round(Math.abs((firstFrame - lastFrame + 1) * cumulativeDistance[i - 1] / cumulativeDistance[numberOfKeys - 2])); } for (int i = 0; i < newFrames.length - 1; i++) { if (newFrames[i] >= newFrames[i + 1]) { newFrames[i + 1] = newFrames[i] + 1; } } if (newFrames[numberOfKeys - 1] != lastFrame) { newFrames[numberOfKeys - 1] = lastFrame; for (int i = newFrames.length - 1; i > 0; i--) { if (newFrames[i] <= newFrames[i - 1]) { newFrames[i - 1] = newFrames[i] - 1; } } } if (newFrames[0] != firstFrame) { throw new IllegalStateException("Expected new first frame to be '" + firstFrame + "' but is '" + newFrames[0] + "'"); } for (int i = 0; i < eyeKeyFrames.size(); i++) { KeyFrame oldKeyFrame = eyeKeyFrames.get(i); Collection<ParameterValue> eyeValues = oldKeyFrame.getValuesForParameters(getParameters()); KeyFrame newKeyFrame = new KeyFrameImpl(newFrames[i], eyeValues); oldKeyFrame.removeValuesForParameters(getParameters()); animation.insertKeyFrame(newKeyFrame); } animation.removeEmptyKeyFrames(); } CameraImpl(Animation animation); protected  CameraImpl(String name, Animation animation); protected  CameraImpl(); @Override Position[] getEyePositionsBetweenFrames(int startFrame, int endFrame); @Override Position[] getLookatPositionsBetweenFrames(int startFrame, int endFrame); @Override Position getEyePositionAtFrame(int frame); @Override Position getLookatPositionAtFrame(int frame); @Override Parameter getEyeLat(); @Override Parameter getEyeLon(); @Override Parameter getEyeElevation(); @Override Parameter getLookAtLat(); @Override Parameter getLookAtLon(); @Override Parameter getLookAtElevation(); @Override Parameter getRoll(); @Override Parameter getFieldOfView(); @Override boolean isClippingParametersActive(); @Override void setClippingParametersActive(boolean active); @Override Parameter getNearClip(); @Override Parameter getFarClip(); @Override Collection<Parameter> getParameters(); @Override void smoothEyeSpeed(); @Override void copyStateFrom(Camera camera); }
CameraImpl extends AnimatableBase implements Camera { @Override public void smoothEyeSpeed() { List<KeyFrame> eyeKeyFrames = eyeLat.getKeyFramesWithThisParameter(); int numberOfKeys = eyeKeyFrames.size(); if (numberOfKeys <= 1) { return; } double[] cumulativeDistance = new double[numberOfKeys - 1]; for (int i = 0; i < numberOfKeys - 1; i++) { int firstFrame = eyeKeyFrames.get(i).getFrame(); int lastFrame = eyeKeyFrames.get(i + 1).getFrame(); cumulativeDistance[i] = i == 0 ? 0 : cumulativeDistance[i - 1]; Vector3 vStart = null; for (int frame = firstFrame; frame <= lastFrame; frame++) { double x = eyeLat.getValueAtFrame(frame).getValue(); double y = eyeLon.getValueAtFrame(frame).getValue(); double z = eyeElevation.getValueAtFrame(frame).getValue(); Vector3 vEnd = new Vector3(x, y, z); if (vStart != null) { cumulativeDistance[i] += vStart.subtract(vEnd).distance(); } vStart = vEnd; } } int[] newFrames = new int[numberOfKeys]; int firstFrame = eyeKeyFrames.get(0).getFrame(); int lastFrame = eyeKeyFrames.get(numberOfKeys - 1).getFrame(); newFrames[0] = firstFrame; newFrames[numberOfKeys - 1] = lastFrame; for (int i = 1; i < numberOfKeys - 1; i++) { newFrames[i] = (int) Math.round(Math.abs((firstFrame - lastFrame + 1) * cumulativeDistance[i - 1] / cumulativeDistance[numberOfKeys - 2])); } for (int i = 0; i < newFrames.length - 1; i++) { if (newFrames[i] >= newFrames[i + 1]) { newFrames[i + 1] = newFrames[i] + 1; } } if (newFrames[numberOfKeys - 1] != lastFrame) { newFrames[numberOfKeys - 1] = lastFrame; for (int i = newFrames.length - 1; i > 0; i--) { if (newFrames[i] <= newFrames[i - 1]) { newFrames[i - 1] = newFrames[i] - 1; } } } if (newFrames[0] != firstFrame) { throw new IllegalStateException("Expected new first frame to be '" + firstFrame + "' but is '" + newFrames[0] + "'"); } for (int i = 0; i < eyeKeyFrames.size(); i++) { KeyFrame oldKeyFrame = eyeKeyFrames.get(i); Collection<ParameterValue> eyeValues = oldKeyFrame.getValuesForParameters(getParameters()); KeyFrame newKeyFrame = new KeyFrameImpl(newFrames[i], eyeValues); oldKeyFrame.removeValuesForParameters(getParameters()); animation.insertKeyFrame(newKeyFrame); } animation.removeEmptyKeyFrames(); } CameraImpl(Animation animation); protected  CameraImpl(String name, Animation animation); protected  CameraImpl(); @Override Position[] getEyePositionsBetweenFrames(int startFrame, int endFrame); @Override Position[] getLookatPositionsBetweenFrames(int startFrame, int endFrame); @Override Position getEyePositionAtFrame(int frame); @Override Position getLookatPositionAtFrame(int frame); @Override Parameter getEyeLat(); @Override Parameter getEyeLon(); @Override Parameter getEyeElevation(); @Override Parameter getLookAtLat(); @Override Parameter getLookAtLon(); @Override Parameter getLookAtElevation(); @Override Parameter getRoll(); @Override Parameter getFieldOfView(); @Override boolean isClippingParametersActive(); @Override void setClippingParametersActive(boolean active); @Override Parameter getNearClip(); @Override Parameter getFarClip(); @Override Collection<Parameter> getParameters(); @Override void smoothEyeSpeed(); @Override void copyStateFrom(Camera camera);  }