⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m3gcanvas.java

📁 3D手机游戏开发实例源代码 3D迷宫游戏的演示程序
💻 JAVA
字号:


import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import javax.microedition.lcdui.game.*;

class M3GCanvas  extends GameCanvas
{
  // Choose another Camera25,26
	//static final int CAMERA_ID = 25;
	 static final int CAMERA_ID = 25;
	private Camera camera = null;	
	Graphics3D g3d = Graphics3D.getInstance();
	World myWorld = null;
  public M3GCanvas(){
    super(false);
    setFullScreenMode(false);

   			
		try {
			// Load the world from the m3g file							
			myWorld = (World) Loader.load("/teapot.m3g")[0];
    	camera = (Camera) myWorld.find(CAMERA_ID);
    	float viewport_width = getWidth();
	    float viewport_height = getHeight();
	    float aspectRatio = (float)viewport_width/(float)viewport_height;
	  	camera.setPerspective(45, aspectRatio,1.0f,2000.0f); 
  		myWorld.setActiveCamera(camera);	

		} catch (Exception e) {
			e.printStackTrace();
		}
		paint();

    }
   public void paint() {
        Graphics g2d = getGraphics();
	       try{
            g3d.bindTarget(g2d); // Binds the given Graphics or mutable Image2D as the rendering target of this Graphics3D
            g3d.clear(null);
            g3d.render(myWorld);
    }finally{
            g3d.releaseTarget();
        }
            flushGraphics();
    }
  }



 

⌨️ 快捷键说明

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