MasDennis/Rajawali — pull request #275 by jayschwa (2012-12-20 02:09:37+00:00)
Title: Fix animation freezes

Since my personal projects do not use animations, I do not have as much at stake with these changes, nor do I have as much material to test with. @ToxicBakery, @Amorgos, @Davhed, @aina-no-software, and anybody else who might have a stake in this, I'd appreciate it if you try this branch with your own projects. This was truly a quick-n-dirty fix (first thing that came to mind), so feel free to critique or suggest something different.

You may need to remove any animation kludges you added to your project to workaround the freeze.

## Changes

Keeping only once instance of `TimerManager` caused multiple renderers to
kill each others' animations. `TimerManager` has been removed and each
renderer will keep track of their own animations instead.

`RajawaliRenderer.addAnim(Animation3D)` has been added, similar to
`addChild(BaseObject3D)`, only for animations. Animations will be started
in `startRendering()`, paused in `stopRendering()`, and cancelled in
`destroyScene()`.

Fixes #250
May also improve #261

## To Do

* Update and test with [examples](https://github.com/MasDennis/RajawaliExamples)
* Figure out what to do (if anything) for `Rajawali[Fragment]Activity.onPause()`
* Figure out how this should work with `Animation3DQueue` objects
* Common interface for `Animation3D` and `Animation3DQueue`?
* start()
* pause()
* cancel()

## Example

Tested with the following renderer in the [wallpaper template](https://github.com/MasDennis/RajawaliWallpaperTemplate):
``` Java
public class Renderer extends RajawaliRenderer {

public Renderer(Context context) {
super(context);
}

public void initScene() {
ALight light = new DirectionalLight();
light.setPower(1);
light.setPosition(0, 0, -5);
mCamera.setPosition(0, 0, -7);
mCamera.setLookAt(0, 0, 0);

Cube cube = new Cube(1);
DiffuseMaterial material = new DiffuseMaterial();
cube.setMaterial(material);
Bitmap texture = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.rajawali_tex);
cube.addTexture(mTextureManager.addTexture(texture));
cube.addLight(light);
addChild(cube);

Number3D axis = new Number3D(3, 1, 6);
axis.normalize();
Animation3D anim = new RotateAnimation3D(axis, 360);
anim.setDuration(8000);
anim.setRepeatCount(Animation3D.INFINITE);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setTransformable3D(cube);
addAnim(anim);
}
}
```