Quantcast
Viewing all articles
Browse latest Browse all 5

Cloning animated 3D objects (min3D framework for Android)

NOTE: This OpenGL ES 1.1 framework isn’t maintained anymore. Check out the OpenGL ES 2.0 Rajawali framework which also supports live wallpapers.

These two examples show how you can clone animated objects with min3D. The first example makes a shallow copy of the object. All the vertices, normals and texture coordinates are shared between all the objects. Only the first object transforms all the data for each keyframe. The rest of the objects are updated automatically.

Another option is to clone an object and clone all its vertices, uv coordinates and normals. This way the animation can be controlled indepently for each object.

This example creates shallow copies:


package rozengain.min3doom;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Min3DoomActivity extends RendererActivity {
	private AnimationObject3d doomGuy;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2, getResources(),
				"rozengain.min3doom:raw/doomguy");
		parser.parse();
		doomGuy = parser.getParsedAnimationObject();
		doomGuy.scale().x = doomGuy.scale().y = doomGuy.scale().z = .01f;
		doomGuy.rotation().z = -90;
		doomGuy.rotation().x = -90;
		doomGuy.position().x = -.3f;
		doomGuy.position().z = -1f;
		scene.addChild(doomGuy);
		doomGuy.setFps(20);
		doomGuy.play();

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				// -- create a shallow copy
				AnimationObject3d doomGuyClone = (AnimationObject3d) doomGuy
						.clone(false);
				scene.addChild(doomGuyClone);
				doomGuyClone.position().x += .3 * i;
				doomGuyClone.position().z += 1.5 * j;
				if(i % 2 == 1) doomGuyClone.position().z += .5;
				// -- prevent this object from updating the vertices.
				doomGuyClone.setUpdateVertices(false);
			}
		}

		scene.camera().position.y = 1;
		scene.camera().position.z = 2;
	}

	@Override
	public void updateScene() {

	}
}

See the youtube video here:

This example copies the all the vertices, normals, texture coordinates, etc so that all the objects can be animated independently:


package rozengain.min3doom2;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Min3Doom2Activity extends RendererActivity {
	private AnimationObject3d doomGuy;
	private AnimationObject3d doomGuyClone;
	private int frameCounter = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2, getResources(),
				"rozengain.min3doom2:raw/doomguy");
		parser.parse();
		doomGuy = parser.getParsedAnimationObject();
		doomGuy.scale().x = doomGuy.scale().y = doomGuy.scale().z = .01f;
		doomGuy.rotation().z = -90;
		doomGuy.rotation().x = -90;
		doomGuy.position().x = -.2f;
		doomGuy.position().z = -.5f;
		scene.addChild(doomGuy);
		doomGuy.setFps(20);
		doomGuy.play();

		// -- create a deep copy
		doomGuyClone = (AnimationObject3d) doomGuy.clone(true);
		doomGuyClone.position().x = .2f;
		scene.addChild(doomGuyClone);

		scene.camera().position.z = 1;
	}

	@Override
	public void updateScene() {
		// -- start playing a bit later
		if(frameCounter++ == 100)
			doomGuyClone.play();
	}
}

See the youtube video here:

Image may be NSFW.
Clik here to view.


Viewing all articles
Browse latest Browse all 5

Trending Articles