/** * Adds a cinematic event to this cinematic at the given timestamp. This * operation returns a keyFrame * * @param timeStamp the time when the event will start after the beginning * of the cinematic * @param cinematicEvent the cinematic event * @return the keyFrame for that event. */ public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); if (keyFrame == null) { keyFrame = new KeyFrame(); timeLine.addKeyFrameAtTime(timeStamp, keyFrame); } keyFrame.cinematicEvents.add(cinematicEvent); cinematicEvents.add(cinematicEvent); if (isInitialized()) { cinematicEvent.initEvent(null, this); } return keyFrame; }
/** * fits the duration of the cinematic to the duration of all its child * cinematic events */ public void fitDuration() { KeyFrame kf = timeLine.getKeyFrameAtIndex(timeLine.getLastKeyFrameIndex()); float d = 0; for (int i = 0; i < kf.getCinematicEvents().size(); i++) { CinematicEvent ce = kf.getCinematicEvents().get(i); float dur = timeLine.getKeyFrameTime(kf) + ce.getDuration() * ce.getSpeed(); if (d < dur) { d = dur; } } initialDuration = d; }
/** * removes the first occurrence found of the given cinematicEvent for the * given keyFrame * * @param keyFrame the keyFrame returned by the addCinematicEvent method. * @param cinematicEvent the cinematicEvent to remove * @return true if the element has been removed */ public boolean removeCinematicEvent(KeyFrame keyFrame, CinematicEvent cinematicEvent) { cinematicEvent.dispose(); boolean ret = keyFrame.cinematicEvents.remove(cinematicEvent); cinematicEvents.remove(cinematicEvent); if (keyFrame.isEmpty()) { timeLine.removeKeyFrame(keyFrame.getIndex()); } return ret; }
public float getKeyFrameTime(KeyFrame keyFrame) { return (float)keyFrame.getIndex()/(float)keyFramesPerSeconds; }
public void addKeyFrameAtIndex(int keyFrameIndex, KeyFrame keyFrame) { put(keyFrameIndex, keyFrame); keyFrame.setIndex(keyFrameIndex); if (lastKeyFrameIndex < keyFrameIndex) { lastKeyFrameIndex = keyFrameIndex; } }
/** * used internally, don't call this directly. * * @param tpf */ @Override public void onUpdate(float tpf) { int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //iterate to make sure every key frame is triggered for (int i = lastFetchedKeyFrame + 1; i <= keyFrameIndex; i++) { KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { keyFrame.trigger(); } } for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); ce.internalUpdate(tpf); } lastFetchedKeyFrame = keyFrameIndex; }
public void read(JmeImporter im) throws IOException { InputCapsule ic = im.getCapsule(this); ArrayList list = ic.readSavableArrayList("keyFrames", null); for (Iterator it = list.iterator(); it.hasNext();) { KeyFrame keyFrame = (KeyFrame) it.next(); addKeyFrameAtIndex(keyFrame.getIndex(), keyFrame); } } }
public void addKeyFrameAtIndex(int keyFrameIndex, KeyFrame keyFrame) { put(keyFrameIndex, keyFrame); keyFrame.setIndex(keyFrameIndex); if (lastKeyFrameIndex < keyFrameIndex) { lastKeyFrameIndex = keyFrameIndex; } }
/** * used internally, don't call this directly. * * @param tpf */ @Override public void onUpdate(float tpf) { int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //iterate to make sure every key frame is triggered for (int i = lastFetchedKeyFrame + 1; i <= keyFrameIndex; i++) { KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { keyFrame.trigger(); } } for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); ce.internalUpdate(tpf); } lastFetchedKeyFrame = keyFrameIndex; }
/** * removes the first occurrence found of the given cinematicEvent for the * given keyFrame * * @param keyFrame the keyFrame returned by the addCinematicEvent method. * @param cinematicEvent the cinematicEvent to remove * @return true if the element has been removed */ public boolean removeCinematicEvent(KeyFrame keyFrame, CinematicEvent cinematicEvent) { cinematicEvent.dispose(); boolean ret = keyFrame.cinematicEvents.remove(cinematicEvent); cinematicEvents.remove(cinematicEvent); if (keyFrame.isEmpty()) { timeLine.removeKeyFrame(keyFrame.getIndex()); } return ret; }
public float getKeyFrameTime(KeyFrame keyFrame) { return (float)keyFrame.getIndex()/(float)keyFramesPerSeconds; }
KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { for (CinematicEvent ce : keyFrame.getCinematicEvents()) { float t = this.time - timeLine.getKeyFrameTime(keyFrame); if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) {
/** * Adds a cinematic event to this cinematic at the given timestamp. This * operation returns a keyFrame * * @param timeStamp the time when the event will start after the beginning * of the cinematic * @param cinematicEvent the cinematic event * @return the keyFrame for that event. */ public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); if (keyFrame == null) { keyFrame = new KeyFrame(); timeLine.addKeyFrameAtTime(timeStamp, keyFrame); } keyFrame.cinematicEvents.add(cinematicEvent); cinematicEvents.add(cinematicEvent); if (isInitialized()) { cinematicEvent.initEvent(null, this); } return keyFrame; }
public void read(JmeImporter im) throws IOException { InputCapsule ic = im.getCapsule(this); ArrayList list = ic.readSavableArrayList("keyFrames", null); for (Iterator it = list.iterator(); it.hasNext();) { KeyFrame keyFrame = (KeyFrame) it.next(); addKeyFrameAtIndex(keyFrame.getIndex(), keyFrame); } } }
/** * fits the duration of the cinematic to the duration of all its child * cinematic events */ public void fitDuration() { KeyFrame kf = timeLine.getKeyFrameAtIndex(timeLine.getLastKeyFrameIndex()); float d = 0; for (int i = 0; i < kf.getCinematicEvents().size(); i++) { CinematicEvent ce = kf.getCinematicEvents().get(i); float dur = timeLine.getKeyFrameTime(kf) + ce.getDuration() * ce.getSpeed(); if (d < dur) { d = dur; } } initialDuration = d; }
KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { for (CinematicEvent ce : keyFrame.getCinematicEvents()) { float t = this.time - timeLine.getKeyFrameTime(keyFrame); if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) {