com.daxie.joglf.gl.model.animation.AnimationInfo Maven / Gradle / Ivy
package com.daxie.joglf.gl.model.animation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import com.daxie.joglf.gl.window.WindowCommonInfoStock;
import com.daxie.log.LogFile;
/**
* Animation information
* @author Daba
*
*/
public class AnimationInfo {
//(frame_index, frame_handle)
private Map frames_map;
public AnimationInfo() {
frames_map=new TreeMap<>();
}
public void AppendFrame(float time,int frame_handle) {
int fps=WindowCommonInfoStock.GetFPS();
int frame_index=Math.round(fps*time);
frames_map.put(frame_index, frame_handle);
}
public float GetMaxTime() {
if(frames_map.size()==0) {
LogFile.WriteWarn("[AnimationInfo-GetTotalTime] No frames registered.", true);
return 0.0f;
}
Set frame_indices_set=frames_map.keySet();
List frame_indices=new ArrayList<>(frame_indices_set);
int size=frame_indices.size();
int max_frame_index=frame_indices.get(size-1);
int fps=WindowCommonInfoStock.GetFPS();
float max_time=(float)max_frame_index/fps;
return max_time;
}
public AnimationBlendInfo GetBlendInfo(float time) {
AnimationBlendInfo abi=new AnimationBlendInfo();
if(frames_map.size()==0) {
LogFile.WriteWarn("[AnimationInfo-GetBlendInfo] No frames registered.", true);
return abi;
}
int fps=WindowCommonInfoStock.GetFPS();
int frame_index=Math.round(time*fps);
Set frame_indices_set=frames_map.keySet();
List frame_indices=new ArrayList<>(frame_indices_set);
int size=frame_indices.size();
int min_frame_index=frame_indices.get(0);
int max_frame_index=frame_indices.get(size-1);
if(frame_index<=min_frame_index) {
int frame_handle=frames_map.get(min_frame_index);
abi.SetFrame1Handle(frame_handle);
return abi;
}
else if(frame_index>=max_frame_index) {
int frame_handle=frames_map.get(max_frame_index);
abi.SetFrame1Handle(frame_handle);
return abi;
}
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy