?? dicev3canvas.java
字號:
/***************************************************************************** Description: A canvas class that uses the Mascot Capsule V3 api to render a dice to the screen. Created By: Oscar Vivall 2005-07-06 @file DiceV3.java COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of the end-user license agreement which accompanies or is included with the software. The software is provided "as is" and Sony Ericsson specifically disclaim any warranty or condition whatsoever regarding merchantability or fitness for a specific purpose, title or non-infringement. No warranty of any kind is made in relation to the condition, suitability, availability, accuracy, reliability, merchantability and/or non-infringement of the software provided herein.*****************************************************************************/import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;import com.mascotcapsule.micro3d.v3.*;import java.util.*;public class DiceV3Canvas extends GameCanvas implements Runnable{ private MIDlet midlet; private Graphics3D g3d; private Figure diceFigure; private ActionTable []action = new ActionTable[6]; private AffineTrans transDice1; private AffineTrans transDice2; private Effect3D effect; private FigureLayout layoutDice1; private FigureLayout layoutDice2; private AffineTrans look; private int diceOneFrame = 0; private int diceTwoFrame = 0; private final int []frameLength = new int[] {80,65,70,80,55,75}; private int diceOneIndex=0; private int diceTwoIndex=0; private Image bgImage = null; int index = 0; public DiceV3Canvas(MIDlet m){ super(false); midlet = m; setFullScreenMode(true); g3d = new Graphics3D(); try{ bgImage = Image.createImage("/res/monopoly.png"); }catch(Exception e){ } try{ diceFigure = new Figure("/res/dice.mbac"); diceFigure.setTexture(new Texture("/res/diceTextur2.bmp", true)); action[0] = new ActionTable("/res/one.mtra"); action[1] = new ActionTable("/res/two.mtra"); action[2] = new ActionTable("/res/three.mtra"); action[3] = new ActionTable("/res/four.mtra"); action[4] = new ActionTable("/res/five.mtra"); action[5] = new ActionTable("/res/six.mtra"); }catch(Exception e){ System.out.println(e); System.out.println(e.getMessage()); } layoutDice1 = new FigureLayout(); layoutDice2 = new FigureLayout(); effect = new Effect3D(); effect.setShadingType(Effect3D.NORMAL_SHADING); transDice1 = new AffineTrans(); transDice1.setIdentity(); transDice2 = new AffineTrans(); transDice2.setIdentity(); layoutDice1.setAffineTrans( transDice1 ); layoutDice1.setPerspective(1, 4096, 512); layoutDice1.setCenter(getWidth()/2, getHeight()/2); layoutDice2.setAffineTrans( transDice2 ); layoutDice2.setPerspective(1, 4096, 512); layoutDice2.setCenter(getWidth()/2, getHeight()/2); look = new AffineTrans(); look.setIdentity(); look.lookAt( new Vector3D(0, -128, 300), new Vector3D(-0, 512, -1024), new Vector3D(0, 4096, 0) ); transDice1.mul(look); transDice2.mul(look); newThrow(); Thread t = new Thread(this); t.start(); } private void draw3D(Graphics g){ if(diceOneFrame < action[diceOneIndex].getNumFrames(0)){ diceOneFrame += action[diceOneIndex].getNumFrames(0)/frameLength[diceOneIndex]; } diceFigure.setPosture(action[diceOneIndex], 0, diceOneFrame); if(diceTwoFrame < action[diceTwoIndex].getNumFrames(0)){ diceTwoFrame += action[diceTwoIndex].getNumFrames(0)/65; } try{ g3d.bind(g); g3d.renderFigure(diceFigure, 0, 0, layoutDice1, effect); diceFigure.setPosture(action[diceTwoIndex], 0, diceTwoFrame); g3d.renderFigure(diceFigure, 0, 0, layoutDice2, effect); g3d.flush(); }catch(Exception e){ }finally{ g3d.release(g); } } private void newThrow(){ Random r = new Random(); diceOneIndex = r.nextInt(6); diceTwoIndex = r.nextInt(6); AffineTrans t = new AffineTrans(); t.setIdentity(); int rnd = -2048 + r.nextInt(4096); t.rotationZ(rnd); transDice1.mul(look, t); rnd = -2048 + r.nextInt(4096); t.setIdentity(); t.rotationZ(rnd); transDice2.multiply(look, t); diceOneFrame = diceTwoFrame = 0; } public void keyPressed(int key){ if(key==-6){ midlet.notifyDestroyed(); }else{ newThrow(); } } public void run(){ Graphics graphics = this.getGraphics(); while(true){ graphics.drawImage(bgImage, 0, 0, 0); draw3D(graphics); graphics.setColor(0xFFFFFF); graphics.drawString("Exit", 0, getHeight(), Graphics.LEFT | Graphics.BOTTOM); flushGraphics(); try{ Thread.sleep(40); }catch(Exception e){} } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -