📄 smokecanvas.java
字号:
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;import com.mascotcapsule.micro3d.v3.*;public class SmokeCanvas extends GameCanvas implements Runnable{ private Graphics3D g3d; private Figure barrel; private int rotY = 0; private FigureLayout layout; private Effect3D effect; private AffineTrans trans; private AffineTrans rotationY; private Plane wall; private Plane floor; private Smoke smoke; private final int WIDTH, HEIGHT; private int ROT_WORLD = 0; private FPS fps = new FPS(); public SmokeCanvas(){ super(false); // setFullScreenMode(true); WIDTH = getWidth(); HEIGHT = getHeight(); g3d = new Graphics3D(); Texture wallTexture = null; Texture floorTexture = null; try{ wallTexture = new Texture("/brickWall255x255.bmp", true); floorTexture = new Texture("/stoneFloor255x255.bmp", true); }catch(Exception e){ e.printStackTrace(); } wall = new Plane(WIDTH, HEIGHT, Plane.TYPE_BACK_WALL); wall.setTexture(wallTexture); floor = new Plane(WIDTH, HEIGHT, Plane.TYPE_FLOOR); floor.setTexture(floorTexture); smoke = new Smoke(WIDTH, HEIGHT); try{ barrel = new Figure("/barrel.mbac"); barrel.setTexture(new Texture("/barrel128x255.bmp", true)); }catch(Exception e){ e.printStackTrace(); } layout = new FigureLayout(); effect = new Effect3D(); trans = new AffineTrans(); trans.setIdentity(); effect.setShadingType(Effect3D.NORMAL_SHADING); layout.setAffineTrans( trans ); layout.setPerspective(1, 4096, 512); layout.setCenter(WIDTH/2, HEIGHT/2); trans.mul(V3Object.lookAt); rotationY = new AffineTrans(); rotationY.setIdentity(); Thread t = new Thread(this); t.start(); } public void draw3D(Graphics g){ // clear the screen. g.setColor(0x00); g.fillRect(0,0, WIDTH, HEIGHT); // Bind the 3D graphics context to the given MIDP Graphics object. g3d.bind(g); try { floor.draw(g3d); g3d.flush(); smoke.draw(g3d); g3d.renderFigure(barrel, 0, 0, layout, effect); wall.draw(g3d); g3d.flush(); // flush the rendered figure } catch( Exception e ) { System.err.println("err: " + e); System.err.println(e.getMessage()); } g3d.release( g ); g.setColor(0xFFFFFF); g.drawString(fps.fps_string, 0, 0, 0); fps.calculateFps(); } /* * the joy pad is used to rotate and zoom in/out. */ public void keyDown(int key){ System.out.println(key); if((key & this.LEFT_PRESSED) != 0){ ROT_WORLD = ROT_WORLD < - 2048?ROT_WORLD+4096:ROT_WORLD-16; floor.rotY(ROT_WORLD); wall.rotY(ROT_WORLD); rotationY.rotationY(ROT_WORLD); trans.mul(V3Object.lookAt, rotationY); }else if((key & RIGHT_PRESSED) != 0){ ROT_WORLD = ROT_WORLD > 2048?ROT_WORLD-4096:ROT_WORLD+16; floor.rotY(ROT_WORLD); wall.rotY(ROT_WORLD); rotationY.rotationY(ROT_WORLD); trans.mul(V3Object.lookAt, rotationY); } if((key & this.UP_PRESSED) != 0){ floor.zoomIn(); smoke.update(); rotationY.rotationY(ROT_WORLD); trans.mul(V3Object.lookAt, rotationY); }else if((key & this.DOWN_PRESSED) != 0){ floor.zoomOut(); smoke.update(); rotationY.rotationY(ROT_WORLD); trans.mul(V3Object.lookAt, rotationY); } } public void run(){ Graphics g = getGraphics(); while(true){ keyDown(getKeyStates()); draw3D(g); flushGraphics(); try{ Thread.sleep(10); }catch(Exception e){} } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -