📄 m3gcanvas.java
字号:
import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;import javax.microedition.m3g.*;public class M3GCanvas extends GameCanvas implements Runnable { private Graphics3D g3d ; private World world; private Camera camera; private int iStartTime; private Graphics g; private int viewport_x; private int viewport_y; private int viewport_width; private int viewport_height; public M3GCanvas(){ super(true); try { world = (World)Loader.load("/tunnel.m3g")[0]; setupAspectRatio(); } catch (Exception e) { e.printStackTrace(); } iStartTime = (int)System.currentTimeMillis(); Thread t = new Thread(this); t.start(); } public void run() { Graphics g = getGraphics(); while(true) { world.animate((int) System.currentTimeMillis() - iStartTime); g.setColor( 255, 255, 255 ); g.fillRect( 0, 0, getWidth(), getHeight() ); g3d = Graphics3D.getInstance(); g3d.bindTarget(g); try{ g3d.render(world); }catch(Exception e){ System.err.println(e); }finally{ g3d.releaseTarget(); } flushGraphics(); try { Thread.sleep(200); } catch (InterruptedException e) { } } } void setupAspectRatio() { viewport_x = 0; viewport_y = 0; viewport_width = getWidth(); viewport_height = getHeight(); camera = world.getActiveCamera(); float[] params = new float[4]; int type = camera.getProjection(params); if (type != Camera.GENERIC) { //calculate window aspect ratio float waspect = viewport_width / viewport_height; if (waspect < params[1]) { float height = viewport_width / params[1]; viewport_height = (int)height; viewport_y = (getHeight() - viewport_height) / 2; } else { float width = viewport_height * params[1]; viewport_width = (int)width; viewport_x = (getWidth() - viewport_width) / 2; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -