Example4.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.m3g.*;
- /**
- * M3G import and show test.
- *
- * The example loads the FILE_NAME file and takes the first object
- * contained in the file. The object is assumed to be of type World.
- * The world is first animated and then rendered. The actions of the
- * camera depend on the contents of the file.
- */
- public class Example4 extends ExampleBase
- {
- private static final String FILE_NAME = "cartrack";
- private World iWorld;
- public Example4()
- {
- super(SHOW_RENDER_TIME);
- }
- protected void render(int time)
- {
- iWorld.animate(time);
- iWorld.align(null);
- // iWorld.setAlphaFactor((float)Math.cos(time * 0.001f) * 0.45f + 0.5f);
- Graphics3D.getInstance().render(iWorld);
- }
- protected void initialize()
- {
- iWorld = (World)load(FILE_NAME)[0];
- traverse(iWorld);
- }
- private void traverse(Node aNode)
- {
- if (aNode instanceof Mesh)
- {
- Mesh mesh = (Mesh)aNode;
- for (int i = 0; i < mesh.getSubmeshCount(); i++)
- {
- Appearance app = mesh.getAppearance(i);
- CompositingMode cm = new CompositingMode();
- cm.setBlending(CompositingMode.ALPHA_ADD);
- app.setCompositingMode(cm);
- app.setTexture(0, null);
- Material mat = new Material();
- mat.setColor(Material.AMBIENT | Material.DIFFUSE | Material.SPECULAR, 0xff000000);
- mat.setColor(Material.EMISSIVE, 0xff444444);
- app.setMaterial(mat);
- }
- }
- if (aNode instanceof Group)
- {
- Group group = (Group)aNode;
- for (int i = 0; i < group.getChildCount(); i++)
- {
- traverse(group.getChild(i));
- }
- }
- }
- }