Skip to content

Instantly share code, notes, and snippets.

@talklittle
Created December 20, 2012 00:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talklittle/4341953 to your computer and use it in GitHub Desktop.
Save talklittle/4341953 to your computer and use it in GitHub Desktop.
the libgdx render code for MD2 model used in Frog Ball
// private KeyframedModel currentModel;
// use ModelLoaderRegistry.loadKeyframedModel() to load MD2 models
// in render():
if (currentModel != desiredModel) {
currentModel = desiredModel;
animationTime = 0;
}
// fixed value for MD2 exporter from
// http://www.junaio.com/develop/docs/documenation/general/3dmodels/
String animation = "all";
animationTime += Gdx.graphics.getDeltaTime();
float totalDuration = currentModel.getAnimation(animation).totalDuration;
if (loop) {
while (animationTime > totalDuration)
animationTime -= totalDuration;
}
else {
if (animationTime > totalDuration)
animationTime = totalDuration - 0.000001f; // libgdx crash when animationTime == totalDuration
}
currentModel.setAnimation(animation, animationTime, loop);
currentModel.render(shader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment