example4.java

来自「< J2ME手机游戏开发技术详解>>上的全部源码,包括实现中需」· Java 代码 · 共 67 行

JAVA
67
字号
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));
            }
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?