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

📄 m3gcanvas.java

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


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

class M3GCanvas  extends GameCanvas implements Runnable
{
    	// UserIDs for objects in the teapot model.
	static final int TEAPOT_ID = 25;

	static final int CAMERA_ID = 16;
	// Choose another Camera16,.17
	// static final int CAMERA_ID = 18;
	
	private Display myDisplay = null;

	private MobileCamera mobCam = null;	


	//private Mesh teapot = null;


	Graphics3D g3d = Graphics3D.getInstance();
	
	// Contains our entire scene graph
	World myWorld = null;


	/**
	 * TeapotMIDlet - default constructor.
	 */
	 
   public M3GCanvas(){
        super(false);
        
        setFullScreenMode(false);
        
		try {
			// Load the world from the m3g file							
			myWorld = (World) Loader.load("/teapot_plane_blue.m3g")[0];
		//	getObjects();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
    mobCam = new MobileCamera( getWidth(), getHeight());

    myWorld.addChild( mobCam.getCameraGroup() );
    myWorld.setActiveCamera( mobCam.getCamera() ); 
        
        
        Thread t = new Thread(this);
        t.start();
    }



    public void run() {
        Graphics g2d = getGraphics();

    
        while(true){
      
            // rotate the pyramid 1 degree around the Y-axis.
        // cubeMesh.postRotate(3.0f, 0.0f, 1.0f, 0.0f);
        try{
            g3d.bindTarget(g2d,false,0); // Binds the given Graphics or mutable Image2D as the rendering target of this Graphics3D
g3d.clear(null);
g3d.render(myWorld);
				mobCam.update();
        }finally{
            g3d.releaseTarget();
        }
        g2d.setColor(255,0,0);
    g2d.drawString( mobCam.getKeyMode(), 5,5, Graphics.TOP|Graphics.LEFT);
    g2d.drawString( mobCam.getPosition(), 5,18, Graphics.TOP|Graphics.LEFT);
    g2d.drawString( mobCam.getRotation(), 5,31, Graphics.TOP|Graphics.LEFT);
            flushGraphics();
        }
    }
    	/**
	 * getObjects()
	 * Get objects from the teapot model	 
	 */
	
	  // ------------ process key presses and releases ------------

  protected void keyPressed(int keyCode)
  { int gameAction = getGameAction(keyCode);
    mobCam.pressedKey(gameAction);

  }

  protected void keyReleased(int keyCode)
  { int gameAction = getGameAction(keyCode);
    mobCam.releasedKey(gameAction);
  }
	
	

	


  }



 

⌨️ 快捷键说明

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